use of com.amazonaws.services.kms.AWSKMS in project athenz by yahoo.
the class AwsPrivateKeyStoreTest method testAwsPrivateKeyStore.
@Test
public void testAwsPrivateKeyStore() throws Exception {
String bucketName = "my_bucket";
String keyName = "my_key";
String expected = "my_value";
AmazonS3 s3 = Mockito.mock(AmazonS3.class);
AWSKMS kms = Mockito.mock(AWSKMS.class);
S3Object s3Object = Mockito.mock(S3Object.class);
Mockito.when(s3.getObject(bucketName, keyName)).thenReturn(s3Object);
InputStream is = new ByteArrayInputStream(expected.getBytes());
S3ObjectInputStream s3ObjectInputStream = new S3ObjectInputStream(is, null);
Mockito.when(s3Object.getObjectContent()).thenReturn(s3ObjectInputStream);
String result = expected;
ByteBuffer buffer = ByteBuffer.wrap(result.getBytes());
DecryptResult decryptResult = Mockito.mock(DecryptResult.class);
Mockito.when(kms.decrypt(Mockito.any(DecryptRequest.class))).thenReturn(decryptResult);
Mockito.when(decryptResult.getPlaintext()).thenReturn(buffer);
AwsPrivateKeyStore awsPrivateKeyStore = new AwsPrivateKeyStore(s3, kms);
String actual = awsPrivateKeyStore.getApplicationSecret(bucketName, keyName);
Assert.assertEquals(actual, expected);
}
Aggregations