use of software.amazon.awssdk.services.s3.model.S3Object in project athenz by yahoo.
the class AwsPrivateKeyStoreTest method testGetPrivateKeyAlgorithm.
private void testGetPrivateKeyAlgorithm(final String service) throws IOException {
final String bucketName = "my_bucket";
final String keyName = "my_key";
final String algKeyName = "my_key.rsa";
final String keyId = "my_key_id";
final String algKeyId = "my_key_id.rsa";
final String expectedKeyId = "1";
System.setProperty("athenz.aws.s3.region", "us-east-1");
System.setProperty("athenz.aws." + service + ".bucket_name", bucketName);
System.setProperty("athenz.aws." + service + ".key_name", keyName);
System.setProperty("athenz.aws." + service + ".key_id_name", keyId);
AmazonS3 s3 = mock(AmazonS3.class);
AWSKMS kms = mock(AWSKMS.class);
S3Object s3ObjectKey = mock(S3Object.class);
Mockito.when(s3.getObject(bucketName, algKeyName)).thenReturn(s3ObjectKey);
File privKeyFile = new File("src/test/resources/unit_test_zts_private.pem");
final String privKey = new String(Files.readAllBytes(privKeyFile.toPath()), StandardCharsets.UTF_8);
InputStream isKey = new ByteArrayInputStream(privKey.getBytes());
S3ObjectInputStream s3ObjectKeyInputStream = new S3ObjectInputStream(isKey, null);
Mockito.when(s3ObjectKey.getObjectContent()).thenReturn(s3ObjectKeyInputStream);
S3Object s3ObjectKeyId = mock(S3Object.class);
Mockito.when(s3.getObject(bucketName, algKeyId)).thenReturn(s3ObjectKeyId);
InputStream isKeyId = new ByteArrayInputStream(expectedKeyId.getBytes());
S3ObjectInputStream s3ObjectKeyIdInputStream = new S3ObjectInputStream(isKeyId, null);
Mockito.when(s3ObjectKeyId.getObjectContent()).thenReturn(s3ObjectKeyIdInputStream);
AwsPrivateKeyStore awsPrivateKeyStore = new AwsPrivateKeyStore(s3, kms);
ServerPrivateKey serverPrivateKey = awsPrivateKeyStore.getPrivateKey(service, "testServerHostName", "us-east-1", "rsa");
assertNotNull(serverPrivateKey);
assertNotNull(serverPrivateKey.getKey());
assertEquals(serverPrivateKey.getAlgorithm().toString(), "RS256");
assertEquals(serverPrivateKey.getId(), "1");
System.clearProperty("athenz.aws.s3.region");
System.clearProperty("athenz.aws." + service + ".bucket_name");
System.clearProperty("athenz.aws." + service + ".key_name");
System.clearProperty("athenz.aws." + service + ".key_id_name");
}
use of software.amazon.awssdk.services.s3.model.S3Object in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetSignedDomainInternal.
@Test
public void testGetSignedDomainInternal() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
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("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
SignedDomain signedDomain = store.getSignedDomain(store.awsS3Client, "iaas");
assertNotNull(signedDomain);
DomainData domainData = signedDomain.getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
use of software.amazon.awssdk.services.s3.model.S3Object in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetUpdatedJWSDomainsWithChange1.
@Test
public void testGetUpdatedJWSDomainsWithChange1() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
ArrayList<S3ObjectSummary> objectList = new ArrayList<>();
S3ObjectSummary objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas");
objectSummary.setLastModified(new Date(100));
objectList.add(objectSummary);
objectSummary = new S3ObjectSummary();
objectSummary.setKey("iaas.athenz");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
// we'll also include an invalid domain that should be skipped
objectSummary = new S3ObjectSummary();
objectSummary.setKey("unknown");
objectSummary.setLastModified(new Date(200));
objectList.add(objectSummary);
ObjectListing objectListing = mock(ObjectListing.class);
when(objectListing.getObjectSummaries()).thenReturn(objectList);
when(objectListing.isTruncated()).thenReturn(false);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
InputStream is = new FileInputStream("src/test/resources/iaas.jws");
MockS3ObjectInputStream s3Is = new MockS3ObjectInputStream(is, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas.athenz")).thenReturn(object);
// set the last modification time to return one of the domains
store.lastModTime = (new Date(150)).getTime();
StringBuilder lastModTimeBuffer = new StringBuilder(512);
List<JWSDomain> jwsDomains = store.getUpdatedJWSDomains(lastModTimeBuffer);
assertTrue(lastModTimeBuffer.length() > 0);
assertEquals(jwsDomains.size(), 1);
is.close();
}
use of software.amazon.awssdk.services.s3.model.S3Object in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetSignedDomainException.
@Test
public void testGetSignedDomainException() throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore();
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("s3-unit-test-bucket-name", "iaas")).thenThrow(new AmazonServiceException("test")).thenReturn(object);
SignedDomain signedDomain = store.getLocalSignedDomain("iaas");
assertNotNull(signedDomain);
DomainData domainData = signedDomain.getDomain();
assertNotNull(domainData);
assertEquals(domainData.getName(), "iaas");
is.close();
}
use of software.amazon.awssdk.services.s3.model.S3Object in project athenz by yahoo.
the class S3ChangeLogStoreTest method testGetAllDomainsException.
public void testGetAllDomainsException(boolean jwsSupport) throws IOException {
MockS3ChangeLogStore store = new MockS3ChangeLogStore(1);
store.setJWSDomainSupport(jwsSupport);
InputStream is1 = new FileInputStream("src/test/resources/iaas.json");
MockS3ObjectInputStream s3Is1 = new MockS3ObjectInputStream(is1, null);
InputStream is2 = new FileInputStream("src/test/resources/iaas.json");
MockS3ObjectInputStream s3Is2 = new MockS3ObjectInputStream(is2, null);
S3Object object = mock(S3Object.class);
when(object.getObjectContent()).thenReturn(s3Is1).thenReturn(s3Is2);
when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
ObjectListing mockObjectListing = mock(ObjectListing.class);
when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(mockObjectListing);
List<S3ObjectSummary> tempList = new ArrayList<>();
S3ObjectSummary s3ObjectSummary = mock(S3ObjectSummary.class);
when(s3ObjectSummary.getKey()).thenReturn("iaas");
tempList.add(s3ObjectSummary);
when(mockObjectListing.getObjectSummaries()).thenReturn(tempList);
List<String> temp = new LinkedList<>();
temp.add("iaas");
try {
when(store.executorService.awaitTermination(defaultTimeoutSeconds, TimeUnit.SECONDS)).thenThrow(new InterruptedException());
assertFalse(store.getAllDomains(temp));
assertTrue(store.getLocalDomainList().size() > 0);
} catch (InterruptedException e) {
e.printStackTrace();
}
is1.close();
is2.close();
}
Aggregations