Search in sources :

Example 31 with Role

use of com.yahoo.athenz.zms.Role in project athenz by yahoo.

the class DataCacheTest method testPolicyNoRoleProcessed.

@Test
public void testPolicyNoRoleProcessed() {
    Domain domain = new Domain();
    domain.setName("testDomain");
    Role role1 = new Role();
    role1.setName("testDomain.role.role1");
    List<RoleMember> members1 = new ArrayList<>();
    members1.add(new RoleMember().setMemberName("user_domain.user1"));
    role1.setRoleMembers(members1);
    Policy policy = new Policy();
    policy.setName("testDomain.policy.policy1");
    Assertion assertion1 = new Assertion();
    assertion1.setAction("assume_role");
    assertion1.setEffect(AssertionEffect.ALLOW);
    assertion1.setResource("testDomain.roleA");
    assertion1.setRole("testDomain.role.role1");
    List<Assertion> assertList = new ArrayList<Assertion>();
    assertList.add(assertion1);
    policy.setAssertions(assertList);
    DataCache cache = new DataCache();
    HashMap<String, Role> roleList = new HashMap<>();
    roleList.put(role1.getName(), role1);
    cache.processPolicy(domain.getName(), policy, roleList);
    Set<MemberRole> set1 = cache.getMemberRoleSet("user_domain.user1");
    assertNotNull(set1);
    assertTrue(set1.contains(new MemberRole("testDomain.roleA", 0)));
    assertEquals(set1.size(), 1);
    Set<MemberRole> set2 = cache.getMemberRoleSet("user_domain.user2");
    assertNull(set2);
}
Also used : Policy(com.yahoo.athenz.zms.Policy) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Assertion(com.yahoo.athenz.zms.Assertion) DataCache(com.yahoo.athenz.zts.cache.DataCache) Role(com.yahoo.athenz.zms.Role) Domain(com.yahoo.athenz.zms.Domain) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 32 with Role

use of com.yahoo.athenz.zms.Role in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheNewDomain.

@Test
public void testAddDomainToCacheNewDomain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    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);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    DomainData domain = store.getDomainData("coretech");
    assertNotNull(domain);
    assertEquals(domain.getRoles().size(), 1);
    assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
    assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 1);
    assertEquals(domain.getRoles().get(0).getRoleMembers().get(0).getMemberName(), "user_domain.user");
}
Also used : 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) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 33 with Role

use of com.yahoo.athenz.zms.Role in project athenz by yahoo.

the class DataStoreTest method testAddDomainToCacheUpdatedDomain.

@Test
public void testAddDomainToCacheUpdatedDomain() {
    ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
    DataStore store = new DataStore(clogStore, null);
    DataCache dataCache = new DataCache();
    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);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    DomainData domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    /* update member list */
    role = new Role();
    role.setName("coretech:role.admin");
    members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user_domain.user1"));
    members.add(new RoleMember().setMemberName("user_domain.user2"));
    role.setRoleMembers(members);
    roles = new ArrayList<>();
    roles.add(role);
    dataCache = new DataCache();
    domainData = new DomainData();
    domainData.setRoles(roles);
    dataCache.setDomainData(domainData);
    store.addDomainToCache("coretech", dataCache);
    DomainData domain = store.getDomainData("coretech");
    assertNotNull(domain);
    assertEquals(domain.getRoles().size(), 1);
    assertEquals(domain.getRoles().get(0).getName(), "coretech:role.admin");
    assertEquals(domain.getRoles().get(0).getRoleMembers().size(), 2);
    boolean user1 = false;
    boolean user2 = false;
    for (RoleMember member : domain.getRoles().get(0).getRoleMembers()) {
        switch(member.getMemberName()) {
            case "user_domain.user1":
                user1 = true;
                break;
            case "user_domain.user2":
                user2 = true;
                break;
        }
    }
    assertTrue(user1);
    assertTrue(user2);
}
Also used : 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) ArrayList(java.util.ArrayList) DomainData(com.yahoo.athenz.zms.DomainData) MockZMSFileChangeLogStore(com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore) DataCache(com.yahoo.athenz.zts.cache.DataCache) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 34 with Role

use of com.yahoo.athenz.zms.Role in project athenz by yahoo.

the class JDBCConnectionTest method testInsertRoleWithTrust.

@Test
public void testInsertRoleWithTrust() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Role role = new Role().setName("my-domain:role.role1").setTrust("trust_domain");
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    Mockito.when(mockResultSet.next()).thenReturn(true);
    // return domain
    Mockito.when(mockResultSet.getInt(1)).thenReturn(5);
    boolean requestSuccess = jdbcConn.insertRole("my-domain", role);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "role1");
    Mockito.verify(mockPrepStmt, times(1)).setInt(2, 5);
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "trust_domain");
    jdbcConn.close();
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 35 with Role

use of com.yahoo.athenz.zms.Role in project athenz by yahoo.

the class JDBCConnectionTest method testUpdateRoleInvalidDomain.

@Test
public void testUpdateRoleInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Role role = new Role().setName("my-domain:role.role1");
    // domain id failure
    Mockito.when(mockResultSet.next()).thenReturn(false);
    try {
        jdbcConn.updateRole("my-domain", role);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Aggregations

Role (com.yahoo.athenz.zms.Role)94 Test (org.testng.annotations.Test)57 RoleMember (com.yahoo.athenz.zms.RoleMember)47 ArrayList (java.util.ArrayList)47 DomainData (com.yahoo.athenz.zms.DomainData)32 DataCache (com.yahoo.athenz.zts.cache.DataCache)31 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)27 Policy (com.yahoo.athenz.zms.Policy)22 SignedDomain (com.yahoo.athenz.zms.SignedDomain)22 Assertion (com.yahoo.athenz.zms.Assertion)20 MemberRole (com.yahoo.athenz.zts.cache.MemberRole)19 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)14 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.MockZMSFileChangeLogStore)13 ZMSFileChangeLogStore (com.yahoo.athenz.zts.store.impl.ZMSFileChangeLogStore)12 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 SQLException (java.sql.SQLException)9 HashMap (java.util.HashMap)8 ResourceException (com.yahoo.athenz.zms.ResourceException)7 Domain (com.yahoo.athenz.zms.Domain)6 File (java.io.File)6