Search in sources :

Example 16 with DataCache

use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.

the class DataStoreTest method testProcessDomainUpdatesFromZMSWithUpdater.

@Test
public void testProcessDomainUpdatesFromZMSWithUpdater() {
    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);
    store.lastDeleteRunTime = System.currentTimeMillis() - 24 * 60 * 60;
    DataUpdater updater = store.new DataUpdater();
    updater.run();
    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"));
}
Also used : ArrayList(java.util.ArrayList) SignedDomains(com.yahoo.athenz.zms.SignedDomains) DataCache(com.yahoo.athenz.zts.cache.DataCache) Role(com.yahoo.athenz.zms.Role) MemberRole(com.yahoo.athenz.zts.cache.MemberRole) ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) SignedDomain(com.yahoo.athenz.zms.SignedDomain) DataUpdater(com.yahoo.athenz.zts.store.DataStore.DataUpdater) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) RoleMember(com.yahoo.athenz.zms.RoleMember) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 17 with DataCache

use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.

the class DataStoreTest method testProcessTrustedDomainMemberRoleNotValid.

@Test
public void testProcessTrustedDomainMemberRoleNotValid() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = createDataCache("coretech");
    Set<String> accessibleRoles = new HashSet<>();
    String prefix = "coretech" + ROLE_POSTFIX;
    String identity = "user_domain.user1";
    String[] requestedRoleList = { "coretech:role.writers" };
    /* invalid role causing no match */
    Set<String> trustedResources = new HashSet<>();
    trustedResources.add("coretech:role.admin");
    trustedResources.add("coretech:role.readers");
    store.processTrustedDomain(dataCache, identity, prefix, requestedRoleList, trustedResources, accessibleRoles, false);
    assertEquals(accessibleRoles.size(), 0);
}
Also used : ZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 18 with DataCache

use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.

the class ZTSImplTest method testEvaluateAccessNoAssertions.

@Test
public void testEvaluateAccessNoAssertions() {
    DataCache domain = new DataCache();
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domain.setDomainData(domainData);
    domainData.setRoles(new ArrayList<Role>());
    Role role = new Role().setName("coretech:role.role1");
    domainData.getRoles().add(role);
    Policy policy = new Policy().setName("coretech:policy.policy1");
    domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
    domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
    domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
    domainData.getPolicies().getContents().getPolicies().add(policy);
    assertEquals(authorizer.evaluateAccess(domain, null, null, null, null), AccessStatus.DENIED);
}
Also used : Role(com.yahoo.athenz.zms.Role) Policy(com.yahoo.athenz.zms.Policy) DomainData(com.yahoo.athenz.zms.DomainData) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 19 with DataCache

use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.

the class ZTSImplTest method testEvaluateAccessAssertionDeny.

@Test
public void testEvaluateAccessAssertionDeny() {
    DataCache domain = new DataCache();
    DomainData domainData = new DomainData();
    domainData.setName("coretech");
    domain.setDomainData(domainData);
    domainData.setRoles(new ArrayList<Role>());
    Role role = createRoleObject("coretech", "role1", null, "user_domain.user1", null);
    domainData.getRoles().add(role);
    Policy policy = new Policy().setName("coretech:policy.policy1");
    Assertion assertion = new Assertion();
    assertion.setAction("read");
    assertion.setEffect(AssertionEffect.DENY);
    assertion.setResource("coretech:*");
    assertion.setRole("coretech:role.role1");
    policy.setAssertions(new ArrayList<Assertion>());
    policy.getAssertions().add(assertion);
    domainData.setPolicies(new com.yahoo.athenz.zms.SignedPolicies());
    domainData.getPolicies().setContents(new com.yahoo.athenz.zms.DomainPolicies());
    domainData.getPolicies().getContents().setPolicies(new ArrayList<Policy>());
    domainData.getPolicies().getContents().getPolicies().add(policy);
    assertEquals(authorizer.evaluateAccess(domain, "user_domain.user1", "read", "coretech:resource1", null), AccessStatus.DENIED);
}
Also used : Role(com.yahoo.athenz.zms.Role) Policy(com.yahoo.athenz.zms.Policy) DomainData(com.yahoo.athenz.zms.DomainData) Assertion(com.yahoo.athenz.zms.Assertion) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Example 20 with DataCache

use of com.yahoo.athenz.zts.cache.DataCache in project athenz by yahoo.

the class DataCacheTest method testProcessRoleMembersWithWildcards.

@Test
public void testProcessRoleMembersWithWildcards() {
    List<RoleMember> members1 = new ArrayList<>();
    members1.add(new RoleMember().setMemberName("user_domain.user1"));
    members1.add(new RoleMember().setMemberName("user_domain.user2"));
    members1.add(new RoleMember().setMemberName("user_domain.*"));
    members1.add(new RoleMember().setMemberName("user_domain.user*"));
    members1.add(new RoleMember().setMemberName("*"));
    DataCache cache = new DataCache();
    cache.processRoleMembers("dom.role1", members1);
    Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
    assertNotNull(set1);
    assertTrue(set1.contains(new MemberRole("dom.role1", 0)));
    assertEquals(set1.size(), 1);
    Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
    assertNotNull(set2);
    assertTrue(set2.contains(new MemberRole("dom.role1", 0)));
    assertEquals(set2.size(), 1);
    Set<MemberRole> set3 = cache.getAllMemberRoleSet();
    assertNotNull(set3);
    assertTrue(set3.contains(new MemberRole("dom.role1", 0)));
    assertEquals(set3.size(), 1);
    Map<String, Set<MemberRole>> setMap = cache.getPrefixMemberRoleSetMap();
    assertNotNull(setMap);
    assertEquals(setMap.size(), 2);
    Set<MemberRole> set4 = setMap.get("user_domain.");
    assertNotNull(set4);
    assertTrue(set4.contains(new MemberRole("dom.role1", 0)));
    assertEquals(set4.size(), 1);
    Set<MemberRole> set5 = setMap.get("user_domain.user");
    assertNotNull(set5);
    assertTrue(set5.contains(new MemberRole("dom.role1", 0)));
    assertEquals(set5.size(), 1);
}
Also used : Set(java.util.Set) ArrayList(java.util.ArrayList) RoleMember(com.yahoo.athenz.zms.RoleMember) DataCache(com.yahoo.athenz.zts.cache.DataCache) Test(org.testng.annotations.Test)

Aggregations

DataCache (com.yahoo.athenz.zts.cache.DataCache)84 Test (org.testng.annotations.Test)68 ArrayList (java.util.ArrayList)44 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)39 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)38 DomainData (com.yahoo.athenz.zms.DomainData)32 Role (com.yahoo.athenz.zms.Role)31 HashSet (java.util.HashSet)24 RoleMember (com.yahoo.athenz.zms.RoleMember)23 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)17 SignedDomain (com.yahoo.athenz.zms.SignedDomain)14 Policy (com.yahoo.athenz.zms.Policy)13 Domain (com.yahoo.athenz.zms.Domain)12 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)12 Set (java.util.Set)12 Assertion (com.yahoo.athenz.zms.Assertion)7 HostServices (com.yahoo.athenz.zts.HostServices)6 HashMap (java.util.HashMap)6 SignedDomains (com.yahoo.athenz.zms.SignedDomains)5 Principal (com.yahoo.athenz.auth.Principal)4