Search in sources :

Example 6 with ObjectStore

use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.

the class DBServiceTest method testSetMembersInDomainNullRoles.

@Test
public void testSetMembersInDomainNullRoles() {
    String domainName = "null-roles";
    Domain domain = new Domain().setModified(Timestamp.fromCurrentTime());
    AthenzDomain athenzDomain = new AthenzDomain(domainName);
    athenzDomain.setDomain(domain);
    athenzDomain.setRoles(null);
    Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false);
    assertNull(resAthenzDomain.getRoles());
    zms.dbService.store = saveStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Test(org.testng.annotations.Test)

Example 7 with ObjectStore

use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.

the class DBServiceTest method testExecutePutPolicyVersionConditionsFailure.

@Test
public void testExecutePutPolicyVersionConditionsFailure() {
    String domainName = "policy-put-policy-version-condition-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 originalPolicyVersion = createPolicyObject(domainName, policyName);
    Map<String, AssertionConditionData> conditionsMap = new HashMap<>();
    conditionsMap.put("cond1", new AssertionConditionData().setValue("testVal"));
    final List<AssertionCondition> assertionConditions = new ArrayList<>();
    assertionConditions.add(new AssertionCondition().setConditionsMap(conditionsMap));
    originalPolicyVersion.getAssertions().get(0).setConditions(new AssertionConditions().setConditionsList(assertionConditions));
    originalPolicyVersion.getAssertions().get(0).setId(1L);
    Mockito.when(mockJdbcConn.insertPolicy(domainName, originalPolicyVersion)).thenReturn(true);
    Mockito.when(mockJdbcConn.listAssertions(eq(domainName), eq(policyName), isNull())).thenReturn(originalPolicyVersion.getAssertions());
    Mockito.when(mockJdbcConn.getPolicy(eq(domainName), eq(policyName), isNull())).thenReturn(originalPolicyVersion);
    Mockito.when(mockJdbcConn.insertAssertion(eq(domainName), eq(policyName), any(), any())).thenReturn(true);
    Mockito.when(mockJdbcConn.getAssertionConditions(anyLong())).thenReturn(assertionConditions);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    int saveRetryCount = zms.dbService.defaultRetryCount;
    zms.dbService.defaultRetryCount = 2;
    // Put policy version - simulate failure in inserting assertion conditions
    try {
        zms.dbService.executePutPolicyVersion(mockDomRsrcCtx, domainName, policyName, "new-version", null, auditRef, "putPolicyVersion");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getMessage(), "ResourceException (500): {code: 500, message: \"unable to put policy: policy-put-policy-version-condition-failure:policy.policy1, version: new-version, fail inserting assertion conditions\"}");
    }
    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 8 with ObjectStore

use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.

the class DBServiceTest method testExecutePutMembershipInvalidRoleFailure.

@Test
public void testExecutePutMembershipInvalidRoleFailure() {
    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())).thenReturn(false);
    Domain domain = new Domain().setName(domainName);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(null);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    try {
        zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe"), auditRef, "putMembership");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    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 9 with ObjectStore

use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.

the class DBServiceTest method testExecuteDeleteDomainDependencyFailure.

@Test
public void testExecuteDeleteDomainDependencyFailure() {
    String domainName = "deleteDomainDependencyFail1";
    String serviceName = "svc1";
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.deleteDomainDependency(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.deleteDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "deleteDomainDependency");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
    }
    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 10 with ObjectStore

use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.

the class DBServiceTest method testExecutePutRoleRetryFailure.

@Test
public void testExecutePutRoleRetryFailure() {
    String domainName = "executeputroledom1";
    String roleName = "role1";
    Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.insertRole(anyString(), any(Role.class))).thenThrow(new ResourceException(ResourceException.CONFLICT));
    Domain domain = new Domain().setName(domainName);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    int saveRetryCount = zms.dbService.defaultRetryCount;
    zms.dbService.defaultRetryCount = 2;
    try {
        zms.dbService.executePutRole(mockDomRsrcCtx, domainName, roleName, role1, auditRef, "putRole");
        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)

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