Search in sources :

Example 6 with JWSDomain

use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetJWSDomainException.

@Test
public void testGetJWSDomainException() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore();
    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);
    // 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);
    JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
    assertNotNull(jwsDomain);
    is.close();
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) JWSDomain(com.yahoo.athenz.zms.JWSDomain) AmazonServiceException(com.amazonaws.AmazonServiceException) S3Object(com.amazonaws.services.s3.model.S3Object) Test(org.testng.annotations.Test)

Example 7 with JWSDomain

use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetLocalJWSDomainList.

@Test
public void testGetLocalJWSDomainList() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore(0);
    store.setJWSDomainSupport(true);
    InputStream is1 = new FileInputStream("src/test/resources/iaas.jws");
    MockS3ObjectInputStream s3Is1 = new MockS3ObjectInputStream(is1, null);
    InputStream is2 = new FileInputStream("src/test/resources/iaas.jws");
    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 = store.getLocalDomainList();
    assertNotNull(temp);
    JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
    assertNotNull(jwsDomain);
    is1.close();
    is2.close();
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) JWSDomain(com.yahoo.athenz.zms.JWSDomain) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) S3Object(com.amazonaws.services.s3.model.S3Object) Test(org.testng.annotations.Test)

Example 8 with JWSDomain

use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.

the class S3ChangeLogStoreTest method testGetLocalJWSDomain.

@Test
public void testGetLocalJWSDomain() throws IOException {
    MockS3ChangeLogStore store = new MockS3ChangeLogStore();
    InputStream is1 = new FileInputStream("src/test/resources/iaas.jws");
    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);
    // first we'll return null from our s3 client
    store.resetAWSS3Client();
    JWSDomain jwsDomain = store.getLocalJWSDomain("iaas");
    assertNull(jwsDomain);
    // next setup our mock aws return object
    when(store.awsS3Client.getObject("s3-unit-test-bucket-name", "iaas")).thenReturn(object);
    jwsDomain = store.getLocalJWSDomain("iaas");
    assertNotNull(jwsDomain);
    jwsDomain = store.getLocalJWSDomain("iaas");
    assertNotNull(jwsDomain);
    is1.close();
    is2.close();
}
Also used : S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) JWSDomain(com.yahoo.athenz.zms.JWSDomain) S3Object(com.amazonaws.services.s3.model.S3Object) Test(org.testng.annotations.Test)

Example 9 with JWSDomain

use of com.yahoo.athenz.zms.JWSDomain in project athenz by yahoo.

the class S3ChangeLogStore method getLocalJWSDomain.

@Override
public JWSDomain getLocalJWSDomain(String domainName) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("getLocalJWSDomain: {}", domainName);
    }
    // clear the mapping if present and value is stored else null is returned
    JWSDomain jwsDomain = tempJWSDomainMap.remove(domainName);
    if (jwsDomain == null) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("getLocalJWSDomain: not present in cache, fetching from S3...");
        }
        if (awsS3Client == null) {
            awsS3Client = getS3Client();
        }
        jwsDomain = getJWSDomain(awsS3Client, domainName);
        if (jwsDomain == null) {
            awsS3Client = getS3Client();
            jwsDomain = getJWSDomain(awsS3Client, domainName);
        }
    }
    return jwsDomain;
}
Also used : JWSDomain(com.yahoo.athenz.zms.JWSDomain)

Aggregations

JWSDomain (com.yahoo.athenz.zms.JWSDomain)9 Test (org.testng.annotations.Test)7 S3Object (com.amazonaws.services.s3.model.S3Object)4 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)4 ListObjectsRequest (com.amazonaws.services.s3.model.ListObjectsRequest)3 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)3 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)3 SignedDomain (com.yahoo.athenz.zms.SignedDomain)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)1