use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testEnforceRoleUserAuthorityFilterRestrictionsUpdate.
@Test
public void testEnforceRoleUserAuthorityFilterRestrictionsUpdate() {
Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
Authority authority = Mockito.mock(Authority.class);
Mockito.when(authority.isAttributeSet("user.joe", "employee")).thenReturn(false);
Mockito.when(authority.isAttributeSet("user.jane", "employee")).thenReturn(true);
zms.dbService.zmsConfig.setUserAuthority(authority);
final String domainName = "authority-test";
final String roleName = "auth-role";
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockConn.insertRoleMember(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(true);
Mockito.when(mockConn.updateDomainModTimestamp(domainName)).thenReturn(true);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
// first we're going to return a null role and then a role
// with no members - in both cases we return without processing
// any code
Role role = new Role().setUserAuthorityFilter("employee");
List<RoleMember> roleMembers = new ArrayList<>();
roleMembers.add(new RoleMember().setMemberName("user.joe"));
roleMembers.add(new RoleMember().setMemberName("user.jane"));
Mockito.when(mockConn.getRole(domainName, roleName)).thenReturn(role);
Mockito.when(mockConn.listRoleMembers(domainName, roleName, false)).thenReturn(roleMembers);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
// the request should complete successfully
zms.dbService.enforceRoleUserAuthorityRestrictions(domainName, roleName, null);
zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupMembershipDecisionFailure.
@Test
public void testExecutePutGroupMembershipDecisionFailure() {
final String domainName = "put-group-mbr-dec-err";
final String groupName = "group1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.confirmGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false).thenThrow(new ResourceException(409));
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
zms.dbService.defaultRetryCount = 2;
Group group = createGroupObject(domainName, groupName, "user.joe", "user.jane");
GroupMember groupMember = new GroupMember().setMemberName("user.john");
try {
zms.dbService.executePutGroupMembershipDecision(mockDomRsrcCtx, domainName, group, groupMember, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.BAD_REQUEST, ex.getCode());
}
try {
zms.dbService.executePutGroupMembershipDecision(mockDomRsrcCtx, domainName, group, groupMember, auditRef);
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteMemberFailureNotFound.
@Test
public void testExecuteDeleteMemberFailureNotFound() {
final String domainName = "deletembrnotfound";
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.deleteRoleMember(domainName, roleName, memberName, adminName, auditRef)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteMembership(mockDomRsrcCtx, domainName, roleName, memberName, auditRef, "deleteMember");
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 testExecutePutDomainDependencyFailure.
@Test
public void testExecutePutDomainDependencyFailure() {
String domainName = "putDomainDependencyFail1";
String serviceName = "svc1";
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertDomainDependency(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.putDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "putDomainDependency");
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 testExecuteDeletePublicKeyEntryFailureRetry.
@Test
public void testExecuteDeletePublicKeyEntryFailureRetry() {
String domainName = "servicepubpubkeydom1";
String serviceName = "service1";
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.deletePublicKeyEntry(domainName, serviceName, "0")).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.executeDeletePublicKeyEntry(mockDomRsrcCtx, domainName, serviceName, "0", auditRef, "deletePublicKeyEntry");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
Aggregations