Search in sources :

Example 1 with KeywhizConfig

use of keywhiz.KeywhizConfig in project keywhiz by square.

the class CryptoModuleTest method secureRandomIsNonSingleton.

@Test
public void secureRandomIsNonSingleton() {
    KeywhizConfig config = ServiceContext.create().getConfig();
    Injector injector = Guice.createInjector(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()));
    assertNotSame(injector.getInstance(SecureRandom.class), injector.getInstance(SecureRandom.class));
}
Also used : Injector(com.google.inject.Injector) KeywhizConfig(keywhiz.KeywhizConfig) SecureRandom(java.security.SecureRandom) Test(org.junit.Test)

Example 2 with KeywhizConfig

use of keywhiz.KeywhizConfig in project keywhiz by square.

the class CryptoModuleTest method secureRandomIsExplicitlyBound.

@Test
public void secureRandomIsExplicitlyBound() {
    KeywhizConfig config = ServiceContext.create().getConfig();
    Injector injector = Guice.createInjector(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()), new StrictGuiceModule());
    assertNotNull(injector.getInstance(SecureRandom.class));
}
Also used : Injector(com.google.inject.Injector) KeywhizConfig(keywhiz.KeywhizConfig) SecureRandom(java.security.SecureRandom) StrictGuiceModule(keywhiz.inject.StrictGuiceModule) Test(org.junit.Test)

Example 3 with KeywhizConfig

use of keywhiz.KeywhizConfig in project keywhiz by square.

the class ServiceContext method create.

public static ServiceContext create() {
    KeywhizService service = new KeywhizService();
    Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
    service.initialize(bootstrap);
    ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    KeywhizConfig config = loadTestConfig(objectMapper, validator);
    Environment environment = new Environment(bootstrap.getApplication().getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader());
    return new ServiceContext(service, bootstrap, config, environment);
}
Also used : KeywhizService(keywhiz.KeywhizService) KeywhizConfig(keywhiz.KeywhizConfig) Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(javax.validation.Validator)

Example 4 with KeywhizConfig

use of keywhiz.KeywhizConfig in project keywhiz by square.

the class SecretControllerMockTest method createController.

private SecretController createController(Long maximumSecretSizeInBytesInclusive) {
    KeywhizConfig config = new KeywhizConfig();
    config.setMaximumSecretSizeInBytesInclusive(maximumSecretSizeInBytesInclusive);
    ContentCryptographer cryptographer = mock(ContentCryptographer.class);
    when(cryptographer.computeHmac(any(), any())).thenReturn("hmac");
    when(cryptographer.encryptionKeyDerivedFrom(any())).thenReturn(mock(ContentCryptographer.Encrypter.class));
    return new SecretController(mock(SecretTransformer.class), cryptographer, mock(SecretDAO.class), mock(AclDAO.class), config);
}
Also used : ContentCryptographer(keywhiz.service.crypto.ContentCryptographer) SecretTransformer(keywhiz.service.crypto.SecretTransformer) KeywhizConfig(keywhiz.KeywhizConfig)

Example 5 with KeywhizConfig

use of keywhiz.KeywhizConfig in project keywhiz by square.

the class ContextModuleTest method injectsContext.

@Test
public void injectsContext() {
    class Holder {

        @Inject
        KeywhizConfig keywhizConfig;

        @Inject
        Configuration config;

        @Inject
        Environment environment;
    }
    Holder holder = new Holder();
    ServiceContext context = ServiceContext.create();
    Guice.createInjector(new ContextModule(context.getConfig(), context.getEnvironment())).injectMembers(holder);
    assertSame(context.getConfig(), holder.keywhizConfig);
    assertSame(context.getConfig(), holder.config);
    assertSame(context.getEnvironment(), holder.environment);
}
Also used : Configuration(io.dropwizard.Configuration) ServiceContext(keywhiz.test.ServiceContext) KeywhizConfig(keywhiz.KeywhizConfig) Environment(io.dropwizard.setup.Environment) Test(org.junit.Test)

Aggregations

KeywhizConfig (keywhiz.KeywhizConfig)5 Test (org.junit.Test)3 Injector (com.google.inject.Injector)2 Environment (io.dropwizard.setup.Environment)2 SecureRandom (java.security.SecureRandom)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Configuration (io.dropwizard.Configuration)1 Bootstrap (io.dropwizard.setup.Bootstrap)1 Validator (javax.validation.Validator)1 KeywhizService (keywhiz.KeywhizService)1 StrictGuiceModule (keywhiz.inject.StrictGuiceModule)1 ContentCryptographer (keywhiz.service.crypto.ContentCryptographer)1 SecretTransformer (keywhiz.service.crypto.SecretTransformer)1 ServiceContext (keywhiz.test.ServiceContext)1