Search in sources :

Example 1 with SignedPolicies

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

the class SignUtilsTest method testAsStructRoleService.

@Test
public void testAsStructRoleService() {
    List<Role> roles = new ArrayList<Role>();
    Role mRole = Mockito.mock(Role.class);
    roles.add(mRole);
    List<String> items = new ArrayList<String>();
    String item = "check_item";
    items.add(item);
    List<ServiceIdentity> services = new ArrayList<ServiceIdentity>();
    ServiceIdentity mService = Mockito.mock(ServiceIdentity.class);
    services.add(mService);
    List<PublicKeyEntry> publicKeys = new ArrayList<PublicKeyEntry>();
    PublicKeyEntry mPublicKey = Mockito.mock(PublicKeyEntry.class);
    publicKeys.add(mPublicKey);
    SignedPolicies signedPolicies = Mockito.mock(SignedPolicies.class);
    Mockito.when(mockDomain.getEnabled()).thenReturn(null);
    Mockito.when(mockDomain.getAccount()).thenReturn("chk_string");
    Mockito.when(mockDomain.getRoles()).thenReturn(roles);
    Mockito.when(mRole.getMembers()).thenReturn(items);
    Mockito.when(mockDomain.getServices()).thenReturn(services);
    Mockito.when(mService.getHosts()).thenReturn(null);
    Mockito.when(mService.getPublicKeys()).thenReturn(publicKeys);
    Mockito.when(mockDomain.getPolicies()).thenReturn(signedPolicies);
    Mockito.when(signedPolicies.getContents()).thenReturn(mockPolicies);
    String check = SignUtils.asCanonicalString(mockDomain);
    assertNotNull(check);
    assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[{}]}],\"ypmId\":0}");
    Mockito.when(mService.getPublicKeys()).thenReturn(null);
    check = SignUtils.asCanonicalString(mockDomain);
    assertNotNull(check);
    assertEquals(check, "{\"account\":\"chk_string\",\"policies\":{\"contents\":{\"policies\":[]}},\"roles\":[{\"members\":[\"check_item\"],\"roleMembers\":[]}],\"services\":[{\"publicKeys\":[]}],\"ypmId\":0}");
}
Also used : Role(com.yahoo.athenz.zms.Role) PublicKeyEntry(com.yahoo.athenz.zms.PublicKeyEntry) SignedPolicies(com.yahoo.athenz.zms.SignedPolicies) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with SignedPolicies

use of com.yahoo.athenz.zms.SignedPolicies 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_ENABLED, domainData.getEnabled());
    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());
    }
    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));
        }
    }
    appendArray(struct, ATTR_SERVICES, structServices);
    appendObject(struct, ATTR_YPMID, domainData.getYpmId());
    return struct;
}
Also used : SignedPolicies(com.yahoo.athenz.zms.SignedPolicies) Array(com.yahoo.rdl.Array) Role(com.yahoo.athenz.zms.Role) ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) Struct(com.yahoo.rdl.Struct)

Aggregations

Role (com.yahoo.athenz.zms.Role)2 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)2 SignedPolicies (com.yahoo.athenz.zms.SignedPolicies)2 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)1 Array (com.yahoo.rdl.Array)1 Struct (com.yahoo.rdl.Struct)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1