use of com.yahoo.athenz.zms.store.ObjectStoreConnection 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;
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBServiceTest method testRemovePrincipalFromDomainRolesExceptions.
@Test
public void testRemovePrincipalFromDomainRolesExceptions() {
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn.getPrincipalRoles("user.joe", "dom1")).thenThrow(new ResourceException(404)).thenThrow(new ResourceException(501));
try {
zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
fail();
} catch (ResourceException ex) {
assertEquals(404, ex.getCode());
}
try {
zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
fail();
} catch (ResourceException ex) {
assertEquals(501, ex.getCode());
}
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBServiceTest method testRemovePrincipalFromDomainRolesDeleteUserException.
@Test
public void testRemovePrincipalFromDomainRolesDeleteUserException() {
DomainRoleMember roles = new DomainRoleMember();
roles.setMemberRoles(new ArrayList<>());
MemberRole role1 = new MemberRole();
role1.setDomainName("dom1");
role1.setRoleName("role1");
roles.getMemberRoles().add(role1);
MemberRole role2 = new MemberRole();
role2.setDomainName("dom1");
role2.setRoleName("role2");
roles.getMemberRoles().add(role2);
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn.getPrincipalRoles("user.joe", "dom1")).thenReturn(roles);
Mockito.when(conn.deleteRoleMember("dom1", "role1", "user.joe", adminUser, "unittest")).thenReturn(true);
Mockito.when(conn.deleteRoleMember("dom1", "role2", "user.joe", adminUser, "unittest")).thenThrow(new ResourceException(501));
// we should handle the exception without any errors
zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBServiceTest method testValidateGroupUserAuthorityAttrRequirements.
@Test
public void testValidateGroupUserAuthorityAttrRequirements() {
Group originalGroup = new Group().setName("group1").setUserAuthorityFilter("OnShore-US");
Group updatedGroup = new Group().setName("group1");
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn.getPrincipalRoles("group1", null)).thenThrow(new ResourceException(ResourceException.BAD_REQUEST));
try {
zms.dbService.validateGroupUserAuthorityAttrRequirements(conn, originalGroup, updatedGroup, "unittest");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
}
// now we're going to mock the use case where the role no longer exists
List<MemberRole> memberRoles = new ArrayList<>();
memberRoles.add(new MemberRole().setDomainName("coretech").setRoleName("role1"));
DomainRoleMember domainRoleMember = new DomainRoleMember();
domainRoleMember.setMemberRoles(memberRoles);
ObjectStoreConnection conn2 = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn2.getPrincipalRoles("group1", null)).thenReturn(domainRoleMember);
Mockito.when(conn2.getRole("coretech", "role1")).thenReturn(null);
// the call will complete without any exceptions and no changes
zms.dbService.validateGroupUserAuthorityAttrRequirements(conn2, originalGroup, updatedGroup, "unittest");
}
use of com.yahoo.athenz.zms.store.ObjectStoreConnection in project athenz by yahoo.
the class DBServiceTest method testUpdateDomainMembersUserAuthorityFilterFailure.
@Test
public void testUpdateDomainMembersUserAuthorityFilterFailure() {
final String domainName = "domain-meta-user-authority-filter";
Domain domain = new Domain().setName(domainName).setUserAuthorityFilter("contractor").setModified(Timestamp.fromCurrentTime());
Domain updateDomain = new Domain().setName(domainName).setUserAuthorityFilter("employee");
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
// we're going to make sure to throw an exception here
// since this should never be called
Mockito.when(mockConn.getAthenzDomain(domainName)).thenThrow(new ResourceException(400));
Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
Authority authority = Mockito.mock(Authority.class);
zms.dbService.zmsConfig.setUserAuthority(authority);
zms.dbService.updateDomainMembersUserAuthorityFilter(mockDomRsrcCtx, mockConn, domain, updateDomain, auditRef, "testUpdateDomainMembersUserAuthorityFilterFailure");
zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
}
Aggregations