use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdateGroupMemberDisabledStateFailure.
@Test
public void testUpdateGroupMemberDisabledStateFailure() {
final String domainName = "update-group-members-disabled-errs";
final String groupName = "group1";
Mockito.when(mockJdbcConn.updateGroupMemberDisabledState(anyString(), anyString(), anyString(), anyString(), anyInt(), anyString())).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
List<GroupMember> groupMembers = new ArrayList<>();
groupMembers.add(new GroupMember().setMemberName("user.joe").setSystemDisabled(1));
groupMembers.add(new GroupMember().setMemberName("user.jane").setSystemDisabled(1));
assertFalse(zms.dbService.updateGroupMemberDisabledState(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 testExecuteDeleteAssertionNotFoundFailure.
@Test
public void testExecuteDeleteAssertionNotFoundFailure() {
String domainName = "policy-assertion-delete-notfound-failure";
String policyName = "policy1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.getAssertion(domainName, policyName, 1001L)).thenReturn(null);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteAssertion(mockDomRsrcCtx, domainName, policyName, null, 1001L, auditRef, "deleteAssertion");
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 testExecutePutAssertionFailureRetry.
@Test
public void testExecutePutAssertionFailureRetry() {
String domainName = "policy-put-assertion-failure-retry";
String policyName = "policy1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Assertion assertion = new Assertion().setRole("reader").setResource("table").setAction("update").setId(1001L);
Mockito.when(mockJdbcConn.insertAssertion(domainName, policyName, null, assertion)).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.executePutAssertion(mockDomRsrcCtx, domainName, policyName, null, assertion, auditRef, "putAssertion");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
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 testExecuteSetActivePolicyRetryException.
@Test
public void testExecuteSetActivePolicyRetryException() {
String domainName = "policy-set-active-retry";
String policyName = "policy1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Policy policy = createPolicyObject(domainName, policyName);
Mockito.when(mockJdbcConn.getPolicy(eq(domainName), eq(policyName), isNull())).thenReturn(policy);
Mockito.when(mockJdbcConn.getPolicy(eq(domainName), eq(policyName), eq("1"))).thenReturn(policy);
Mockito.when(mockJdbcConn.setActivePolicyVersion(eq(domainName), eq(policyName), eq("1"))).thenThrow(new ResourceException(ResourceException.CONFLICT, "db conflict"));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeSetActivePolicy(mockDomRsrcCtx, domainName, policyName, "1", auditRef, "setActivePolicy");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
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 testGetPrincipals.
@Test
public void testGetPrincipals() {
List<String> dbPrincipals = Arrays.asList("user.user1", "user.user2", "dom1.svc1");
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getPrincipals(2)).thenReturn(dbPrincipals);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
List<Principal> principals = zms.dbService.getPrincipals(2);
assertNotNull(principals);
assertEquals(principals.size(), 3);
zms.dbService.store = savedStore;
}
Aggregations