Search in sources :

Example 21 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class SignUtils method asStruct.

private static Struct asStruct(DomainData domainData) {
    // all of our fields are in canonical order based
    // on their attribute name
    Struct struct = new Struct();
    appendObject(struct, ATTR_ACCOUNT, domainData.getAccount());
    appendObject(struct, ATTR_AUDIT_ENABLED, domainData.getAuditEnabled());
    appendObject(struct, ATTR_CERT_DNS_DOMAIN, domainData.getCertDnsDomain());
    appendObject(struct, ATTR_ENABLED, domainData.getEnabled());
    if (domainData.getGroups() != null && !domainData.getGroups().isEmpty()) {
        Array structGroups = new Array();
        for (Group group : domainData.getGroups()) {
            structGroups.add(asStruct(group));
        }
        appendArray(struct, ATTR_GROUPS, structGroups);
    }
    appendObject(struct, ATTR_MEMBER_EXPIRY_DAYS, domainData.getMemberExpiryDays());
    appendObject(struct, ATTR_MODIFIED, domainData.getModified());
    appendObject(struct, ATTR_NAME, domainData.getName());
    SignedPolicies signedPolicies = domainData.getPolicies();
    if (signedPolicies != null) {
        Struct structSignedPolicies = new Struct();
        appendObject(structSignedPolicies, ATTR_CONTENTS, asStruct(signedPolicies.getContents()));
        appendObject(structSignedPolicies, ATTR_KEYID, signedPolicies.getKeyId());
        appendObject(struct, ATTR_POLICIES, structSignedPolicies);
        appendObject(structSignedPolicies, ATTR_SIGNATURE, signedPolicies.getSignature());
    }
    appendObject(struct, ATTR_ROLE_CERT_EXPIRY_MINS, domainData.getRoleCertExpiryMins());
    Array structRoles = new Array();
    if (domainData.getRoles() != null) {
        for (Role role : domainData.getRoles()) {
            structRoles.add(asStruct(role));
        }
    }
    appendArray(struct, ATTR_ROLES, structRoles);
    Array structServices = new Array();
    if (domainData.getServices() != null) {
        for (ServiceIdentity service : domainData.getServices()) {
            structServices.add(asStruct(service));
        }
    }
    appendObject(struct, ATTR_SERVICE_CERT_EXPIRY_MINS, domainData.getServiceCertExpiryMins());
    appendObject(struct, ATTR_SERVICE_EXPIRY_DAYS, domainData.getServiceExpiryDays());
    appendArray(struct, ATTR_SERVICES, structServices);
    appendObject(struct, ATTR_SIGN_ALGORITHM, domainData.getSignAlgorithm());
    appendObject(struct, ATTR_TOKEN_EXPIRY_MINS, domainData.getTokenExpiryMins());
    appendObject(struct, ATTR_YPMID, domainData.getYpmId());
    return struct;
}
Also used : Array(com.yahoo.rdl.Array) SignedPolicies(com.yahoo.athenz.zms.SignedPolicies) Role(com.yahoo.athenz.zms.Role) Group(com.yahoo.athenz.zms.Group) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) Struct(com.yahoo.rdl.Struct)

Example 22 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testDeleteExistent.

@Test
public void testDeleteExistent() {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    fstore.put("test1", JSON.bytes(data));
    fstore.delete("test1");
    Struct st = fstore.get("test1", Struct.class);
    assertNull(st);
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 23 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileMTLSChangeLogStoreTest method testGetLocalDomainListHidden.

@Test
public void testGetLocalDomainListHidden() throws InterruptedException, IOException, KeyRefresherException {
    ZMSFileMTLSChangeLogStore fstore = new ZMSFileMTLSChangeLogStore(FSTORE_PATH, keyPath, certPath, trustStorePath, trustStorePassword);
    ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    cstore.put("test1", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put(".test2", JSON.bytes(data));
    data = new Struct();
    data.put("key", "val1");
    cstore.put(".test3", JSON.bytes(data));
    List<String> ls = fstore.getLocalDomainList();
    assertEquals(ls.size(), 1);
    assertTrue(ls.contains("test1"));
}
Also used : Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 24 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileMTLSChangeLogStoreTest method testGetLocalDomainListSingle.

@Test
public void testGetLocalDomainListSingle() throws IOException, KeyRefresherException, InterruptedException {
    File rootDir = new File(FSTORE_PATH);
    // noinspection ResultOfMethodCallIgnored
    rootDir.mkdirs();
    Struct lastModStruct = new Struct();
    lastModStruct.put("lastModTime", 1001);
    File file = new File(FSTORE_PATH, ".lastModTime");
    Path path = Paths.get(file.toURI());
    Files.write(path, JSON.bytes(lastModStruct));
    ZMSFileMTLSChangeLogStore fstore = new ZMSFileMTLSChangeLogStore(FSTORE_PATH, keyPath, certPath, trustStorePath, trustStorePassword);
    ZMSFileChangeLogStoreCommon cstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    Struct data = new Struct();
    data.put("key", "val1");
    cstore.put("test1", JSON.bytes(data));
    List<String> ls = fstore.getLocalDomainList();
    assertEquals(ls.size(), 1);
    assertTrue(ls.contains("test1"));
}
Also used : Path(java.nio.file.Path) File(java.io.File) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Example 25 with Struct

use of com.yahoo.rdl.Struct in project athenz by yahoo.

the class ZMSFileChangeLogStoreCommonTest method testPutException.

@Test
public void testPutException() throws IOException {
    ZMSFileChangeLogStoreCommon fstore = new ZMSFileChangeLogStoreCommon(FSTORE_PATH);
    FilesHelper helper = Mockito.mock(FilesHelper.class);
    Mockito.when(helper.write(any(), any())).thenThrow(new IOException("io exception"));
    fstore.filesHelper = helper;
    Struct data = new Struct();
    data.put("key", "val1");
    try {
        fstore.put("test1", JSON.bytes(data));
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
}
Also used : IOException(java.io.IOException) FilesHelper(com.yahoo.athenz.common.server.util.FilesHelper) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Struct(com.yahoo.rdl.Struct) Test(org.testng.annotations.Test)

Aggregations

Struct (com.yahoo.rdl.Struct)61 Test (org.testng.annotations.Test)30 Array (com.yahoo.rdl.Array)10 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)7 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)5 Path (java.nio.file.Path)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Assertion (com.yahoo.athenz.zms.Assertion)3 Policy (com.yahoo.athenz.zms.Policy)3 ZpeMatch (com.yahoo.athenz.zpe.match.ZpeMatch)3 File (java.io.File)3 AuthzDetailsField (com.yahoo.athenz.common.config.AuthzDetailsField)2 FilesHelper (com.yahoo.athenz.common.server.util.FilesHelper)2 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AthenzConfig (com.yahoo.athenz.common.config.AthenzConfig)1