示例#1
0
    def setUp(self):
        registry_url = "docker.io"

        self.config = ProxyCacheConfig(
            upstream_registry=registry_url,
            organization=User(username="******", organization=True),
        )

        encrypter = FieldEncrypter(app.config.get("DATABASE_SECRET_KEY"))
        username_field = ProxyCacheConfig.upstream_registry_username
        password_field = ProxyCacheConfig.upstream_registry_password
        user = LazyEncryptedValue(
            encrypter.encrypt_value(
                "user", field_max_length=username_field.max_length),
            username_field,
        )
        password = LazyEncryptedValue(
            encrypter.encrypt_value(
                "pass", field_max_length=password_field.max_length),
            password_field,
        )

        self.auth_config = ProxyCacheConfig(
            upstream_registry=registry_url,
            upstream_registry_username=user,
            upstream_registry_password=password,
            organization=User(username="******", organization=True),
        )
示例#2
0
def test_encryption(test_data, version, secret_key, use_valid_key):
    encrypter = FieldEncrypter(secret_key, version)
    encrypted = encrypter.encrypt_value(test_data, field_max_length=255)
    assert encrypted != test_data

    if use_valid_key:
        decrypted = encrypter.decrypt_value(encrypted)
        assert decrypted == test_data

        with pytest.raises(DecryptionFailureException):
            encrypter.decrypt_value("somerandomvalue")
    else:
        decrypter = FieldEncrypter("some other key", version)
        with pytest.raises(DecryptionFailureException):
            decrypter.decrypt_value(encrypted)