use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutServiceIdentitySystemMetaFailureInvalidDomain.
@Test
public void testExecutePutServiceIdentitySystemMetaFailureInvalidDomain() {
String domainName = "serviceadddom1";
String serviceName = "service1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(null);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
ServiceIdentitySystemMeta meta = new ServiceIdentitySystemMeta();
meta.setProviderEndpoint("https://localhost");
try {
zms.dbService.executePutServiceIdentitySystemMeta(mockDomRsrcCtx, domainName, serviceName, meta, "providerendpoint", auditRef, "putServiceIdentitySystemMeta");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testSetMembersInDomainEmptyMembers.
@Test
public void testSetMembersInDomainEmptyMembers() {
String domainName = "no-role-members";
List<RoleMember> roleMembers = new ArrayList<>();
roleMembers.add(new RoleMember().setMemberName("user.admin"));
Role role = new Role().setMembers(null).setRoleMembers(roleMembers);
List<Role> roles = new ArrayList<>();
roles.add(role);
Domain domain = new Domain().setModified(Timestamp.fromCurrentTime());
AthenzDomain athenzDomain = new AthenzDomain(domainName);
athenzDomain.setDomain(domain);
athenzDomain.setRoles(roles);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false);
assertNotNull(resAthenzDomain.getRoles());
List<RoleMember> roleMembersResult = resAthenzDomain.getRoles().get(0).getRoleMembers();
assertEquals(roleMembersResult.size(), 1);
assertEquals(roleMembersResult.get(0).getMemberName(), "user.admin");
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testGetPendingDomainGroupMembersList.
@Test
public void testGetPendingDomainGroupMembersList() {
String domainName = "domain1";
String principal = "user.user1";
Map<String, List<DomainGroupMember>> dummyResult = new LinkedHashMap<>();
dummyResult.put(domainName, Collections.singletonList(new DomainGroupMember()));
dummyResult.put("domain2", Collections.singletonList(new DomainGroupMember()));
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getPendingDomainGroupMembersByPrincipal(principal)).thenReturn(dummyResult);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
DomainGroupMembership domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, domainName);
assertNotNull(domainGroupMembership);
assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
assertEquals(domainGroupMembership.getDomainGroupMembersList().get(0).domainName, domainName);
domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, "domain2");
assertNotNull(domainGroupMembership);
assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
assertEquals(domainGroupMembership.getDomainGroupMembersList().get(0).domainName, "domain2");
domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, "*");
assertNotNull(domainGroupMembership);
assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 2);
domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, null);
assertNotNull(domainGroupMembership);
assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 2);
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testProcessRoleUserAuthorityRestrictions.
@Test
public void testProcessRoleUserAuthorityRestrictions() {
Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
Authority authority = Mockito.mock(Authority.class);
Mockito.when(authority.getDateAttribute("user.joe", "elevated-clearance")).thenReturn(null);
zms.dbService.zmsConfig.setUserAuthority(authority);
final String domainName = "authority-test";
final String roleName = "auth-role";
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockConn.insertRoleMember(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(true);
Mockito.when(mockConn.updateDomainModTimestamp(domainName)).thenReturn(true);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockConn);
// first we're going to return a null role and then a role
// with no members - in both cases we return without processing
// any code
Role role = new Role().setUserAuthorityExpiration("elevated-clearance");
List<RoleMember> roleMembers = new ArrayList<>();
roleMembers.add(new RoleMember().setMemberName("user.joe"));
Mockito.when(mockConn.getRole(domainName, roleName)).thenReturn(role);
Mockito.when(mockConn.listRoleMembers(domainName, roleName, false)).thenReturn(roleMembers);
// first we're going to return no roles and then list of roles
// in the second one
List<PrincipalRole> roles = new ArrayList<>();
PrincipalRole prRole = new PrincipalRole();
prRole.setDomainName(domainName);
prRole.setRoleName(roleName);
roles.add(prRole);
Mockito.when(mockConn.listRolesWithUserAuthorityRestrictions()).thenReturn(null).thenReturn(roles);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
// the request should complete successfully
// first time we'll get no roles so no work is done
// second time we'll get a single role that we'll process
zms.dbService.processRoleUserAuthorityRestrictions();
zms.dbService.processRoleUserAuthorityRestrictions();
zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutMembershipFailure.
@Test
public void testExecutePutMembershipFailure() {
String domainName = "mgradddom1";
String roleName = "role1";
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertRoleMember(anyString(), anyString(), any(RoleMember.class), anyString(), anyString())).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Role role = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe"), auditRef, "putMembership");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
}
zms.dbService.store = saveStore;
}
Aggregations