Search in sources :

Example 76 with ObjectStore

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

the class DBServiceTest method testExecutePutGroupReviewRetry.

@Test
public void testExecutePutGroupReviewRetry() {
    final String domainName = "group-review-retry";
    List<String> admins = new ArrayList<>();
    admins.add(adminUser);
    Timestamp thirtyDayExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) + TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES));
    zms.dbService.makeDomain(mockDomRsrcCtx, ZMSTestUtils.makeDomainObject(domainName, "test desc", "org", false, "", 1234, "", 0), admins, null, auditRef);
    Group group1 = createGroupObject(domainName, "group1", "user.john", "user.jane");
    Timestamp timExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
    group1.getGroupMembers().add(new GroupMember().setMemberName("user.tim").setExpiration(timExpiry).setApproved(true).setActive(true));
    zms.dbService.executePutGroup(mockDomRsrcCtx, domainName, "group1", group1, "putgroup");
    Group incomingGroup = new Group().setName("group1");
    List<GroupMember> incomingMembers = new ArrayList<>();
    incomingMembers.add(new GroupMember().setMemberName("user.john").setActive(false).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
    incomingMembers.add(new GroupMember().setMemberName("user.jane").setActive(true).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
    incomingGroup.setGroupMembers(incomingMembers);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    int saveRetryCount = zms.dbService.defaultRetryCount;
    zms.dbService.defaultRetryCount = 2;
    ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockConn);
    Mockito.when(mockConn.getDomain(domainName)).thenThrow(new ResourceException(ResourceException.CONFLICT));
    MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), new Group().setMemberExpiryDays(10));
    try {
        zms.dbService.executePutGroupReview(mockDomRsrcCtx, domainName, "group1", incomingGroup, expiryDueDays, "review test");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.CONFLICT);
    }
    // getDomain gets called to check domain auditEnabled requirement. verification of 2 retries happened
    verify(mockConn, times(2)).getDomain(domainName);
    zms.dbService.store = saveStore;
    zms.dbService.defaultRetryCount = saveRetryCount;
    Group resGroup = zms.dbService.getGroup(domainName, "group1", false, false);
    assertEquals(resGroup.getGroupMembers().size(), 3);
    int membersChecked = 0;
    for (GroupMember groupMember : resGroup.getGroupMembers()) {
        switch(groupMember.getMemberName()) {
            case "user.john":
            case "user.jane":
                assertNull(groupMember.getExpiration());
                assertTrue(groupMember.getApproved());
                membersChecked += 1;
                break;
            case "user.tim":
                assertEquals(groupMember.getExpiration(), timExpiry);
                membersChecked += 1;
                break;
        }
    }
    assertEquals(membersChecked, 3);
    zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain");
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Timestamp(com.yahoo.rdl.Timestamp) MemberDueDays(com.yahoo.athenz.zms.config.MemberDueDays) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Test(org.testng.annotations.Test)

Example 77 with ObjectStore

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

the class DBServiceTest method testPutDomainDependencyRetryFailure.

@Test
public void testPutDomainDependencyRetryFailure() {
    String domainName = "putDomainDependencyRetryFail1";
    String serviceName = "service1";
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.insertDomainDependency(eq(domainName), eq(serviceName))).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.putDomainDependency(mockDomRsrcCtx, domainName, serviceName, auditRef, "putDomainDependency");
        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 78 with ObjectStore

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

the class DBServiceTest method testExecutePutServiceIdentityFailure.

@Test
public void testExecutePutServiceIdentityFailure() {
    String domainName = "serviceadddom1";
    String serviceName = "service1";
    ServiceIdentity service = createServiceObject(domainName, serviceName, "http://localhost", "/usr/bin/java", "root", "users", "host1");
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.insertServiceIdentity(anyString(), any(ServiceIdentity.class))).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.executePutServiceIdentity(mockDomRsrcCtx, domainName, serviceName, service, auditRef, "putServiceIdentity");
        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 79 with ObjectStore

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

the class DBServiceTest method testExecuteDeleteEntityFailureRetry.

@Test
public void testExecuteDeleteEntityFailureRetry() {
    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)).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.executeDeleteEntity(mockDomRsrcCtx, domainName, entityName, auditRef, "deleteEntity");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.CONFLICT, ex.getCode());
    }
    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 80 with ObjectStore

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

the class DBServiceTest method testGetRoleReviewMembersFailure.

@Test
public void testGetRoleReviewMembersFailure() {
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
    Mockito.when(mockConn.updateRoleMemberReviewNotificationTimestamp(anyString(), anyLong(), anyInt())).thenReturn(false);
    assertNull(zms.dbService.getRoleReviewMembers(1));
    zms.dbService.store = saveStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) 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