Search in sources :

Example 1 with JWSDomain

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

the class ChangeLogStoreTest method testChangeLogStore.

@Test
public void testChangeLogStore() {
    ChangeLogStore store = new ChangeLogStore() {

        @Override
        public SignedDomain getLocalSignedDomain(String domainName) {
            return null;
        }

        @Override
        public SignedDomain getServerSignedDomain(String domainName) {
            return null;
        }

        @Override
        public void removeLocalDomain(String domainName) {
        }

        @Override
        public void saveLocalDomain(String domainName, SignedDomain signedDomain) {
        }

        @Override
        public List<String> getLocalDomainList() {
            return null;
        }

        @Override
        public Set<String> getServerDomainList() {
            return null;
        }

        @Override
        public SignedDomains getServerDomainModifiedList() {
            return null;
        }

        @Override
        public SignedDomains getUpdatedSignedDomains(StringBuilder lastModTimeBuffer) {
            return null;
        }

        @Override
        public void setLastModificationTimestamp(String lastModTime) {
        }

        @Override
        public boolean supportsFullRefresh() {
            return false;
        }
    };
    assertNull(store.getLocalJWSDomain("domain"));
    assertNull(store.getServerJWSDomain("domain"));
    assertNull(store.getUpdatedJWSDomains(null));
    store.saveLocalDomain("domain", new JWSDomain());
    store.setRequestConditions(true);
    store.setRequestConditions(false);
    store.setJWSDomainSupport(true);
    store.setJWSDomainSupport(false);
}
Also used : ChangeLogStore(com.yahoo.athenz.common.server.store.ChangeLogStore) JWSDomain(com.yahoo.athenz.zms.JWSDomain) SignedDomain(com.yahoo.athenz.zms.SignedDomain) Test(org.testng.annotations.Test)

Example 2 with JWSDomain

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

the class S3ChangeLogStore method getUpdatedJWSDomains.

@Override
public List<JWSDomain> getUpdatedJWSDomains(StringBuilder lastModTimeBuffer) {
    // get the updated domain list and fetch each one individually
    AmazonS3 s3 = getS3Client();
    List<String> domains = getUpdatedDomainList(s3, lastModTimeBuffer);
    List<JWSDomain> jwsDomainList = new ArrayList<>();
    for (String domain : domains) {
        JWSDomain jwsDomain = getJWSDomain(s3, domain);
        if (jwsDomain != null) {
            jwsDomainList.add(jwsDomain);
        }
    }
    return jwsDomainList;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) JWSDomain(com.yahoo.athenz.zms.JWSDomain)

Example 3 with JWSDomain

use of com.yahoo.athenz.zms.JWSDomain 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();
}
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 4 with JWSDomain

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

the class S3ChangeLogStoreTest method testNoOpMethods.

@Test
public void testNoOpMethods() {
    S3ChangeLogStore store = new S3ChangeLogStore();
    store.removeLocalDomain("iaas.athenz");
    store.saveLocalDomain("iaas.athenz", new SignedDomain());
    store.saveLocalDomain("iaas.athenz", new JWSDomain());
}
Also used : JWSDomain(com.yahoo.athenz.zms.JWSDomain) SignedDomain(com.yahoo.athenz.zms.SignedDomain) Test(org.testng.annotations.Test)

Example 5 with JWSDomain

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

the class S3ChangeLogStoreTest method testGetUpdatedJWSDomainsNoChanges.

@Test
public void testGetUpdatedJWSDomainsNoChanges() {
    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);
    ObjectListing objectListing = mock(ObjectListing.class);
    when(objectListing.getObjectSummaries()).thenReturn(objectList);
    when(objectListing.isTruncated()).thenReturn(false);
    when(store.awsS3Client.listObjects(any(ListObjectsRequest.class))).thenReturn(objectListing);
    // set the last modification time to not return any of the domains
    store.lastModTime = (new Date(250)).getTime();
    StringBuilder lastModTimeBuffer = new StringBuilder(512);
    List<JWSDomain> jwsDomains = store.getUpdatedJWSDomains(lastModTimeBuffer);
    assertTrue(lastModTimeBuffer.length() > 0);
    assertEquals(jwsDomains.size(), 0);
}
Also used : ListObjectsRequest(com.amazonaws.services.s3.model.ListObjectsRequest) JWSDomain(com.yahoo.athenz.zms.JWSDomain) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Test(org.testng.annotations.Test)

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