use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class JDBCObjectStoreFactoryTest method testCreateWriteOnly.
@Test
public void testCreateWriteOnly() {
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_STORE, "jdbc:mysql://localhost");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_USER, "user");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_PASSWORD, "password");
System.clearProperty(ZMSConsts.ZMS_PROP_JDBC_RO_STORE);
System.clearProperty(ZMSConsts.ZMS_PROP_JDBC_RO_USER);
System.clearProperty(ZMSConsts.ZMS_PROP_JDBC_RO_PASSWORD);
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
Mockito.doReturn("password").when(keyStore).getApplicationSecret("jdbc", "password");
JDBCObjectStoreFactory factory = new JDBCObjectStoreFactory();
ObjectStore store = factory.create(keyStore);
assertNotNull(store);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class JDBCObjectStoreFactoryTest method testCreateReadWrite.
@Test
public void testCreateReadWrite() {
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_STORE, "jdbc:mysql://localhost");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_USER, "user");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RW_PASSWORD, "password");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RO_STORE, "jdbc:mysql://localhost");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RO_USER, "user");
System.setProperty(ZMSConsts.ZMS_PROP_JDBC_RO_PASSWORD, "password");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
Mockito.doReturn("password").when(keyStore).getApplicationSecret("jdbc", "password");
JDBCObjectStoreFactory factory = new JDBCObjectStoreFactory();
ObjectStore store = factory.create(keyStore);
assertNotNull(store);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecuteDeletePolicyVersionFailure.
@Test
public void testExecuteDeletePolicyVersionFailure() {
String domainName = "policy-delete-version";
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);
originalPolicyVersion.setActive(false);
Mockito.when(mockJdbcConn.getPolicy(eq(domainName), eq(policyName), eq("0"))).thenReturn(originalPolicyVersion);
Mockito.when(mockJdbcConn.deletePolicyVersion(eq(domainName), eq(policyName), eq("0"))).thenReturn(false);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executeDeletePolicyVersion(mockDomRsrcCtx, domainName, policyName, "0", auditRef, "deletePolicyVersion");
fail();
} catch (Exception ex) {
assertEquals(ex.getMessage(), "ResourceException (404): {code: 404, message: \"deletePolicyVersion: unable to delete policy: policy1, version: 0\"}");
}
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 testExecutePutMembershipRetryFailure.
@Test
public void testExecutePutMembershipRetryFailure() {
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())).thenThrow(new ResourceException(ResourceException.CONFLICT));
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
Role role = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
int saveRetryCount = zms.dbService.defaultRetryCount;
zms.dbService.defaultRetryCount = 2;
try {
zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe"), auditRef, "putMembership");
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 testProcessDomainWithUpdateNullTags.
@Test
public void testProcessDomainWithUpdateNullTags() {
ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
ObjectStore savedStore = zms.dbService.store;
Map<String, TagValueList> domainTags = new HashMap<>();
domainTags.put("tagToBeRemoved", new TagValueList().setList(Collections.singletonList("val0")));
domainTags.put("tagKey", new TagValueList().setList(Arrays.asList("val1", "val2")));
Domain domain = new Domain().setName("newDomain").setTags(domainTags);
Mockito.when(conn.insertDomain(domain)).thenReturn(true);
Mockito.when(conn.insertDomainTags("newDomain", domainTags)).thenReturn(true);
Mockito.when(conn.insertRole(anyString(), any(Role.class))).thenReturn(true);
Mockito.when(conn.insertRoleMember(any(), any(), any(), any(), any())).thenReturn(true);
Mockito.when(conn.insertPolicy(any(), any())).thenReturn(true);
Mockito.when(conn.insertAssertion(any(), any(), any(), any())).thenReturn(true);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn);
zms.dbService.store = mockObjStore;
Domain createdDomain = zms.dbService.makeDomain(mockDomRsrcCtx, domain, Collections.singletonList(adminUser), null, auditRef);
assertEquals(createdDomain.getTags(), domainTags);
Mockito.when(conn.updateDomain(any(Domain.class))).thenReturn(true);
Mockito.when(conn.deleteDomainTags(anyString(), anySet())).thenReturn(true);
Mockito.when(conn.insertDomainTags(anyString(), anyMap())).thenReturn(true);
Mockito.when(conn.getDomain("newDomain")).thenReturn(domain);
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(conn).thenReturn(conn).thenReturn(conn).thenReturn(conn);
// update domain meta
DomainMeta meta = new DomainMeta().setTags(null);
zms.dbService.executePutDomainMeta(mockDomRsrcCtx, domain, meta, null, false, auditRef, "putDomainMeta");
assertEquals(createdDomain.getTags(), domainTags);
zms.dbService.store = savedStore;
}
Aggregations