use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdatePrincipalByStateFromAuthorityExistingDisabled.
@Test
public void testUpdatePrincipalByStateFromAuthorityExistingDisabled() {
JDBCConnection jdbcConn = Mockito.mock(JDBCConnection.class);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(jdbcConn);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
DomainRoleMember drm = new DomainRoleMember();
MemberRole mr1 = new MemberRole().setMemberName("user.user1").setRoleName("role1").setDomainName("dom1").setSystemDisabled(1);
List<MemberRole> memberRoles = new ArrayList<>();
memberRoles.add(mr1);
drm.setMemberRoles(memberRoles);
DomainGroupMember dgm = new DomainGroupMember();
GroupMember gm1 = new GroupMember().setMemberName("user.user1").setGroupName("grp1").setDomainName("dom1").setSystemDisabled(1);
List<GroupMember> memberGroups = new ArrayList<>();
memberGroups.add(gm1);
dgm.setMemberGroups(memberGroups);
Mockito.when(jdbcConn.updatePrincipal("user.user1", 2)).thenReturn(true);
Mockito.when(jdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(jdbcConn.updateRoleMemberDisabledState("dom1", "role1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 2, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(jdbcConn.updateRoleModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(jdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
Mockito.when(jdbcConn.getPrincipalGroups("user.user1", null)).thenReturn(dgm);
Mockito.when(jdbcConn.updateGroupMemberDisabledState("dom1", "grp1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 2, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(jdbcConn.updateGroupModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(jdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
List<Principal> changedPrincipals = new ArrayList<>();
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user1", "user", null));
try {
zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, true);
} catch (ResourceException rex) {
fail();
}
Mockito.when(jdbcConn.updatePrincipal("user.user1", 0)).thenReturn(true);
Mockito.when(jdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(jdbcConn.updateRoleMemberDisabledState("dom1", "role1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 0, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(jdbcConn.updateRoleModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(jdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
Mockito.when(jdbcConn.getPrincipalGroups("user.user1", null)).thenReturn(dgm);
Mockito.when(jdbcConn.updateGroupMemberDisabledState("dom1", "grp1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 0, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(jdbcConn.updateGroupModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(jdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
try {
zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, false);
} catch (ResourceException rex) {
fail();
}
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeletePolicyFailureRetry.
@Test
public void testExecuteDeletePolicyFailureRetry() {
String domainName = "policy-delete-failure-retry";
String policyName = "policy1";
String version = "0";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Policy policy = new Policy().setName(policyName).setVersion(version).setActive(true);
Mockito.when(mockJdbcConn.getPolicy(domainName, policyName, version)).thenReturn(policy);
Mockito.when(mockJdbcConn.deletePolicy(domainName, policyName)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
Mockito.when(mockJdbcConn.listPolicyVersions(domainName, policyName)).thenReturn(Arrays.asList(version));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeletePolicy(mockDomRsrcCtx, domainName, policyName, auditRef, "deletePolicy");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUserAuthorityFilterEnforcerException.
@Test
public void testUserAuthorityFilterEnforcerException() {
Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
Authority authority = Mockito.mock(Authority.class);
zms.dbService.zmsConfig.setUserAuthority(authority);
Mockito.when(mockObjStore.getConnection(true, false)).thenThrow(new ResourceException(400, "invalid request"));
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
DBService.UserAuthorityFilterEnforcer enforcer = zms.dbService.new UserAuthorityFilterEnforcer();
// make sure no exceptions are thrown from the run call even if
// processing call throws an exceptions
enforcer.run();
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 testExecutePutMembershipDecisionBadRequest.
@Test
public void testExecutePutMembershipDecisionBadRequest() {
final String domainName = "put-mbr-decision-bad-request";
final String roleName = "role1";
TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser);
zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
zms.putRole(mockDomRsrcCtx, domainName, roleName, auditRef, role1);
zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe").setActive(false).setApproved(false), auditRef, "putMembership");
zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.bob").setActive(false).setApproved(false), auditRef, "putMembership");
RoleMember roleMem = new RoleMember().setMemberName("user.doe").setActive(true).setApproved(true);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role1);
Mockito.when(mockJdbcConn.confirmRoleMember(anyString(), anyString(), any(), anyString(), anyString())).thenReturn(false);
try {
zms.dbService.executePutMembershipDecision(mockDomRsrcCtx, domainName, roleName, roleMem, auditRef, "putMembershipDecision");
fail();
} catch (ResourceException r) {
assertEquals(r.getCode(), 400);
assertTrue(r.getMessage().contains("unable to apply role membership"));
}
zms.dbService.store = saveStore;
zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testGetRoleExpiryMembersFailure.
@Test
public void testGetRoleExpiryMembersFailure() {
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
Mockito.when(mockConn.updateRoleMemberExpirationNotificationTimestamp(anyString(), anyLong(), anyInt(), anyBoolean())).thenReturn(false);
assertNull(zms.dbService.getRoleExpiryMembers(1, false));
zms.dbService.store = saveStore;
}
Aggregations