use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdatePrincipalByStateFromAuthorityEmptyMembershipInDB.
@Test
public void testUpdatePrincipalByStateFromAuthorityEmptyMembershipInDB() {
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
DomainRoleMember drm = new DomainRoleMember();
List<MemberRole> memberRoles = new ArrayList<>();
drm.setMemberRoles(memberRoles);
DomainGroupMember dgm = new DomainGroupMember();
List<GroupMember> memberGroups = new ArrayList<>();
dgm.setMemberGroups(memberGroups);
Mockito.when(mockJdbcConn.updatePrincipal("user.user1", 2)).thenReturn(true);
Mockito.when(mockJdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(mockJdbcConn.getPrincipalGroups("user.user1", null)).thenReturn(dgm);
List<Principal> changedPrincipals = new ArrayList<>();
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user1", "user", null));
try {
zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, true);
} catch (ResourceException rex) {
fail();
}
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdateRoleMetaWithoutTag.
@Test
public void testUpdateRoleMetaWithoutTag() {
final String domainName = "sys.auth";
final String updateRoleMetaTag = "tag-key-update-role-meta-without-tag";
final List<String> updateRoleMetaTagValues = Collections.singletonList("update-meta-value");
final String roleName = "roleWithTagUpdateMeta";
ObjectStore savedStore = zms.dbService.store;
Role role = new Role().setName(roleName);
RoleMeta rm = new RoleMeta().setTags(Collections.singletonMap(updateRoleMetaTag, new TagValueList().setList(updateRoleMetaTagValues)));
// mock dbService store
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(conn.updateRole(any(), any())).thenReturn(true);
Mockito.when(conn.insertRoleTags(anyString(), anyString(), anyMap())).thenReturn(true);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn);
zms.dbService.store = mockObjStore;
// update role meta
zms.dbService.executePutRoleMeta(mockDomRsrcCtx, domainName, roleName, role, rm, auditRef, "testUpdateRoleMetaWithoutTag");
// assert tags to add contains role meta tags
ArgumentCaptor<String> roleCapture = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> domainCapture = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<Map<String, TagValueList>> tagInsertCapture = ArgumentCaptor.forClass(Map.class);
Mockito.verify(conn, times(1)).insertRoleTags(roleCapture.capture(), domainCapture.capture(), tagInsertCapture.capture());
assertEquals(roleName, roleCapture.getValue());
assertEquals(domainName, domainCapture.getValue());
Map<String, TagValueList> resultInsertTags = tagInsertCapture.getAllValues().get(0);
TagValueList tagValues = resultInsertTags.get(updateRoleMetaTag);
assertNotNull(tagValues);
assertTrue(tagValues.getList().containsAll(updateRoleMetaTagValues));
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeleteServiceIdentityFailure.
@Test
public void testExecuteDeleteServiceIdentityFailure() {
String domainName = "servicedelete1";
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.deleteServiceIdentity(domainName, serviceName)).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executeDeleteServiceIdentity(mockDomRsrcCtx, domainName, serviceName, auditRef, "deleteServiceIdentity");
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 testExecutePutServiceIdentityRetryException.
@Test
public void testExecutePutServiceIdentityRetryException() {
String domainName = "serviceadddom1";
String serviceName = "service1";
ServiceIdentity service = createServiceObject(domainName, serviceName, "http://localhost", "/usr/bin/java", "root", "users", "host1");
Domain domain = new Domain().setAuditEnabled(false);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Mockito.when(mockJdbcConn.insertServiceIdentity(domainName, service)).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.executePutServiceIdentity(mockDomRsrcCtx, domainName, serviceName, service, auditRef, "putServiceIdentity");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.CONFLICT, ex.getCode());
}
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 testGetServicePublicKeyEntryServiceUnavailable.
@Test
public void testGetServicePublicKeyEntryServiceUnavailable() {
final String domainName = "test1";
final String serviceName = "service1";
final String keyId = "0";
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockConn);
Mockito.when(mockConn.getPublicKeyEntry(domainName, serviceName, keyId, false)).thenThrow(new ResourceException(ResourceException.SERVICE_UNAVAILABLE));
try {
zms.dbService.getServicePublicKeyEntry(domainName, serviceName, keyId, false);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
}
zms.dbService.store = saveStore;
}
Aggregations