use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataCacheTest method testPublicKeysMultipleVersionFormat.
@Test
public void testPublicKeysMultipleVersionFormat() {
Domain domain = new Domain();
domain.setName("testDomain");
ServiceIdentity service1 = new ServiceIdentity();
service1.setName("testDomain.storage1");
com.yahoo.athenz.zms.PublicKeyEntry keyEntry0 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry0.setId("0");
keyEntry0.setKey(ZTS_Y64_CERT0);
List<com.yahoo.athenz.zms.PublicKeyEntry> listKeys1 = new ArrayList<>();
listKeys1.add(keyEntry0);
service1.setPublicKeys(listKeys1);
ServiceIdentity service2 = new ServiceIdentity();
service2.setName("testDomain.storage2");
com.yahoo.athenz.zms.PublicKeyEntry keyEntry1 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry1.setId("0");
keyEntry1.setKey(ZTS_Y64_CERT1);
com.yahoo.athenz.zms.PublicKeyEntry keyEntry3 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry3.setId("3");
keyEntry3.setKey(ZTS_Y64_CERT2);
com.yahoo.athenz.zms.PublicKeyEntry keyEntry4 = new com.yahoo.athenz.zms.PublicKeyEntry();
keyEntry4.setId("4");
keyEntry4.setKey(ZTS_Y64_CERT3);
List<com.yahoo.athenz.zms.PublicKeyEntry> listKeys = new ArrayList<>();
listKeys.add(keyEntry1);
listKeys.add(keyEntry3);
listKeys.add(keyEntry4);
service2.setPublicKeys(listKeys);
ServiceIdentity service3 = new ServiceIdentity();
service3.setName("testDomain.storage3");
DataCache cache = new DataCache();
cache.processServiceIdentity(service1);
cache.processServiceIdentity(service2);
cache.processServiceIdentity(service3);
Map<String, String> publicKeyMap = cache.getPublicKeyMap();
assertEquals(publicKeyMap.size(), 4);
assertEquals(publicKeyMap.get("testDomain.storage1_0"), ZTS_PEM_CERT0);
assertEquals(publicKeyMap.get("testDomain.storage2_0"), ZTS_PEM_CERT1);
assertEquals(publicKeyMap.get("testDomain.storage2_3"), ZTS_PEM_CERT2);
assertEquals(publicKeyMap.get("testDomain.storage2_4"), ZTS_PEM_CERT3);
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class ZTSImplTest method testLookupServiceIdentityNoMatch.
@Test
public void testLookupServiceIdentityNoMatch() {
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(generateServiceIdentityName("coretech", "storage"));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
services.add(service);
service = new ServiceIdentity();
service.setName(generateServiceIdentityName("coretech", "backup"));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
services.add(service);
DomainData domain = new DomainData();
domain.setName("coretech");
domain.setServices(services);
com.yahoo.athenz.zts.ServiceIdentity svc = zts.lookupServiceIdentity(domain, "coretech.sync");
assertNull(svc);
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class ZTSImplTest method createSignedDomainExpiration.
private SignedDomain createSignedDomainExpiration(String domainName, String serviceName, Boolean enabled) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
String memberName = "user_domain.user1";
Role role = new Role();
role.setName(generateRoleName(domainName, "admin"));
List<RoleMember> members = new ArrayList<RoleMember>();
RoleMember roleMember = new RoleMember();
roleMember.setMemberName("user_domain.adminuser");
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role1"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() - 100));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(generateRoleName(domainName, "role2"));
members = new ArrayList<RoleMember>();
roleMember = new RoleMember();
roleMember.setMemberName(memberName);
roleMember.setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)));
members.add(roleMember);
role.setRoleMembers(members);
roles.add(role);
List<ServiceIdentity> services = new ArrayList<>();
ServiceIdentity service = new ServiceIdentity();
service.setName(generateServiceIdentityName(domainName, serviceName));
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
services.add(service);
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
domain.setServices(services);
domain.setModified(Timestamp.fromCurrentTime());
domain.setEnabled(enabled);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), privateKey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.ServiceIdentity 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.ServiceIdentity 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