Search in sources :

Example 86 with ObjectStore

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

the class DBServiceTest method testExecutePutServiceIdentitySystemMetaFailureInvalidDomain.

@Test
public void testExecutePutServiceIdentitySystemMetaFailureInvalidDomain() {
    String domainName = "serviceadddom1";
    String serviceName = "service1";
    Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(null);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    ServiceIdentitySystemMeta meta = new ServiceIdentitySystemMeta();
    meta.setProviderEndpoint("https://localhost");
    try {
        zms.dbService.executePutServiceIdentitySystemMeta(mockDomRsrcCtx, domainName, serviceName, meta, "providerendpoint", auditRef, "putServiceIdentitySystemMeta");
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.NOT_FOUND);
    }
    zms.dbService.store = saveStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) Test(org.testng.annotations.Test)

Example 87 with ObjectStore

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

the class DBServiceTest method testSetMembersInDomainEmptyMembers.

@Test
public void testSetMembersInDomainEmptyMembers() {
    String domainName = "no-role-members";
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.admin"));
    Role role = new Role().setMembers(null).setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(role);
    Domain domain = new Domain().setModified(Timestamp.fromCurrentTime());
    AthenzDomain athenzDomain = new AthenzDomain(domainName);
    athenzDomain.setDomain(domain);
    athenzDomain.setRoles(roles);
    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);
    assertNotNull(resAthenzDomain.getRoles());
    List<RoleMember> roleMembersResult = resAthenzDomain.getRoles().get(0).getRoleMembers();
    assertEquals(roleMembersResult.size(), 1);
    assertEquals(roleMembersResult.get(0).getMemberName(), "user.admin");
    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 88 with ObjectStore

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

the class DBServiceTest method testGetPendingDomainGroupMembersList.

@Test
public void testGetPendingDomainGroupMembersList() {
    String domainName = "domain1";
    String principal = "user.user1";
    Map<String, List<DomainGroupMember>> dummyResult = new LinkedHashMap<>();
    dummyResult.put(domainName, Collections.singletonList(new DomainGroupMember()));
    dummyResult.put("domain2", Collections.singletonList(new DomainGroupMember()));
    Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
    Mockito.when(mockJdbcConn.getPendingDomainGroupMembersByPrincipal(principal)).thenReturn(dummyResult);
    ObjectStore saveStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    DomainGroupMembership domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, domainName);
    assertNotNull(domainGroupMembership);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().get(0).domainName, domainName);
    domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, "domain2");
    assertNotNull(domainGroupMembership);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 1);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().get(0).domainName, "domain2");
    domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, "*");
    assertNotNull(domainGroupMembership);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 2);
    domainGroupMembership = zms.dbService.getPendingDomainGroupMembers(principal, null);
    assertNotNull(domainGroupMembership);
    assertEquals(domainGroupMembership.getDomainGroupMembersList().size(), 2);
    zms.dbService.store = saveStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) Test(org.testng.annotations.Test)

Example 89 with ObjectStore

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

the class DBServiceTest method testProcessRoleUserAuthorityRestrictions.

@Test
public void testProcessRoleUserAuthorityRestrictions() {
    Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
    Authority authority = Mockito.mock(Authority.class);
    Mockito.when(authority.getDateAttribute("user.joe", "elevated-clearance")).thenReturn(null);
    zms.dbService.zmsConfig.setUserAuthority(authority);
    final String domainName = "authority-test";
    final String roleName = "auth-role";
    ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
    Mockito.when(mockConn.insertRoleMember(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(true);
    Mockito.when(mockConn.updateDomainModTimestamp(domainName)).thenReturn(true);
    Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
    Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockConn);
    // first we're going to return a null role and then a role
    // with no members - in both cases we return without processing
    // any code
    Role role = new Role().setUserAuthorityExpiration("elevated-clearance");
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.joe"));
    Mockito.when(mockConn.getRole(domainName, roleName)).thenReturn(role);
    Mockito.when(mockConn.listRoleMembers(domainName, roleName, false)).thenReturn(roleMembers);
    // first we're going to return no roles and then list of roles
    // in the second one
    List<PrincipalRole> roles = new ArrayList<>();
    PrincipalRole prRole = new PrincipalRole();
    prRole.setDomainName(domainName);
    prRole.setRoleName(roleName);
    roles.add(prRole);
    Mockito.when(mockConn.listRolesWithUserAuthorityRestrictions()).thenReturn(null).thenReturn(roles);
    ObjectStore savedStore = zms.dbService.store;
    zms.dbService.store = mockObjStore;
    // the request should complete successfully
    // first time we'll get no roles so no work is done
    // second time we'll get a single role that we'll process
    zms.dbService.processRoleUserAuthorityRestrictions();
    zms.dbService.processRoleUserAuthorityRestrictions();
    zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
    zms.dbService.store = savedStore;
}
Also used : ObjectStore(com.yahoo.athenz.zms.store.ObjectStore) Authority(com.yahoo.athenz.auth.Authority) ObjectStoreConnection(com.yahoo.athenz.zms.store.ObjectStoreConnection) Test(org.testng.annotations.Test)

Example 90 with ObjectStore

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

the class DBServiceTest method testExecutePutMembershipFailure.

@Test
public void testExecutePutMembershipFailure() {
    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);
    Role role = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
    Mockito.when(mockJdbcConn.getRole(domainName, roleName)).thenReturn(role);
    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.BAD_REQUEST);
    }
    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