Beispiel #1
0
def test_get_user_password_from_user_input():
    username = tests_util.get_random_ascii_string(10)
    password = tests_util.get_random_ascii_string(10)

    mock_input = '__builtin__.raw_input' if util.PY2 else 'builtins.input'
    with mock.patch(mock_input,
                    return_value=username), mock.patch('getpass.getpass',
                                                       return_value=password):
        user_password_credential = credential.get_user_password(
            name='credential_1')
    assert user_password_credential == {
        'type': credential.CredentialType.UserPassword,
        'username': username,
        'password': password,
    }
Beispiel #2
0
def test_create_acme_challenge(local_server):
    # prepare data
    token = tests_util.get_random_ascii_string()
    key_authorization = tests_util.get_random_ascii_string()
    wellknown_path = local_server.acme_dir / token

    # check challenge does not exist yet
    assert not wellknown_path.exists()

    # deploy challenge
    local_server.create_acme_challenge(token=token, key_authorization=key_authorization)

    # ensure challenge exist and with proper value
    assert wellknown_path.exists()
    assert wellknown_path.read_text() == key_authorization
Beispiel #3
0
def test_save_retrieve_data_from_content(git_storage, folder_name, tracking_record_id):
    file_name = tests_util.get_random_ascii_string()
    file_content = tests_util.get_random_text()
    # save content in main repo
    git_storage.save_data(name=file_name, content=file_content)

    assert git_storage.retrieve_data(name=file_name) == file_content
Beispiel #4
0
def test_save_retrieve_data_from_local_file(tmp_path, local_storage):
    file_name = tests_util.get_random_ascii_string()
    file_content = tests_util.get_random_text()

    # save data with content from local file
    # first create a temporary file on disk that will be used as source of the data
    source_file_path = tmp_path / file_name
    source_file_path.write_bytes(file_content)

    # save data
    file_name2 = tests_util.get_random_ascii_string()
    local_storage.save_data(name=file_name2, local_path=source_file_path)

    assert local_storage.retrieve_data(name=file_name2) == file_content

    local_storage.save_data(name=file_name2, local_path=source_file_path)
    assert local_storage.retrieve_data(name=file_name2) == file_content
Beispiel #5
0
def test_delete_acme_challenge(local_server):
    # prepare data
    token = tests_util.get_random_ascii_string()
    key_authorization = tests_util.get_random_ascii_string()
    wellknown_path = local_server.acme_dir / token

    # deploy challenge
    local_server.create_acme_challenge(token=token, key_authorization=key_authorization)

    # check challenge exists
    assert wellknown_path.exists()

    # delete challenge
    local_server.delete_acme_challenge(token=token)

    # ensure challenge has been deleted
    assert not wellknown_path.exists()
Beispiel #6
0
def test_get_credentials_already_retrieved_once():
    username = tests_util.get_random_ascii_string(10)
    password = tests_util.get_random_ascii_string(10)
    user_password_credential = credential.get_credentials(
        name='credential_1',
        global_config=None,
        credentials={
            'credential_1': {
                'type': credential.CredentialType.UserPassword,
                'username': username,
                'password': password,
            }
        },
        extra_parameters=None,
    )
    assert user_password_credential == {
        'type': credential.CredentialType.UserPassword,
        'username': username,
        'password': password,
    }
Beispiel #7
0
def test_save_retrieve_data_from_local_path(git_storage, folder_name):
    file_name = tests_util.get_random_ascii_string()
    file_content = tests_util.get_random_text()

    # save content in main repo from local_path
    with tempfile.NamedTemporaryFile() as local_file:
        local_file.write(file_content)
        local_file.seek(0)
        git_storage.save_data(name=file_name, local_path=local_file.name)

    assert git_storage.retrieve_data(name=file_name) == file_content
Beispiel #8
0
def test_save_retrieve_data_from_content(local_storage):
    file_name = tests_util.get_random_ascii_string()
    file_content = tests_util.get_random_text()

    # save data in main repo from content
    local_storage.save_data(
        name=file_name,
        content=file_content,
        # local_path here will be ignored as content is already provided
        local_path='not_existing_path')
    assert local_storage.retrieve_data(name=file_name) == file_content
Beispiel #9
0
def test_save_retrieve_data_same_file_twice(git_storage):
    file_name = tests_util.get_random_ascii_string()
    file_content = tests_util.get_random_text()

    # save content in main repo
    git_storage.save_data(name=file_name, content=file_content)

    assert git_storage.retrieve_data(name=file_name) == file_content

    # try to save same data a 2nd time should not fail
    git_storage.save_data(name=file_name, content=file_content)

    assert git_storage.retrieve_data(name=file_name) == file_content
Beispiel #10
0
def keypair(tmp_path, ca_keypair_path):
    common_name = 'tst.autossl.example.com'
    crt_name = tests_util.get_random_ascii_string()
    key_path = tmp_path.joinpath(crt_name + '.key')
    key_content, csr_path = ssl.generate_csr(name=crt_name, common_name=common_name, output_path=tmp_path)
    crt_path = tmp_path.joinpath(crt_name + '.crt')
    crt_content = tests_util.create_signed_certificate(
        csr_path=csr_path,
        ca_crt_path=ca_keypair_path.crt,
        ca_key_path=ca_keypair_path.key,
        certificate_validity_days=10,
    )

    crt_path.write_bytes(crt_content)
    key_path.write_bytes(key_content)

    yield CertificateKeyPair(key_path, crt_path)