Search in sources :

Example 31 with ObjectStoreConnection

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

the class DBServiceTest method testGetRoleExpiryMembersFailure.

@Test
public void testGetRoleExpiryMembersFailure() {
    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.updateRoleMemberExpirationNotificationTimestamp(anyString(), anyLong(), anyInt(), anyBoolean())).thenReturn(false);
    assertNull(zms.dbService.getRoleExpiryMembers(1, false));
    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)

Example 32 with ObjectStoreConnection

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

the class DBServiceTest method testRemovePrincipalFromDomainRolesExceptions.

@Test
public void testRemovePrincipalFromDomainRolesExceptions() {
    ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(conn.getPrincipalRoles("user.joe", "dom1")).thenThrow(new ResourceException(404)).thenThrow(new ResourceException(501));
    try {
        zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(404, ex.getCode());
    }
    try {
        zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(501, ex.getCode());
    }
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 33 with ObjectStoreConnection

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

the class DBServiceTest method testRemovePrincipalFromDomainRolesDeleteUserException.

@Test
public void testRemovePrincipalFromDomainRolesDeleteUserException() {
    DomainRoleMember roles = new DomainRoleMember();
    roles.setMemberRoles(new ArrayList<>());
    MemberRole role1 = new MemberRole();
    role1.setDomainName("dom1");
    role1.setRoleName("role1");
    roles.getMemberRoles().add(role1);
    MemberRole role2 = new MemberRole();
    role2.setDomainName("dom1");
    role2.setRoleName("role2");
    roles.getMemberRoles().add(role2);
    ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(conn.getPrincipalRoles("user.joe", "dom1")).thenReturn(roles);
    Mockito.when(conn.deleteRoleMember("dom1", "role1", "user.joe", adminUser, "unittest")).thenReturn(true);
    Mockito.when(conn.deleteRoleMember("dom1", "role2", "user.joe", adminUser, "unittest")).thenThrow(new ResourceException(501));
    // we should handle the exception without any errors
    zms.dbService.removePrincipalFromDomainRoles(null, conn, "dom1", "user.joe", adminUser, "unittest");
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 34 with ObjectStoreConnection

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

the class DBServiceTest method testValidateGroupUserAuthorityAttrRequirements.

@Test
public void testValidateGroupUserAuthorityAttrRequirements() {
    Group originalGroup = new Group().setName("group1").setUserAuthorityFilter("OnShore-US");
    Group updatedGroup = new Group().setName("group1");
    ObjectStoreConnection conn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(conn.getPrincipalRoles("group1", null)).thenThrow(new ResourceException(ResourceException.BAD_REQUEST));
    try {
        zms.dbService.validateGroupUserAuthorityAttrRequirements(conn, originalGroup, updatedGroup, "unittest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.BAD_REQUEST);
    }
    // now we're going to mock the use case where the role no longer exists
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setDomainName("coretech").setRoleName("role1"));
    DomainRoleMember domainRoleMember = new DomainRoleMember();
    domainRoleMember.setMemberRoles(memberRoles);
    ObjectStoreConnection conn2 = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(conn2.getPrincipalRoles("group1", null)).thenReturn(domainRoleMember);
    Mockito.when(conn2.getRole("coretech", "role1")).thenReturn(null);
    // the call will complete without any exceptions and no changes
    zms.dbService.validateGroupUserAuthorityAttrRequirements(conn2, originalGroup, updatedGroup, "unittest");
}
Also used : ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 35 with ObjectStoreConnection

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

the class DBServiceTest method testUpdateDomainMembersUserAuthorityFilterFailure.

@Test
public void testUpdateDomainMembersUserAuthorityFilterFailure() {
    final String domainName = "domain-meta-user-authority-filter";
    Domain domain = new Domain().setName(domainName).setUserAuthorityFilter("contractor").setModified(Timestamp.fromCurrentTime());
    Domain updateDomain = new Domain().setName(domainName).setUserAuthorityFilter("employee");
    ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
    // we're going to make sure to throw an exception here
    // since this should never be called
    Mockito.when(mockConn.getAthenzDomain(domainName)).thenThrow(new ResourceException(400));
    Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
    Authority authority = Mockito.mock(Authority.class);
    zms.dbService.zmsConfig.setUserAuthority(authority);
    zms.dbService.updateDomainMembersUserAuthorityFilter(mockDomRsrcCtx, mockConn, domain, updateDomain, auditRef, "testUpdateDomainMembersUserAuthorityFilterFailure");
    zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
}
Also used : Authority(com.yahoo.athenz.auth.Authority) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Test(org.testng.annotations.Test)

Aggregations

ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)173 Test (org.testng.annotations.Test)96 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)38 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)34 Authority (com.yahoo.athenz.auth.Authority)23 Timestamp (com.yahoo.rdl.Timestamp)17 ArrayList (java.util.ArrayList)16 MemberDueDays (com.yahoo.athenz.zms.config.MemberDueDays)11 Principal (com.yahoo.athenz.auth.Principal)7 SimplePrincipal (com.yahoo.athenz.auth.impl.SimplePrincipal)7 EmbeddedMysql (com.wix.mysql.EmbeddedMysql)5 FilePrivateKeyStore (com.yahoo.athenz.auth.impl.FilePrivateKeyStore)5 Crypto (com.yahoo.athenz.auth.util.Crypto)5 AuditReferenceValidator (com.yahoo.athenz.common.server.audit.AuditReferenceValidator)5 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)5 ResourceUtils (com.yahoo.athenz.common.server.util.ResourceUtils)5 DataCache (com.yahoo.athenz.zms.DBService.DataCache)5 MockAuditReferenceValidatorImpl (com.yahoo.athenz.zms.audit.MockAuditReferenceValidatorImpl)5 JDBCConnection (com.yahoo.athenz.zms.store.impl.jdbc.JDBCConnection)5 ZMSUtils (com.yahoo.athenz.zms.utils.ZMSUtils)5