Search in sources :

Example 36 with S3Object

use of com.amazonaws.services.s3.model.S3Object 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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) DecryptResult(com.amazonaws.services.kms.model.DecryptResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) S3Object(com.amazonaws.services.s3.model.S3Object) ByteBuffer(java.nio.ByteBuffer) DecryptRequest(com.amazonaws.services.kms.model.DecryptRequest) AWSKMS(com.amazonaws.services.kms.AWSKMS) Test(org.testng.annotations.Test)

Example 37 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetSignedDomainException.

@Test
public void testGetSignedDomainException() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
    InputStream is = new FileInputStream("src/test/resources/iaas.json");
    MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
    S3Object object = mock(S3Object.class);
    when(object.getObjectContent()).thenReturn(s3Is);
    // first call we return null, second call we return success
    when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenThrow(new AmazonServiceException("test")).thenReturn(object);
    SignedDomain signedDomain = store.getSignedDomain("iaas");
    assertNotNull(signedDomain);
    DomainData domainData = signedDomain.getDomain();
    assertNotNull(domainData);
    assertEquals(domainData.getName(), "iaas");
    is.close();
}
Also used : FileInputStream(java.io.FileInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) AmazonServiceException(com.amazonaws.AmazonServiceException) SignedDomain(com.yahoo.athenz.zms.SignedDomain) DomainData(com.yahoo.athenz.zms.DomainData) S3Object(com.amazonaws.services.s3.model.S3Object) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 38 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetSignedDomain.

@Test
public void testGetSignedDomain() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
    InputStream is = new FileInputStream("src/test/resources/iaas.json");
    MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
    S3Object object = mock(S3Object.class);
    when(object.getObjectContent()).thenReturn(s3Is);
    when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenReturn(object);
    SignedDomain signedDomain = store.getSignedDomain("iaas");
    assertNotNull(signedDomain);
    DomainData domainData = signedDomain.getDomain();
    assertNotNull(domainData);
    assertEquals(domainData.getName(), "iaas");
    is.close();
}
Also used : FileInputStream(java.io.FileInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) SignedDomain(com.yahoo.athenz.zms.SignedDomain) DomainData(com.yahoo.athenz.zms.DomainData) S3Object(com.amazonaws.services.s3.model.S3Object) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 39 with S3Object

use of com.amazonaws.services.s3.model.S3Object in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetSignedDomainInternal.

@Test
public void testGetSignedDomainInternal() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore(null);
    InputStream is = new FileInputStream("src/test/resources/iaas.json");
    MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
    S3Object object = mock(S3Object.class);
    when(object.getObjectContent()).thenReturn(s3Is);
    when(store.awsS3Client.getObject("athenz-domain-sys.auth", "iaas")).thenReturn(object);
    SignedDomain signedDomain = store.getSignedDomain(store.awsS3Client, "iaas");
    assertNotNull(signedDomain);
    DomainData domainData = signedDomain.getDomain();
    assertNotNull(domainData);
    assertEquals(domainData.getName(), "iaas");
    is.close();
}
Also used : FileInputStream(java.io.FileInputStream) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) InputStream(java.io.InputStream) SignedDomain(com.yahoo.athenz.zms.SignedDomain) DomainData(com.yahoo.athenz.zms.DomainData) S3Object(com.amazonaws.services.s3.model.S3Object) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Aggregations

S3Object (com.amazonaws.services.s3.model.S3Object)30 InputStream (java.io.InputStream)13 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)10 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)7 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)7 IOException (java.io.IOException)6 SignedDomain (com.yahoo.athenz.zms.SignedDomain)5 FileInputStream (java.io.FileInputStream)5 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)4 DomainData (com.yahoo.athenz.zms.DomainData)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Test (org.testng.annotations.Test)4 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)3 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)3 Date (java.util.Date)3 Exchange (org.apache.camel.Exchange)3 DecryptRequest (com.amazonaws.services.kms.model.DecryptRequest)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2