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;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdatePrincipalByStateFromAuthorityExceptionUpdateRoleMembership.
@Test
public void testUpdatePrincipalByStateFromAuthorityExceptionUpdateRoleMembership() {
JDBCConnection jdbcConn = Mockito.mock(JDBCConnection.class);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(jdbcConn);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Mockito.when(jdbcConn.updatePrincipal("user.user3", 2)).thenReturn(true);
Mockito.when(jdbcConn.updatePrincipal("user.user4", 2)).thenReturn(true);
Mockito.when(jdbcConn.getPrincipalRoles("user.user3", null)).thenThrow(new ResourceException(ResourceException.NOT_FOUND, "not found"));
Mockito.when(jdbcConn.getPrincipalRoles("user.user4", null)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
List<Principal> changedPrincipals = new ArrayList<>();
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user3", "user", null));
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user4", "user", null));
try {
zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, true);
fail();
} catch (ResourceException rex) {
assertEquals(rex.getCode(), ResourceException.CONFLICT);
}
Mockito.verify(jdbcConn, atLeastOnce()).getPrincipalRoles("user.user3", null);
Mockito.verify(jdbcConn, atLeastOnce()).getPrincipalRoles("user.user4", null);
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteSetActivePolicyFailure.
@Test
public void testExecuteSetActivePolicyFailure() {
String domainName = "policy-set-active-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 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"))).thenReturn(false);
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 (Exception ex) {
assertEquals(ex.getMessage(), "ResourceException (500): {code: 500, message: \"unable to set active policy version: 1 for policy: policy1 in domain: policy-set-active-failure\"}");
}
zms.dbService.defaultRetryCount = saveRetryCount;
zms.dbService.store = saveStore;
}
Aggregations