Search in sources :

Example 66 with ObjectStore

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

the class DBServiceTest method testExecutePutPublicKeyEntryFailure.

@Test
public void testExecutePutPublicKeyEntryFailure() {
    String domainName = "servicepubpubkeydom1";
    String serviceName = "service1";
    Domain domain = new Domain().setAuditEnabled(false);
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
    PublicKeyEntry keyEntry = new PublicKeyEntry().setId("0").setKey("key");
    Mockito.when(mockJdbcConn.getPublicKeyEntry(domainName, serviceName, "0", false)).thenReturn(keyEntry);
    Mockito.when(mockJdbcConn.updatePublicKeyEntry(domainName, serviceName, keyEntry)).thenReturn(false);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    try {
        zms.dbService.executePutPublicKeyEntry(mockDomRsrcCtx, domainName, serviceName, keyEntry, auditRef, "putPublicKeyEntry");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ResourceException.INTERNAL_SERVER_ERROR, 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 67 with ObjectStore

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

the class DBServiceTest method testExecutePutQuotaFailureRetry.

@Test
public void testExecutePutQuotaFailureRetry() {
    String domainName = "putquota";
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
    Quota quota = new Quota();
    Mockito.when(mockJdbcConn.insertQuota(domainName, quota)).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.executePutQuota(mockDomRsrcCtx, domainName, quota, auditRef, "putQuota");
        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) Test(org.testng.annotations.Test)

Example 68 with ObjectStore

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

the class DBServiceTest method testGetRolesByDomain.

@Test
public void testGetRolesByDomain() {
    ObjectStore saveStore = zms.dbService.store;
    AthenzDomain athenzDomain = new AthenzDomain("test1");
    Domain domain = new Domain().setName("test1").setMemberExpiryDays(100).setModified(Timestamp.fromCurrentTime());
    athenzDomain.setDomain(domain);
    Role testRole = new Role();
    testRole.setName("admin");
    List<Role> roles = new ArrayList<>();
    roles.add(testRole);
    athenzDomain.setRoles(roles);
    Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(eq("test1"))).thenReturn(domain);
    Mockito.when(mockJdbcConn.getAthenzDomain(eq("test1"))).thenReturn(athenzDomain);
    zms.dbService.store = mockObjStore;
    List<Role> rolesFetched = zms.dbService.getRolesByDomain("test1");
    assertEquals(1, rolesFetched.size());
    assertEquals("admin", rolesFetched.get(0).getName());
    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 69 with ObjectStore

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

the class DBServiceTest method testUpdatePrincipalByStateFromAuthorityExceptionUpdatePrincipal.

@Test
public void testUpdatePrincipalByStateFromAuthorityExceptionUpdatePrincipal() {
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockJdbcConn);
    ObjectStore savedStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    Mockito.when(mockJdbcConn.updatePrincipal("user.user1", 2)).thenThrow(new ResourceException(ResourceException.NOT_FOUND, "not found"));
    Mockito.when(mockJdbcConn.updatePrincipal("user.user2", 2)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
    List<Principal> changedPrincipals = new ArrayList<>();
    changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user1", "user", null));
    changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user2", "user", null));
    try {
        zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, true);
    } catch (ResourceException rex) {
        fail();
    }
    Mockito.verify(mockJdbcConn, atLeast(2)).updatePrincipal(anyString(), anyInt());
    zms.dbService.store = savedStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) SimplePrincipal(com.yahoo.athenz.auth.impl.SimplePrincipal) Principal(com.yahoo.athenz.auth.Principal) Test(org.testng.annotations.Test)

Example 70 with ObjectStore

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

the class DBServiceTest method testExecutePutRoleReviewDelError.

@Test
public void testExecutePutRoleReviewDelError() {
    final String domainName = "role-review";
    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);
    Role role1 = createRoleObject(domainName, "role1", null, "user.john", "user.jane");
    Timestamp timExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(10, TimeUnit.DAYS));
    role1.getRoleMembers().add(new RoleMember().setMemberName("user.tim").setExpiration(timExpiry).setApproved(true).setActive(true));
    zms.dbService.executePutRole(mockDomRsrcCtx, domainName, "role1", role1, "test", "putrole");
    Role incomingRole = new Role().setName("role1");
    List<RoleMember> incomingMembers = new ArrayList<>();
    incomingMembers.add(new RoleMember().setMemberName("user.john").setActive(false).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
    incomingMembers.add(new RoleMember().setMemberName("user.jane").setActive(true).setExpiration(thirtyDayExpiry).setPrincipalType(Principal.Type.USER.getValue()));
    incomingRole.setRoleMembers(incomingMembers);
    Domain resDom = zms.dbService.getDomain(domainName, true);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockConn);
    Mockito.when(mockConn.getDomain(domainName)).thenReturn(resDom);
    Mockito.when(mockConn.getRole(domainName, "role1")).thenReturn(role1);
    Mockito.when(mockConn.listRoleMembers(domainName, "role1", false)).thenReturn(role1.getRoleMembers());
    Mockito.when(mockConn.deleteRoleMember(domainName, "role1", "user.john", adminUser, auditRef)).thenThrow(new ResourceException(ResourceException.NOT_FOUND));
    MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), new Role().setMemberExpiryDays(10), MemberDueDays.Type.EXPIRY);
    MemberDueDays reminderDueDays = new MemberDueDays(new Domain(), new Role(), MemberDueDays.Type.REMINDER);
    try {
        zms.dbService.executePutRoleReview(mockDomRsrcCtx, domainName, "role1", incomingRole, expiryDueDays, reminderDueDays, "review test", "putRoleReview");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    zms.dbService.store = saveStore;
    Role resRole = zms.dbService.getRole(domainName, "role1", false, false, false);
    assertEquals(resRole.getRoleMembers().size(), 3);
    int membersChecked = 0;
    for (RoleMember roleMember : resRole.getRoleMembers()) {
        switch(roleMember.getMemberName()) {
            case "user.john":
            case "user.jane":
                assertNull(roleMember.getExpiration());
                assertTrue(roleMember.getApproved());
                membersChecked += 1;
                break;
            case "user.tim":
                assertEquals(roleMember.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)

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