use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testDeleteDomainFromCacheServices.
@Test
public void testDeleteDomainFromCacheServices() {
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 ZMSUtilsTest method getRoles.
@DataProvider(name = "roles")
public static Object[][] getRoles() {
String domainName = "test_domain";
Role role1 = new Role();
String memberName = "member";
RoleMember roleMember = new RoleMember().setMemberName(memberName);
Role role2 = new Role();
role2.setMembers(Arrays.asList(memberName));
role2.setRoleMembers(Arrays.asList(roleMember));
Role role3 = new Role();
role3.setRoleMembers(Arrays.asList(roleMember));
Role role4 = new Role();
role4.setRoleMembers(Arrays.asList(roleMember));
role4.setTrust("trust");
Role role5 = new Role();
role5.setMembers(Arrays.asList(memberName));
role5.setTrust("trust");
Role role6 = new Role();
role6.setTrust("trust");
return new Object[][] { { domainName, role1, false }, { domainName, role2, true }, { domainName, role3, false }, { domainName, role4, true }, { domainName, role5, true }, { "trust", role6, true }, { "test_domain", role6, false } };
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class JDBCConnectionTest method testInsertRoleMember.
@Test
public void testInsertRoleMember() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7).thenReturn(// principal id
9);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for role id
true).thenReturn(// validate principle domain
true).thenReturn(// principal id
true).thenReturn(// member exists
false);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertRoleMember("my-domain", "role1", new RoleMember().setMemberName("user.user1"), "user.admin", "audit-ref");
// this is combined for all operations above
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.user1");
// we need additional operation for the audit log
// additional operation to check for roleMember exist using roleID and principal ID.
Mockito.verify(mockPrepStmt, times(3)).setInt(1, 7);
Mockito.verify(mockPrepStmt, times(2)).setInt(2, 9);
// the rest of the audit log details
Mockito.verify(mockPrepStmt, times(1)).setString(2, "user.admin");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "user.user1");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "ADD");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "audit-ref");
assertTrue(requestSuccess);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class JDBCConnectionTest method testInsertRoleMemberException.
@Test
public void testInsertRoleMemberException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7).thenReturn(// member domain id
9).thenReturn(// principal id
11);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for role id
true).thenReturn(// member domain id
true).thenReturn(// principal id
true).thenReturn(// role member exists
false);
Mockito.when(mockPrepStmt.executeUpdate()).thenThrow(new SQLException("failed operation", "state", 1001));
try {
jdbcConn.insertRoleMember("my-domain", "role1", new RoleMember().setMemberName("user.user1"), "user.admin", "audit-ref");
fail();
} catch (Exception ex) {
assertTrue(true);
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.RoleMember in project athenz by yahoo.
the class DataStoreTest method testValidateSignedDomainMissingRole.
@Test
public void testValidateSignedDomainMissingRole() {
ChangeLogStore clogStore = new MockZMSFileChangeLogStore("/tmp/zts_server_unit_tests/zts_root", pkey, "0");
DataStore store = new DataStore(clogStore, null);
store.loadZMSPublicKeys();
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);
roles.add(role);
DomainData domain = new DomainData();
domain.setRoles(roles);
signedDomain.setDomain(domain);
signedDomain.setSignature(Crypto.sign(SignUtils.asCanonicalString(domain), pkey));
signedDomain.setKeyId("0");
domain.setRoles(null);
signedDomain.setDomain(domain);
assertFalse(store.validateSignedDomain(signedDomain));
}
Aggregations