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}");
}
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;
}
Aggregations