use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testSetMembersInDomainNullRoles.
@Test
public void testSetMembersInDomainNullRoles() {
String domainName = "null-roles";
Domain domain = new Domain().setModified(Timestamp.fromCurrentTime());
AthenzDomain athenzDomain = new AthenzDomain(domainName);
athenzDomain.setDomain(domain);
athenzDomain.setRoles(null);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false);
assertNull(resAthenzDomain.getRoles());
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutPolicyVersionConditionsFailure.
@Test
public void testExecutePutPolicyVersionConditionsFailure() {
String domainName = "policy-put-policy-version-condition-failure";
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 originalPolicyVersion = createPolicyObject(domainName, policyName);
Map<String, AssertionConditionData> conditionsMap = new HashMap<>();
conditionsMap.put("cond1", new AssertionConditionData().setValue("testVal"));
final List<AssertionCondition> assertionConditions = new ArrayList<>();
assertionConditions.add(new AssertionCondition().setConditionsMap(conditionsMap));
originalPolicyVersion.getAssertions().get(0).setConditions(new AssertionConditions().setConditionsList(assertionConditions));
originalPolicyVersion.getAssertions().get(0).setId(1L);
Mockito.when(mockJdbcConn.insertPolicy(domainName, originalPolicyVersion)).thenReturn(true);
Mockito.when(mockJdbcConn.listAssertions(eq(domainName), eq(policyName), isNull())).thenReturn(originalPolicyVersion.getAssertions());
Mockito.when(mockJdbcConn.getPolicy(eq(domainName), eq(policyName), isNull())).thenReturn(originalPolicyVersion);
Mockito.when(mockJdbcConn.insertAssertion(eq(domainName), eq(policyName), any(), any())).thenReturn(true);
Mockito.when(mockJdbcConn.getAssertionConditions(anyLong())).thenReturn(assertionConditions);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
// Put policy version - simulate failure in inserting assertion conditions
try {
zms.dbService.executePutPolicyVersion(mockDomRsrcCtx, domainName, policyName, "new-version", null, auditRef, "putPolicyVersion");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getMessage(), "ResourceException (500): {code: 500, message: \"unable to put policy: policy-put-policy-version-condition-failure:policy.policy1, version: new-version, fail inserting assertion conditions\"}");
}
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 testExecutePutMembershipInvalidRoleFailure.
@Test
public void testExecutePutMembershipInvalidRoleFailure() {
String domainName = "mgradddom1";
String roleName = "role1";
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertRoleMember(anyString(), anyString(), any(RoleMember.class), anyString(), anyString())).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(null);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe"), auditRef, "putMembership");
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 testExecuteDeleteDomainDependencyFailure.
@Test
public void testExecuteDeleteDomainDependencyFailure() {
String domainName = "deleteDomainDependencyFail1";
String serviceName = "svc1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.deleteDomainDependency(eq(domainName), eq(serviceName))).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.deleteDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "deleteDomainDependency");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutRoleRetryFailure.
@Test
public void testExecutePutRoleRetryFailure() {
String domainName = "executeputroledom1";
String roleName = "role1";
Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertRole(anyString(), any(Role.class))).thenThrow(new ResourceException(ResourceException.CONFLICT));
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executePutRole(mockDomRsrcCtx, domainName, roleName, role1, auditRef, "putRole");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.CONFLICT);
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
Aggregations