use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteGroupMemberFailureNotFound.
@Test
public void testExecuteDeleteGroupMemberFailureNotFound() {
final String domainName = "failure-del-group-mbr-domain";
final String groupName = "group1";
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.deleteGroupMember(domainName, groupName, memberName, adminName, auditRef)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteGroupMembership(mockDomRsrcCtx, domainName, groupName, memberName, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.NOT_FOUND, ex.getCode());
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutMembershipDecisionRetry.
@Test
public void testExecutePutMembershipDecisionRetry() {
final String domainName = "put-mbr-decision-retry";
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;
zms.dbService.defaultRetryCount = 2;
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role1);
ResourceException rex = new ResourceException(409);
Mockito.when(mockJdbcConn.confirmRoleMember(anyString(), anyString(), any(), anyString(), anyString())).thenThrow(rex);
try {
zms.dbService.executePutMembershipDecision(mockDomRsrcCtx, domainName, roleName, roleMem, auditRef, "putMembershipDecision");
fail();
} catch (ResourceException r) {
assertEquals(r.getCode(), 409);
assertTrue(r.getMessage().contains("Conflict"));
}
zms.dbService.store = saveStore;
zms.dbService.defaultRetryCount = 120;
zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupMemberFailure.
@Test
public void testExecutePutGroupMemberFailure() {
final String domainName = "failure-put-group-mbr-domain";
final String groupName = "group1";
final String memberName = "user.member1";
final String adminName = "user.user1";
GroupMember groupMember = new GroupMember().setMemberName(memberName);
Group group = new Group().setName(ResourceUtils.groupResourceName(domainName, groupName));
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.insertGroupMember(domainName, groupName, groupMember, adminName, auditRef)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutGroupMembership(mockDomRsrcCtx, domainName, group, groupMember, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.BAD_REQUEST, ex.getCode());
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteEntityFailure.
@Test
public void testExecuteDeleteEntityFailure() {
String domainName = "entitydelete1";
String entityName = "entity1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deleteEntity(domainName, entityName)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteEntity(mockDomRsrcCtx, domainName, entityName, auditRef, "deleteEntity");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.NOT_FOUND, ex.getCode());
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteAssertionCondition.
@Test
public void testExecuteDeleteAssertionCondition() {
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
String domain = "assertion-condition-dom";
String policy = "assertion-condition-pol";
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Domain dom = new Domain().setName(domain);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(conn);
Mockito.when(conn.getDomain(anyString())).thenReturn(dom);
AssertionCondition ac = new AssertionCondition();
ac.setConditionsMap(new HashMap<>());
Mockito.when(conn.getAssertionCondition(anyLong(), anyInt())).thenReturn(ac).thenReturn(ac).thenReturn(null).thenReturn(ac);
Mockito.when(conn.deleteAssertionCondition(anyLong(), anyInt())).thenReturn(true).thenReturn(false).thenThrow(new ResourceException(ResourceException.CONFLICT));
int savedRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
// happy path
try {
zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
} catch (ResourceException ignored) {
fail();
}
// db call failed
try {
zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
fail();
} catch (ResourceException re) {
assertEquals(re.getCode(), ResourceException.NOT_FOUND);
}
// null assertion condition from db
try {
zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
fail();
} catch (ResourceException re) {
assertEquals(re.getCode(), ResourceException.NOT_FOUND);
}
try {
zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
fail();
} catch (ResourceException re) {
assertEquals(re.getCode(), ResourceException.CONFLICT);
}
zms.dbService.defaultRetryCount = savedRetryCount;
zms.dbService.store = savedStore;
}
Aggregations