Search in sources :

Example 41 with ObjectStore

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

the class DBServiceTest method testExecuteDeleteGroupMemberFailureNotFound.

@Test
public void testExecuteDeleteGroupMemberFailureNotFound() {
    final String domainName = "failure-del-group-mbr-domain";
    final String groupName = "group1";
    final String memberName = "user.member1";
    final String adminName = "user.user1";
    Domain domain = new Domain().setAuditEnabled(false);
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    Mockito.when(mockJdbcConn.deleteGroupMember(domainName, groupName, memberName, adminName, auditRef)).thenReturn(false);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    try {
        zms.dbService.executeDeleteGroupMembership(mockDomRsrcCtx, domainName, groupName, memberName, auditRef);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.NOT_FOUND, ex.getCode());
    }
    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 42 with ObjectStore

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

the class DBServiceTest method testExecutePutMembershipDecisionRetry.

@Test
public void testExecutePutMembershipDecisionRetry() {
    final String domainName = "put-mbr-decision-retry";
    final String roleName = "role1";
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName, "Test Domain1", "testOrg", adminUser);
    zms.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
    zms.putRole(mockDomRsrcCtx, domainName, roleName, auditRef, role1);
    zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.doe").setActive(false).setApproved(false), auditRef, "putMembership");
    zms.dbService.executePutMembership(mockDomRsrcCtx, domainName, roleName, new RoleMember().setMemberName("user.bob").setActive(false).setApproved(false), auditRef, "putMembership");
    RoleMember roleMem = new RoleMember().setMemberName("user.doe").setActive(true).setApproved(true);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    zms.dbService.defaultRetryCount = 2;
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role1);
    ResourceException rex = new ResourceException(409);
    Mockito.when(mockJdbcConn.confirmRoleMember(anyString(), anyString(), any(), anyString(), anyString())).thenThrow(rex);
    try {
        zms.dbService.executePutMembershipDecision(mockDomRsrcCtx, domainName, roleName, roleMem, auditRef, "putMembershipDecision");
        fail();
    } catch (ResourceException r) {
        assertEquals(r.getCode(), 409);
        assertTrue(r.getMessage().contains("Conflict"));
    }
    zms.dbService.store = saveStore;
    zms.dbService.defaultRetryCount = 120;
    zms.deleteTopLevelDomain(mockDomRsrcCtx, domainName, auditRef);
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) Test(org.testng.annotations.Test)

Example 43 with ObjectStore

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

the class DBServiceTest method testExecutePutGroupMemberFailure.

@Test
public void testExecutePutGroupMemberFailure() {
    final String domainName = "failure-put-group-mbr-domain";
    final String groupName = "group1";
    final String memberName = "user.member1";
    final String adminName = "user.user1";
    GroupMember groupMember = new GroupMember().setMemberName(memberName);
    Group group = new Group().setName(ResourceUtils.groupResourceName(domainName, groupName));
    Domain domain = new Domain().setAuditEnabled(false);
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    Mockito.when(mockJdbcConn.insertGroupMember(domainName, groupName, groupMember, adminName, auditRef)).thenReturn(false);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    try {
        zms.dbService.executePutGroupMembership(mockDomRsrcCtx, domainName, group, groupMember, auditRef);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.BAD_REQUEST, ex.getCode());
    }
    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 44 with ObjectStore

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

the class DBServiceTest method testExecuteDeleteEntityFailure.

@Test
public void testExecuteDeleteEntityFailure() {
    String domainName = "entitydelete1";
    String entityName = "entity1";
    Domain domain = new Domain().setAuditEnabled(false);
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    Mockito.when(mockJdbcConn.deleteEntity(domainName, entityName)).thenReturn(false);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    try {
        zms.dbService.executeDeleteEntity(mockDomRsrcCtx, domainName, entityName, auditRef, "deleteEntity");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.NOT_FOUND, ex.getCode());
    }
    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 45 with ObjectStore

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

the class DBServiceTest method testExecuteDeleteAssertionCondition.

@Test
public void testExecuteDeleteAssertionCondition() {
    ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
    String domain = "assertion-condition-dom";
    String policy = "assertion-condition-pol";
    ObjectStore savedStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    Domain dom = new Domain().setName(domain);
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(conn);
    Mockito.when(conn.getDomain(anyString())).thenReturn(dom);
    AssertionCondition ac = new AssertionCondition();
    ac.setConditionsMap(new HashMap<>());
    Mockito.when(conn.getAssertionCondition(anyLong(), anyInt())).thenReturn(ac).thenReturn(ac).thenReturn(null).thenReturn(ac);
    Mockito.when(conn.deleteAssertionCondition(anyLong(), anyInt())).thenReturn(true).thenReturn(false).thenThrow(new ResourceException(ResourceException.CONFLICT));
    int savedRetryCount = zms.dbService.defaultRetryCount;
    zms.dbService.defaultRetryCount = 2;
    // happy path
    try {
        zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
    } catch (ResourceException ignored) {
        fail();
    }
    // db call failed
    try {
        zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
        fail();
    } catch (ResourceException re) {
        assertEquals(re.getCode(), ResourceException.NOT_FOUND);
    }
    // null assertion condition from db
    try {
        zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
        fail();
    } catch (ResourceException re) {
        assertEquals(re.getCode(), ResourceException.NOT_FOUND);
    }
    try {
        zms.dbService.executeDeleteAssertionCondition(mockDomRsrcCtx, domain, policy, 1L, 1, auditRef, "DeleteAssertionCondition");
        fail();
    } catch (ResourceException re) {
        assertEquals(re.getCode(), ResourceException.CONFLICT);
    }
    zms.dbService.defaultRetryCount = savedRetryCount;
    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