use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testProcessDomainPolicies.
@Test
public void testProcessDomainPolicies() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
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("sports:role.readers");
assertion.setAction("assume_role");
assertion.setRole("coretech:role.readers");
List<com.yahoo.athenz.zms.Assertion> assertions = new ArrayList<>();
assertions.add(assertion);
policy.setAssertions(assertions);
policies.add(policy);
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName("coretech: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("coretech:role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
roles.add(role);
com.yahoo.athenz.zms.DomainPolicies domainPolicies = new com.yahoo.athenz.zms.DomainPolicies();
domainPolicies.setDomain("coretech");
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 domainData = new DomainData();
domainData.setName("coretech");
domainData.setPolicies(signedPolicies);
domainData.setRoles(roles);
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.processDomainRoles(domainData, dataCache);
assertEquals(dataCache.getMemberRoleSet("user_domain.user").size(), 2);
assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.admin", 0)));
assertTrue(dataCache.getMemberRoleSet("user_domain.user").contains(new MemberRole("coretech:role.readers", 0)));
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method createDataCacheWildCard.
private DataCache createDataCacheWildCard(String domainName) {
DataCache dataCache = new DataCache();
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);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.readers");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user1"));
members.add(new RoleMember().setMemberName("user_domain.joe"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.editors");
members = new ArrayList<>();
members.add(new RoleMember().setMemberName("*"));
role.setRoleMembers(members);
roles.add(role);
dataCache.processRole(role);
role = new Role();
role.setName(domainName + ":role.writers");
role.setTrust(domainName + "Trust");
roles.add(role);
dataCache.processRole(role);
DomainData domainData = new DomainData();
domainData.setName(domainName);
domainData.setRoles(roles);
dataCache.setDomainData(domainData);
return dataCache;
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testDeleteDomain.
@Test
public void testDeleteDomain() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
SignedDomain signedDomain = new SignedDomain();
List<Role> roles = new ArrayList<>();
Role role = new Role();
role.setName("coretech:role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user"));
role.setRoleMembers(members);
DomainData domainData = new DomainData();
domainData.setName("coretech");
domainData.setRoles(roles);
signedDomain.setDomain(domainData);
signedDomain.setKeyId("0");
((MockZMSFileChangeLogStore) store.changeLogStore).put("coretech", JSON.bytes(signedDomain));
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.addDomainToCache("coretech", dataCache);
store.deleteDomainFromCache("coretech");
store.changeLogStore.removeLocalDomain("coretech");
assertNull(store.getCacheStore().getIfPresent("coretech"));
File file = new File("/tmp/zts_server_unit_tests/zts_root/coretech");
assertFalse(file.exists());
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testProcessDomainUpdatesFromZMS.
@Test
public void testProcessDomainUpdatesFromZMS() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
((MockZMSFileChangeLogStore) store.changeLogStore).setTagHeader("2014-01-01T12:00:00");
store.loadZMSPublicKeys();
SignedDomain signedDomain = createSignedDomain("coretech", "weather");
store.processDomain(signedDomain, true);
List<SignedDomain> domains = new ArrayList<>();
/* we're going to create a new domain */
signedDomain = createSignedDomain("sports", "weather");
domains.add(signedDomain);
/* we're going to update the coretech domain and set new roles */
signedDomain = createSignedDomain("coretech", "weather");
Role role = new Role();
role.setName("coretech:role.admin");
List<RoleMember> members = new ArrayList<>();
members.add(new RoleMember().setMemberName("user_domain.user8"));
role.setRoleMembers(members);
List<Role> roles = new ArrayList<>();
roles.add(role);
signedDomain.getDomain().setRoles(roles);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(signedDomain.getDomain()), pkey));
domains.add(signedDomain);
SignedDomains signedDomains = new SignedDomains();
signedDomains.setDomains(domains);
((MockZMSFileChangeLogStore) store.changeLogStore).setSignedDomains(signedDomains);
boolean result = store.processDomainUpdates();
assertTrue(result);
Set<String> accessibleRoles = new HashSet<>();
DataCache data = store.getDataCache("coretech");
store.getAccessibleRoles(data, "coretech", "user_domain.user1", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 0);
accessibleRoles = new HashSet<>();
store.getAccessibleRoles(data, "coretech", "user_domain.user8", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 1);
assertTrue(accessibleRoles.contains("admin"));
accessibleRoles = new HashSet<>();
data = store.getDataCache("sports");
store.getAccessibleRoles(data, "sports", "user_domain.user", null, accessibleRoles, false);
assertEquals(accessibleRoles.size(), 2);
assertTrue(accessibleRoles.contains("admin"));
assertTrue(accessibleRoles.contains("writers"));
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method addDomainToDataStore.
private void addDomainToDataStore(DataStore store, String domainName) {
SignedDomain signedDomain = new SignedDomain();
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);
List<Role> roles = new ArrayList<>();
roles.add(role);
DomainData domainData = new DomainData();
domainData.setName(domainName);
domainData.setRoles(roles);
signedDomain.setDomain(domainData);
signedDomain.setKeyId("0");
((MockZMSFileChangeLogStore) store.changeLogStore).put(domainName, JSON.bytes(signedDomain));
DataCache dataCache = new DataCache();
dataCache.setDomainData(domainData);
store.addDomainToCache(domainName, dataCache);
}
Aggregations