use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheRemovedHosts.
@Test
public void testAddDomainToCacheRemovedHosts() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
ServiceIdentity service = new ServiceIdentity();
service.setName("coretech.storage");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
hosts.add("host2");
hosts.add("host3");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* removed hosts */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
HostServices hostServices = store.getHostServices("host1");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 1);
assertTrue(hosts.contains("coretech.storage"));
hostServices = store.getHostServices("host2");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 0);
hostServices = store.getHostServices("host3");
hosts = hostServices.getNames();
assertEquals(hosts.size(), 0);
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataStoreTest method createSignedDomain.
private SignedDomain createSignedDomain(String domainName, String tenantDomain) {
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName(domainName + ":role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.writers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
members.add(new RoleMember().setMemberName("user_domain.user1"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user3"));
members.add(new RoleMember().setMemberName("user_domain.user4"));
role.setRoleMembers(members);
roles.add(role);
role = new Role();
role.setName(domainName + ":role.tenant.readers");
role.setTrust(tenantDomain);
roles.add(role);
List<com.yahoo.athenz.zms.Policy> policies = new ArrayList<>();
com.yahoo.athenz.zms.Policy policy = new com.yahoo.athenz.zms.Policy();
com.yahoo.athenz.zms.Assertion assertion = new com.yahoo.athenz.zms.Assertion();
assertion.setResource(domainName + ":tenant.weather.*");
assertion.setAction("read");
assertion.setRole(domainName + ":role.tenant.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policy.setName(domainName + ":policy.tenant.reader");
policies.add(policy);
ServiceIdentity service = new ServiceIdentity();
service.setName(domainName + ".storage");
setServicePublicKey(service, "0", "abcdefgh");
List<String> hosts = new ArrayList<>();
hosts.add("host1");
service.setHosts(hosts);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain(domainName);
domainPolicies.setPolicies(policies);
com.yahoo.athenz.zms.SignedPolicies signedPolicies = new com.yahoo.athenz.zms.SignedPolicies();
signedPolicies.setContents(domainPolicies);
signedPolicies.setSignature(Crypto.sign(SignUtils.asCanonicalString(domainPolicies), pkey));
signedPolicies.setKeyId("0");
DomainData domain = new DomainData();
domain.setName(domainName);
domain.setRoles(roles);
domain.setServices(services);
domain.setPolicies(signedPolicies);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), pkey));
signedDomain.setKeyId("0");
return signedDomain;
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheRemovedPublicKeysV0.
@Test
public void testAddDomainToCacheRemovedPublicKeysV0() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
ServiceIdentity service = new ServiceIdentity();
service.setName("coretech.storage");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* remove V0 public key */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
assertNull(store.getPublicKey("coretech", "storage", "0"));
assertEquals(store.getPublicKey("coretech", "storage", "1"), ZTS_PEM_CERT1);
assertNull(store.getPublicKey("coretech", "storage", "2"));
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class DataStoreTest method testAddDomainToCacheUpdatedPublicKeysV0.
@Test
public void testAddDomainToCacheUpdatedPublicKeysV0() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
DataCache dataCache = new DataCache();
ServiceIdentity service = new ServiceIdentity();
service.setName("coretech.storage");
setServicePublicKey(service, "0", ZTS_Y64_CERT0);
com.yahoo.athenz.zms.PublicKeyEntry publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
List<com.yahoo.athenz.zms.PublicKeyEntry> publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
List<ServiceIdentity> services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
DomainData domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
/* update V0 public key */
dataCache = new DataCache();
service = new ServiceIdentity();
service.setName("coretech.storage");
publicKeys = new ArrayList<com.yahoo.athenz.zms.PublicKeyEntry>();
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT2);
publicKey.setId("0");
publicKeys.add(publicKey);
publicKey = new com.yahoo.athenz.zms.PublicKeyEntry();
publicKey.setKey(ZTS_Y64_CERT1);
publicKey.setId("1");
publicKeys.add(publicKey);
service.setPublicKeys(publicKeys);
services = new ArrayList<>();
services.add(service);
dataCache.processServiceIdentity(service);
domainData = new DomainData();
domainData.setServices(services);
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
assertEquals(store.getPublicKey("coretech", "storage", "0"), ZTS_PEM_CERT2);
assertEquals(store.getPublicKey("coretech", "storage", "1"), ZTS_PEM_CERT1);
assertNull(store.getPublicKey("coretech", "storage", "2"));
}
use of com.yahoo.athenz.zms.ServiceIdentity in project athenz by yahoo.
the class JDBCConnectionTest method testUpdateServiceIdentity.
@Test
public void testUpdateServiceIdentity() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = new ServiceIdentity().setName("my-domain.service1");
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
Mockito.when(mockResultSet.next()).thenReturn(true);
// return domain id
Mockito.when(mockResultSet.getInt(1)).thenReturn(5).thenReturn(// service id
4);
boolean requestSuccess = jdbcConn.updateServiceIdentity("my-domain", service);
assertTrue(requestSuccess);
// get domain id
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
// get service id
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
// update service
Mockito.verify(mockPrepStmt, times(1)).setString(1, "");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "");
Mockito.verify(mockPrepStmt, times(1)).setInt(6, 4);
jdbcConn.close();
}
Aggregations