use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.
the class ZMSImplTest method testUpdateRoleMemberExpirationNoService.
@Test
public void testUpdateRoleMemberExpirationNoService() {
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").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()));
// for user members we have 50/125 setup while for service members 0
Role role = new Role().setMemberExpiryDays(125).setServiceExpiryDays(0).setGroupExpiryDays(0);
Domain domain = new Domain().setMemberExpiryDays(50).setServiceExpiryDays(0).setGroupExpiryDays(0);
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));
assertNull(members.get(2).getExpiration());
stamp = members.get(3).getExpiration();
assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
}
use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.
the class ZMSImplTest method testUpdateRoleMemberExpirationNoUser.
@Test
public void testUpdateRoleMemberExpirationNoUser() {
long ext100Millis = TimeUnit.MILLISECONDS.convert(100, 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 0 setup while for service members 75/150
Role role = new Role().setMemberExpiryDays(0).setServiceExpiryDays(150).setGroupExpiryDays(0);
Domain domain = new Domain().setMemberExpiryDays(0).setServiceExpiryDays(75).setGroupExpiryDays(0);
MemberDueDays memberDueDays = new MemberDueDays(domain, role, MemberDueDays.Type.EXPIRY);
zmsTestInitializer.getZms().updateRoleMemberExpiration(memberDueDays, members);
assertNull(members.get(0).getExpiration());
Timestamp 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));
assertNull(members.get(4).getExpiration());
stamp = members.get(5).getExpiration();
assertTrue(ZMSTestUtils.validateDueDate(stamp.millis(), ext100Millis));
}
use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.
the class DBServiceTest method testApplyMembershipChanges.
@Test
public void testApplyMembershipChanges() {
List<RoleMember> incomingMembers = new ArrayList<>(3);
List<RoleMember> originalMembers = new ArrayList<>(5);
Timestamp thirtyDayExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(30, TimeUnit.DAYS) + TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES));
Timestamp currentExpiry = Timestamp.fromMillis(System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(4, TimeUnit.DAYS));
incomingMembers.add(createRoleMember("user.user1", true, thirtyDayExpiry, true).setPrincipalType(Principal.Type.USER.getValue()));
incomingMembers.add(createRoleMember("user.user2", true, thirtyDayExpiry, true).setPrincipalType(Principal.Type.USER.getValue()));
incomingMembers.add(createRoleMember("user.user4", false, thirtyDayExpiry, true).setPrincipalType(Principal.Type.USER.getValue()));
Role incomingRole = new Role().setName("role1").setRoleMembers(incomingMembers);
originalMembers.add(createRoleMember("user.user1", true, currentExpiry, true));
originalMembers.add(createRoleMember("user.user2", true, currentExpiry, true));
originalMembers.add(createRoleMember("user.user3", true, currentExpiry, true));
originalMembers.add(createRoleMember("user.user4", true, currentExpiry, true));
originalMembers.add(createRoleMember("user.user5", true, currentExpiry, true));
Role originalRole = new Role().setName("role1").setRoleMembers(originalMembers).setMemberExpiryDays(10).setServiceExpiryDays(10).setGroupExpiryDays(10);
Role updatedRole = new Role().setName("role1");
MemberDueDays expiryDueDays = new MemberDueDays(new Domain(), originalRole, MemberDueDays.Type.EXPIRY);
MemberDueDays reminderDueDays = new MemberDueDays(new Domain(), originalRole, MemberDueDays.Type.REMINDER);
zms.dbService.applyMembershipChanges(updatedRole, originalRole, incomingRole, expiryDueDays, reminderDueDays, auditRef);
assertEquals(updatedRole.getRoleMembers().size(), 3);
List<String> expectedMemberNames = Arrays.asList("user.user1", "user.user2", "user.user4");
for (RoleMember roleMember : updatedRole.getRoleMembers()) {
assertTrue(roleMember.getApproved());
assertEquals(roleMember.getExpiration(), thirtyDayExpiry);
assertTrue(expectedMemberNames.contains(roleMember.getMemberName()));
assertEquals(roleMember.getAuditRef(), auditRef);
if (roleMember.getMemberName().equals("user.user4")) {
assertFalse(roleMember.getActive());
} else {
assertTrue(roleMember.getActive());
}
}
originalRole.setAuditEnabled(true);
updatedRole.setRoleMembers(null);
List<RoleMember> noactionMembers = zms.dbService.applyMembershipChanges(updatedRole, originalRole, incomingRole, expiryDueDays, reminderDueDays, auditRef);
assertEquals(noactionMembers.size(), 2);
int noActChecked = 0;
for (RoleMember roleMember : noactionMembers) {
switch(roleMember.getMemberName()) {
case "user.user3":
case "user.user5":
noActChecked += 1;
break;
}
}
assertEquals(noActChecked, 2);
assertEquals(updatedRole.getRoleMembers().size(), 3);
for (RoleMember roleMember : updatedRole.getRoleMembers()) {
assertFalse(roleMember.getApproved());
assertEquals(roleMember.getExpiration(), thirtyDayExpiry);
assertTrue(expectedMemberNames.contains(roleMember.getMemberName()));
assertEquals(roleMember.getAuditRef(), auditRef);
if (roleMember.getMemberName().equals("user.user4")) {
assertFalse(roleMember.getActive());
} else {
assertTrue(roleMember.getActive());
}
}
}
use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.
the class DBServiceTest method testExecutePutRoleReviewExtendError.
@Test
public void testExecutePutRoleReviewExtendError() {
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(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
Mockito.when(mockConn.insertRoleMember(anyString(), anyString(), any(RoleMember.class), anyString(), anyString())).thenReturn(false);
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");
}
use of com.yahoo.athenz.zms.config.MemberDueDays in project athenz by yahoo.
the class DBServiceTest method testExecutePutGroupReviewExtendError.
@Test
public void testExecutePutGroupReviewExtendError() {
final String domainName = "group-review-extend-error";
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, "test");
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);
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.getGroup(domainName, "group1")).thenReturn(group1);
Mockito.when(mockConn.listGroupMembers(domainName, "group1", false)).thenReturn(group1.getGroupMembers());
Mockito.when(mockConn.deleteGroupMember(anyString(), anyString(), anyString(), anyString(), anyString())).thenReturn(true);
Mockito.when(mockConn.insertGroupMember(anyString(), anyString(), any(GroupMember.class), anyString(), anyString())).thenReturn(false);
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.NOT_FOUND);
}
zms.dbService.store = saveStore;
Group resGroup = zms.dbService.getGroup(domainName, "group1", false, false);
assertEquals(group1.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");
}
Aggregations