Search in sources :

Example 1 with ObjectStore

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);
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Example 2 with ObjectStore

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);
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Example 3 with ObjectStore

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;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 4 with ObjectStore

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;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Test(org.testng.annotations.Test)

Example 5 with ObjectStore

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;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Test(org.testng.annotations.Test)

Aggregations

ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)116 Test (org.testng.annotations.Test)116 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)62 ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)34 Authority (com.yahoo.athenz.auth.Authority)12 Principal (com.yahoo.athenz.auth.Principal)10 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)10 MemberDueDays (com.yahoo.athenz.zms.config.MemberDueDays)7 Timestamp (com.yahoo.rdl.Timestamp)7 JDBCConnection (com.yahoo.athenz.zms.store.impl.jdbc.JDBCConnection)4 IOException (java.io.IOException)4 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)2 EmbeddedMysql (com.wix.mysql.EmbeddedMysql)1 FilePrivateKeyStore (com.yahoo.athenz.auth.impl.FilePrivateKeyStore)1 Crypto (com.yahoo.athenz.auth.util.Crypto)1 AuditReferenceValidator (com.yahoo.athenz.common.server.audit.AuditReferenceValidator)1 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)1 ResourceUtils (com.yahoo.athenz.common.server.util.ResourceUtils)1 DataCache (com.yahoo.athenz.zms.DBService.DataCache)1 MockAuditReferenceValidatorImpl (com.yahoo.athenz.zms.audit.MockAuditReferenceValidatorImpl)1