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);
}
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");
}
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);
}
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();
}
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();
}
Aggregations