Search in sources :

Example 11 with MemberDueDays

use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.

the class DBServiceTest method testExecutePutRoleReview.

@Test
public void testExecutePutRoleReview() {
    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);
    MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), new Role().setMemberExpiryDays(10), MemberDueDays.Type.EXPIRY);
    MemberDueDays reminderDueDays = new MemberDueDays(new Domain(), new Role(), MemberDueDays.Type.REMINDER);
    zms.dbService.executePutRoleReview(mockDomRsrcCtx, domainName, "role1", incomingRole, expiryDueDays, reminderDueDays, "review test", "putRoleReview");
    Role resRole = zms.dbService.getRole(domainName, "role1", false, false, false);
    assertEquals(resRole.getRoleMembers().size(), 2);
    int membersChecked = 0;
    for (RoleMember roleMember : resRole.getRoleMembers()) {
        switch(roleMember.getMemberName()) {
            case "user.jane":
                // user.jane is extended to new expiry
                assertEquals(roleMember.getExpiration(), thirtyDayExpiry);
                assertTrue(roleMember.getApproved());
                membersChecked += 1;
                break;
            case "user.tim":
                // user.tim was not part of incoming role, so he remains unchanged
                assertEquals(roleMember.getExpiration(), timExpiry);
                membersChecked += 1;
                break;
        }
    }
    assertEquals(membersChecked, 2);
    zms.dbService.executeDeleteDomain(mockDomRsrcCtx, domainName, auditRef, "deletedomain");
}
Also used : MemberDueDays(com.yahoo.athenz.zms.config.MemberDueDays) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Timestamp(com.yahoo.rdl.Timestamp) Test(org.testng.annotations.Test)

Example 12 with MemberDueDays

use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.

the class DBServiceTest method testExecutePutRoleReviewRetry.

@Test
public void testExecutePutRoleReviewRetry() {
    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);
    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 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.CONFLICT);
    }
    // getDomain gets called to check domain auditEnabled requirement. verification of 2 retries happened
    verify(mockConn, times(2)).getDomain("role-review");
    zms.dbService.store = saveStore;
    zms.dbService.defaultRetryCount = saveRetryCount;
    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)

Example 13 with MemberDueDays

use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.

the class ZMSImplTest method testUpdateRoleMemberReview.

@Test
public void testUpdateRoleMemberReview() {
    long ext100Millis = TimeUnit.MILLISECONDS.convert(100, TimeUnit.DAYS);
    long ext125Millis = TimeUnit.MILLISECONDS.convert(125, TimeUnit.DAYS);
    long ext150Millis = TimeUnit.MILLISECONDS.convert(150, TimeUnit.DAYS);
    long ext175Millis = TimeUnit.MILLISECONDS.convert(175, TimeUnit.DAYS);
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user.joe").setReviewReminder(null).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("user.jane").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("athenz.api").setReviewReminder(null).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz.backend").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz.api.group").setReviewReminder(null).setPrincipalType(Principal.Type.GROUP.getValue()));
    members.add(new RoleMember().setMemberName("athenz.backend.group").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.GROUP.getValue()));
    Role role = new Role().setMemberReviewDays(125).setServiceReviewDays(150).setGroupReviewDays(175);
    MemberDueDays memberDueDays = new MemberDueDays(null, role, MemberDueDays.Type.REMINDER);
    zmsTestInitializer.getZms().updateRoleMemberReviewReminder(memberDueDays, members);
    Timestamp stamp = members.get(0).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext125Millis));
    stamp = members.get(1).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
    stamp = members.get(2).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext150Millis));
    stamp = members.get(3).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
    stamp = members.get(4).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext175Millis));
    stamp = members.get(5).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
}
Also used : MemberDueDays(com.yahoo.athenz.zms.config.MemberDueDays) Timestamp(com.yahoo.rdl.Timestamp)

Example 14 with MemberDueDays

use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.

the class ZMSImplTest method testUpdateRoleMemberReviewNoService.

@Test
public void testUpdateRoleMemberReviewNoService() {
    long ext100Millis = TimeUnit.MILLISECONDS.convert(100, TimeUnit.DAYS);
    long ext125Millis = TimeUnit.MILLISECONDS.convert(125, TimeUnit.DAYS);
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user.joe").setReviewReminder(null).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("user.jane").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("athenz.api").setReviewReminder(null).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz.backend").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz.api.group").setReviewReminder(null).setPrincipalType(Principal.Type.GROUP.getValue()));
    members.add(new RoleMember().setMemberName("athenz.backend.group").setReviewReminder(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.GROUP.getValue()));
    Role role = new Role().setMemberReviewDays(125).setServiceReviewDays(0).setGroupReviewDays(175);
    MemberDueDays memberDueDays = new MemberDueDays(null, role, MemberDueDays.Type.REMINDER);
    zmsTestInitializer.getZms().updateRoleMemberReviewReminder(memberDueDays, members);
    Timestamp stamp = members.get(0).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext125Millis));
    stamp = members.get(1).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
    assertNull(members.get(2).getReviewReminder());
    stamp = members.get(3).getReviewReminder();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
}
Also used : MemberDueDays(com.yahoo.athenz.zms.config.MemberDueDays) Timestamp(com.yahoo.rdl.Timestamp)

Example 15 with MemberDueDays

use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.

the class ZMSImplTest method testUpdateRoleMemberExpiration.

@Test
public void testUpdateRoleMemberExpiration() {
    long ext100Millis = TimeUnit.MILLISECONDS.convert(100, TimeUnit.DAYS);
    long ext125Millis = TimeUnit.MILLISECONDS.convert(125, TimeUnit.DAYS);
    long ext150Millis = TimeUnit.MILLISECONDS.convert(150, TimeUnit.DAYS);
    List<RoleMember> members = new ArrayList<>();
    members.add(new RoleMember().setMemberName("user.joe").setExpiration(null).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("user.jane").setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.USER.getValue()));
    members.add(new RoleMember().setMemberName("athenz.api").setExpiration(null).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz.backend").setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.SERVICE.getValue()));
    members.add(new RoleMember().setMemberName("athenz:group.dev-team").setExpiration(null).setPrincipalType(Principal.Type.GROUP.getValue()));
    members.add(new RoleMember().setMemberName("athenz:group.ops-team").setExpiration(Timestamp.fromMillis(System.currentTimeMillis() + ext100Millis)).setPrincipalType(Principal.Type.GROUP.getValue()));
    // for user members we have 50/125 setup while for service members 75/150
    Role role = new Role().setMemberExpiryDays(125).setServiceExpiryDays(150).setGroupExpiryDays(125);
    Domain domain = new Domain().setMemberExpiryDays(50).setServiceExpiryDays(75).setGroupExpiryDays(100);
    MemberDueDays memberDueDays = new MemberDueDays(domain, role, MemberDueDays.Type.EXPIRY);
    zmsTestInitializer.getZms().updateRoleMemberExpiration(memberDueDays, members);
    Timestamp stamp = members.get(0).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext125Millis));
    stamp = members.get(1).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
    stamp = members.get(2).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext150Millis));
    stamp = members.get(3).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
    stamp = members.get(4).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext125Millis));
    stamp = members.get(5).getExpiration();
    assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
}
Also used : MemberDueDays(com.yahoo.athenz.zms.config.MemberDueDays) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Timestamp(com.yahoo.rdl.Timestamp)

Aggregations

MemberDueDays (com.yahoo.athenz.zms.config.MemberDueDays)15 Timestamp (com.yahoo.rdl.Timestamp)15 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)12 Test (org.testng.annotations.Test)9 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)6 ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)6