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));
}
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));
}
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);
}
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);
}
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);
}
Aggregations