Search in sources :

Example 1 with USER_DOMAIN_PREFIX

use of com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX in project athenz by yahoo.

the class RoleMemberNotificationCommonTest method testReviewGetNotificationDetailsFilterTag.

@Test
public void testReviewGetNotificationDetailsFilterTag() {
    DBService dbsvc = Mockito.mock(DBService.class);
    Role adminRole = new Role().setName("athenz1:role.admin").setRoleMembers(Arrays.asList(new RoleMember().setMemberName("user.testadmin")));
    Mockito.when(dbsvc.getRolesByDomain(eq("athenz1"))).thenReturn(Arrays.asList(adminRole));
    RoleMemberNotificationCommon roleMemberNotificationCommon = new RoleMemberNotificationCommon(dbsvc, USER_DOMAIN_PREFIX);
    NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
    DomainRoleMember roleMember = new DomainRoleMember();
    roleMember.setMemberName("user.joe");
    Map<String, DomainRoleMember> members = new HashMap<>();
    members.put("user.joe", roleMember);
    final Timestamp expirationTs = Timestamp.fromMillis(100);
    final Timestamp reviewTs = Timestamp.fromMillis(50);
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz1").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    roleMember.setMemberRoles(memberRoles);
    // Verify disable notification for users
    List<Notification> notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(1));
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBERS_LIST), "user.joe;role1;" + reviewTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_DOMAIN), "athenz1");
    // Verify disable notification for admins
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(2));
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST), "athenz1;role1;" + reviewTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    // Verify disable all notifications
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(3));
    assertEquals(0, notification.size());
}
Also used : Notification(com.yahoo.athenz.common.server.notification.Notification) Mockito(org.mockito.Mockito) java.util(java.util) Timestamp(com.yahoo.rdl.Timestamp) NotificationServiceConstants(com.yahoo.athenz.common.server.notification.NotificationServiceConstants) com.yahoo.athenz.zms(com.yahoo.athenz.zms) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Test(org.testng.annotations.Test) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) USER_DOMAIN_PREFIX(com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Test(org.testng.annotations.Test)

Example 2 with USER_DOMAIN_PREFIX

use of com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX in project athenz by yahoo.

the class RoleMemberNotificationCommonTest method testReviewPrincipalGetNotificationDetails.

@Test
public void testReviewPrincipalGetNotificationDetails() {
    DBService dbsvc = Mockito.mock(DBService.class);
    Role adminRole = new Role().setName("athenz1:role.admin").setRoleMembers(Arrays.asList(new RoleMember().setMemberName("user.testadmin")));
    Mockito.when(dbsvc.getRolesByDomain(eq("athenz1"))).thenReturn(Arrays.asList(adminRole));
    RoleMemberNotificationCommon roleMemberNotificationCommon = new RoleMemberNotificationCommon(dbsvc, USER_DOMAIN_PREFIX);
    NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
    // Verify no notification for member without member roles
    DomainRoleMember roleMember = new DomainRoleMember();
    roleMember.setMemberName("user.joe");
    Map<String, DomainRoleMember> members = new HashMap<>();
    members.put("user.joe", roleMember);
    List<Notification> notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(0, notification.size());
    // Verify the same result when setting the memberRoles to an empty collection
    roleMember.setMemberRoles(Collections.emptyList());
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(0, notification.size());
    final Timestamp expirationTs = Timestamp.fromMillis(100);
    final Timestamp reviewTs = Timestamp.fromMillis(50);
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz1").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    roleMember.setMemberRoles(memberRoles);
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(2, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(2, notification.get(1).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST), "athenz1;role1;" + reviewTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    assertEquals(notification.get(1).getDetails().get(NOTIFICATION_DETAILS_MEMBERS_LIST), "user.joe;role1;" + reviewTs);
    assertEquals(notification.get(1).getDetails().get(NOTIFICATION_DETAILS_DOMAIN), "athenz1");
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz2").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    memberRoles.add(new MemberRole().setRoleName("role2").setDomainName("athenz2").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberReviewNotificationTask.ReviewRoleMemberDetailStringer(), new RoleMemberReviewNotificationTask.RoleReviewPrincipalNotificationToMetricConverter(), new RoleMemberReviewNotificationTask.RoleReviewDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(2, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    String expectedRolesList = "athenz1;role1;" + reviewTs + "|athenz2;role1;" + reviewTs + "|athenz2;role2;" + reviewTs;
    assertEquals(expectedRolesList, notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST));
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    assertEquals(expectedRolesList, notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST));
    assertEquals(notification.get(1).getDetails().get(NOTIFICATION_DETAILS_MEMBERS_LIST), "user.joe;role1;" + reviewTs);
    assertEquals(notification.get(1).getDetails().get(NOTIFICATION_DETAILS_DOMAIN), "athenz1");
}
Also used : Notification(com.yahoo.athenz.common.server.notification.Notification) Mockito(org.mockito.Mockito) java.util(java.util) Timestamp(com.yahoo.rdl.Timestamp) NotificationServiceConstants(com.yahoo.athenz.common.server.notification.NotificationServiceConstants) com.yahoo.athenz.zms(com.yahoo.athenz.zms) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Test(org.testng.annotations.Test) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) USER_DOMAIN_PREFIX(com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Test(org.testng.annotations.Test)

Example 3 with USER_DOMAIN_PREFIX

use of com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX in project athenz by yahoo.

the class RoleMemberNotificationCommonTest method testExpiryPrincipalGetNotificationDetails.

@Test
public void testExpiryPrincipalGetNotificationDetails() {
    DBService dbsvc = Mockito.mock(DBService.class);
    RoleMemberNotificationCommon roleMemberNotificationCommon = new RoleMemberNotificationCommon(dbsvc, USER_DOMAIN_PREFIX);
    NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
    // Verify no notification for member without member roles
    DomainRoleMember roleMember = new DomainRoleMember();
    roleMember.setMemberName("user.joe");
    Map<String, DomainRoleMember> members = new HashMap<>();
    members.put("user.joe", roleMember);
    List<Notification> notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(), new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToMetricConverter(), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(0, notification.size());
    // Verify the same result when setting the memberRoles to an empty collection
    roleMember.setMemberRoles(Collections.emptyList());
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(), new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToMetricConverter(), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(0, notification.size());
    final Timestamp expirationTs = Timestamp.fromMillis(100);
    final Timestamp reviewTs = Timestamp.fromMillis(50);
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz1").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    roleMember.setMemberRoles(memberRoles);
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(), new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToMetricConverter(), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST), "athenz1;role1;" + expirationTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz2").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    memberRoles.add(new MemberRole().setRoleName("role2").setDomainName("athenz2").setMemberName("user.joe").setExpiration(expirationTs).setReviewReminder(reviewTs));
    notification = roleMemberNotificationCommon.getNotificationDetails(members, new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(notificationToEmailConverterCommon), new RoleMemberExpiryNotificationTask.ExpiryRoleMemberDetailStringer(), new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToMetricConverter(), new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToMetricConverter(), memberRole -> DisableNotificationEnum.getEnumSet(0));
    assertEquals(1, notification.size());
    assertEquals(2, notification.get(0).getDetails().size());
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST), "athenz1;role1;" + expirationTs + "|athenz2;role1;" + expirationTs + "|athenz2;role2;" + expirationTs);
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_MEMBER), "user.joe");
    assertEquals(notification.get(0).getDetails().get(NOTIFICATION_DETAILS_ROLES_LIST), "athenz1;role1;" + expirationTs + "|athenz2;role1;" + expirationTs + "|athenz2;role2;" + expirationTs);
}
Also used : Notification(com.yahoo.athenz.common.server.notification.Notification) Mockito(org.mockito.Mockito) java.util(java.util) Timestamp(com.yahoo.rdl.Timestamp) NotificationServiceConstants(com.yahoo.athenz.common.server.notification.NotificationServiceConstants) com.yahoo.athenz.zms(com.yahoo.athenz.zms) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Test(org.testng.annotations.Test) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) USER_DOMAIN_PREFIX(com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Test(org.testng.annotations.Test)

Aggregations

USER_DOMAIN_PREFIX (com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX)3 Notification (com.yahoo.athenz.common.server.notification.Notification)3 NotificationServiceConstants (com.yahoo.athenz.common.server.notification.NotificationServiceConstants)3 NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)3 com.yahoo.athenz.zms (com.yahoo.athenz.zms)3 Timestamp (com.yahoo.rdl.Timestamp)3 java.util (java.util)3 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 Mockito (org.mockito.Mockito)3 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)3 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)3 Test (org.testng.annotations.Test)3