Search in sources :

Example 21 with Notification

use of com.yahoo.athenz.common.server.notification.Notification in project athenz by yahoo.

the class ZMSNotificationsTest method testDisableAdminGroupExpiryNotification.

@Test
public void testDisableAdminGroupExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        List<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        // Now disable notification for admins
        Map<String, TagValueList> disableUserTags = new HashMap<>();
        disableUserTags.put("zms.DisableReminderNotifications", new TagValueList().setList(Arrays.asList("2")));
        group1.setTags(disableUserTags);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        assertEquals(notifications.size(), 6, "notificationRecipients: " + notificationsToRecipientString(notifications));
        for (Notification notification : notifications) {
            assertEquals(notification.getRecipients().size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
            String recipient = notification.getRecipients().stream().findFirst().get();
            assertTrue(emailNotificationMembers.contains(recipient));
            emailNotificationMembers.remove(recipient);
        }
        assertTrue(emailNotificationMembers.isEmpty());
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 22 with Notification

use of com.yahoo.athenz.common.server.notification.Notification in project athenz by yahoo.

the class ZMSNotificationsTest method testDisableUserGroupExpiryNotification.

@Test
public void testDisableUserGroupExpiryNotification() {
    TopLevelDomain dom1 = zmsTestInitializer.createTopLevelDomainObject("test-domain1", "Test Domain1", "testOrg", zmsTestInitializer.getAdminUser());
    zmsTestInitializer.getZms().postTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), zmsTestInitializer.getAuditRef(), dom1);
    try {
        long currentTimeMillis = System.currentTimeMillis();
        List<GroupMember> groupMembers = generateGroupMembers(currentTimeMillis);
        Group group1 = zmsTestInitializer.createGroupObject("test-domain1", "Group1", groupMembers);
        // Now disable notification for users
        Map<String, TagValueList> disableUserTags = new HashMap<>();
        disableUserTags.put("zms.DisableReminderNotifications", new TagValueList().setList(Arrays.asList("1")));
        group1.setTags(disableUserTags);
        zmsTestInitializer.getZms().putGroup(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", "Group1", zmsTestInitializer.getAuditRef(), group1);
        GroupMemberExpiryNotificationTask groupMemberExpiryNotificationTask = new GroupMemberExpiryNotificationTask(zmsTestInitializer.getZms().dbService, zmsTestInitializer.getZms().userDomainPrefix, zmsTestInitializer.getZms().notificationToEmailConverterCommon);
        List<Notification> notifications = groupMemberExpiryNotificationTask.getNotifications();
        // Email notifications should be sent every 7 days
        Set<String> emailNotificationMembers = new HashSet<>(Arrays.asList(new String[] { "user.expireddays0", "user.expireddays1", "user.expireddays7", "user.expireddays14", "user.expireddays21", "user.expireddays28" }));
        assertEquals(notifications.size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
        Notification notification = notifications.get(0);
        assertEquals(notification.getRecipients().size(), 1, "notificationRecipients: " + notificationsToRecipientString(notifications));
        String recipient = notification.getRecipients().stream().findFirst().get();
        assertEquals(recipient, "user.testadminuser");
        verifyAdminNotifications(emailNotificationMembers, notification);
    } finally {
        zmsTestInitializer.getZms().deleteTopLevelDomain(zmsTestInitializer.getMockDomRsrcCtx(), "test-domain1", zmsTestInitializer.getAuditRef());
    }
}
Also used : GroupMemberExpiryNotificationTask(com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 23 with Notification

use of com.yahoo.athenz.common.server.notification.Notification in project athenz by yahoo.

the class ZMSImpl method sendMembershipApprovalNotification.

void sendMembershipApprovalNotification(final String domain, final String org, final String roleName, final String member, final String auditRef, final String principal, final Role role) {
    Map<String, String> details = new HashMap<>();
    details.put(NOTIFICATION_DETAILS_DOMAIN, domain);
    details.put(NOTIFICATION_DETAILS_ROLE, roleName);
    details.put(NOTIFICATION_DETAILS_MEMBER, member);
    details.put(NOTIFICATION_DETAILS_REASON, auditRef);
    details.put(NOTIFICATION_DETAILS_REQUESTER, principal);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Sending Membership Approval notification after putMembership");
    }
    List<Notification> notifications = new PutRoleMembershipNotificationTask(domain, org, role, details, dbService, userDomainPrefix, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PutRoleMembershipNotificationTask(com.yahoo.athenz.zms.notification.PutRoleMembershipNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 24 with Notification

use of com.yahoo.athenz.common.server.notification.Notification in project athenz by yahoo.

the class AWSZTSHealthNotificationTaskTest method getEmailSubject.

@Test
public void getEmailSubject() {
    Notification notification = new Notification();
    AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToEmailConverter converter = new AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToEmailConverter(notificationToEmailConverterCommon);
    NotificationEmail notificationAsEmail = converter.getNotificationAsEmail(notification);
    String subject = notificationAsEmail.getSubject();
    Assert.assertEquals(subject, "AWS ZTS Failure Notification");
}
Also used : NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) Notification(com.yahoo.athenz.common.server.notification.Notification) ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) Test(org.testng.annotations.Test)

Example 25 with Notification

use of com.yahoo.athenz.common.server.notification.Notification in project athenz by yahoo.

the class AWSZTSHealthNotificationTaskTest method testGetNotificationAsMetric.

@Test
public void testGetNotificationAsMetric() {
    Timestamp currentTimeStamp = Timestamp.fromCurrentTime();
    Timestamp twentyFiveDaysFromNow = ZTSTestUtils.addDays(currentTimeStamp, 25);
    Map<String, String> details = new HashMap<>();
    details.put(NOTIFICATION_DETAILS_AFFECTED_ZTS, "affected zts");
    details.put(NOTIFICATION_DETAILS_AWS_ZTS_HEALTH, "zts.url;domain0;role0;" + twentyFiveDaysFromNow + ";Error message");
    Notification notification = new Notification();
    notification.setDetails(details);
    AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToMetricConverter converter = new AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToMetricConverter();
    NotificationMetric notificationAsMetrics = converter.getNotificationAsMetrics(notification, currentTimeStamp);
    String[] expectedRecord = new String[] { METRIC_NOTIFICATION_TYPE_KEY, "aws_zts_health", METRIC_NOTIFICATION_ZTS_KEY, "zts.url", METRIC_NOTIFICATION_DOMAIN_KEY, "domain0", METRIC_NOTIFICATION_ROLE_KEY, "role0", METRIC_NOTIFICATION_EXPIRY_DAYS_KEY, "25", METRIC_NOTIFICATION_ZTS_HEALTH_MSG_KEY, "Error message" };
    List<String[]> expectedAttributes = new ArrayList<>();
    expectedAttributes.add(expectedRecord);
    assertEquals(new NotificationMetric(expectedAttributes), notificationAsMetrics);
}
Also used : NotificationMetric(com.yahoo.athenz.common.server.notification.NotificationMetric) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification) ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) Test(org.testng.annotations.Test)

Aggregations

Notification (com.yahoo.athenz.common.server.notification.Notification)30 Test (org.testng.annotations.Test)22 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)10 Timestamp (com.yahoo.rdl.Timestamp)9 NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)8 NotificationEmail (com.yahoo.athenz.common.server.notification.NotificationEmail)6 NotificationMetric (com.yahoo.athenz.common.server.notification.NotificationMetric)4 NotificationServiceConstants (com.yahoo.athenz.common.server.notification.NotificationServiceConstants)4 GroupMemberExpiryNotificationTask (com.yahoo.athenz.zms.notification.GroupMemberExpiryNotificationTask)4 ZTSClientNotification (com.yahoo.athenz.zts.ZTSClientNotification)4 java.util (java.util)4 Mockito (org.mockito.Mockito)4 AssertJUnit.assertEquals (org.testng.AssertJUnit.assertEquals)4 USER_DOMAIN_PREFIX (com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX)3 com.yahoo.athenz.zms (com.yahoo.athenz.zms)3 DomainData (com.yahoo.athenz.zms.DomainData)3 TagValueList (com.yahoo.athenz.zms.TagValueList)3 DataStore (com.yahoo.athenz.zts.store.DataStore)3 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)3