use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testInsertGroupMembersFailure.
@Test
public void testInsertGroupMembersFailure() {
final String domainName = "insert-group-members-errs";
final String groupName = "group1";
Mockito.when(mockJdbcConn.insertGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false).thenThrow(new ResourceException(400));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
List<GroupMember> groupMembers = new ArrayList<>();
groupMembers.add(new GroupMember().setMemberName("user.joe"));
groupMembers.add(new GroupMember().setMemberName("user.jane"));
assertFalse(zms.dbService.insertGroupMembers(mockDomRsrcCtx, mockJdbcConn, groupMembers, domainName, groupName, adminUser, auditRef, "unit-test"));
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteRoleFailureRetry.
@Test
public void testExecuteDeleteRoleFailureRetry() {
String domainName = "roledelete1";
String roleName = "role1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deleteRole(domainName, roleName)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeleteRole(mockDomRsrcCtx, domainName, roleName, auditRef, "deleteRole");
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 testUpdatePrincipalByStateFromAuthority.
@Test
public void testUpdatePrincipalByStateFromAuthority() {
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
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(null);
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(null);
List<GroupMember> memberGroups = new ArrayList<>();
memberGroups.add(gm1);
dgm.setMemberGroups(memberGroups);
Mockito.when(mockJdbcConn.updatePrincipal("user.user1", 2)).thenReturn(true);
Mockito.when(mockJdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(mockJdbcConn.updateRoleMemberDisabledState("dom1", "role1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 2, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(mockJdbcConn.updateRoleModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.getPrincipalGroups("user.user1", null)).thenReturn(dgm);
Mockito.when(mockJdbcConn.updateGroupMemberDisabledState("dom1", "grp1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 2, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(mockJdbcConn.updateGroupModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.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(mockJdbcConn.updatePrincipal("user.user1", 0)).thenReturn(true);
Mockito.when(mockJdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(mockJdbcConn.updateRoleMemberDisabledState("dom1", "role1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 0, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(mockJdbcConn.updateRoleModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.updateDomainModTimestamp(anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.getPrincipalGroups("user.user1", null)).thenReturn(dgm);
Mockito.when(mockJdbcConn.updateGroupMemberDisabledState("dom1", "grp1", "user.user1", ZMSConsts.SYS_AUTH_MONITOR, 0, "Athenz User Authority Enforcer")).thenReturn(true);
Mockito.when(mockJdbcConn.updateGroupModTimestamp(anyString(), anyString())).thenReturn(true);
Mockito.when(mockJdbcConn.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 testExecutePutGroupReviewDelError.
@Test
public void testExecutePutGroupReviewDelError() {
final String domainName = "group-review-del-error";
List<String> admins = new ArrayList<>();
admins.add(adminUser);
Timestamp thirtyDayExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) + TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES));
zms.dbService.makeDomain(mockDomRsrcCtx, ZMSTestUtils.makeDomainObject(domainName, "test desc", "org", false, "", 1234, "", 0), admins, null, auditRef);
Group group1 = createGroupObject(domainName, "group1", "user.john", "user.jane");
Timestamp timExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
group1.getGroupMembers().add(new GroupMember().setMemberName("user.tim").setExpiration(timExpiry).setApproved(true).setActive(true));
zms.dbService.executePutGroup(mockDomRsrcCtx, domainName, "group1", group1, "test");
Group incomingGroup = new Group().setName("group1");
List<GroupMember> incomingMembers = new ArrayList<>();
incomingMembers.add(new GroupMember().setMemberName("user.john").setActive(false).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
incomingMembers.add(new GroupMember().setMemberName("user.jane").setActive(true).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
incomingGroup.setGroupMembers(incomingMembers);
Domain resDom = zms.dbService.getDomain(domainName, true);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockConn);
Mockito.when(mockConn.getDomain(domainName)).thenReturn(resDom);
Mockito.when(mockConn.getGroup(domainName, "group1")).thenReturn(group1);
Mockito.when(mockConn.listGroupMembers(domainName, "group1", false)).thenReturn(group1.getGroupMembers());
Mockito.when(mockConn.deleteRoleMember(domainName, "role1", "user.john", adminUser, auditRef)).thenThrow(new ResourceException(ResourceException.NOT_FOUND));
MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), new Group().setMemberExpiryDays(10));
try {
zms.dbService.executePutGroupReview(mockDomRsrcCtx, domainName, "group1", incomingGroup, expiryDueDays, "review test");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
}
zms.dbService.store = saveStore;
Group resGroup = zms.dbService.getGroup(domainName, "group1", false, false);
assertEquals(group1.getGroupMembers().size(), 3);
int membersChecked = 0;
for (GroupMember groupMember : resGroup.getGroupMembers()) {
switch(groupMember.getMemberName()) {
case "user.john":
case "user.jane":
assertNull(groupMember.getExpiration());
assertTrue(groupMember.getApproved());
membersChecked += 1;
break;
case "user.tim":
assertEquals(groupMember.getExpiration(), timExpiry);
membersChecked += 1;
break;
}
}
assertEquals(membersChecked, 3);
zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain");
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeletePendingMemberFailureRetry.
@Test
public void testExecuteDeletePendingMemberFailureRetry() {
final String domainName = "pendingdeletembrretry";
final String roleName = "role1";
final String memberName = "user.member1";
final String adminName = "user.user1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deletePendingRoleMember(domainName, roleName, memberName, adminName, auditRef)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeletePendingMembership(mockDomRsrcCtx, domainName, roleName, memberName, auditRef, "deletePendingMember");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
Aggregations