Search in sources :

Example 1 with NotificationEmail

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

the class CertFailedRefreshNotificationTaskTest method testGetEmailBodyMultipleRecords.

@Test
public void testGetEmailBodyMultipleRecords() {
    System.setProperty("athenz.notification_workflow_url", "https://athenz.example.com/workflow");
    System.setProperty("athenz.notification_support_text", "#Athenz slack channel");
    System.setProperty("athenz.notification_support_url", "https://link.to.athenz.channel.com");
    System.setProperty("athenz.notification_athenz_ui_url", "https://ui-athenz.example.com/");
    Map<String, String> details = new HashMap<>();
    details.put("domain", "dom1");
    details.put(NOTIFICATION_DETAILS_UNREFRESHED_CERTS, "service0;provider;instanceID0;Sun Mar 15 15:08:07 IST 2020;;hostName0|" + // bad entry with missing provider
    "bad;instanceID0;Sun Mar 15 15:08:07 IST 2020;;hostBad|" + "service0;provider;instanceID0;Sun Mar 15 15:08:07 IST 2020;;secondHostName0");
    Notification notification = new Notification();
    notification.setDetails(details);
    CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter converter = new CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter(serverName, httpsPort, new NotificationToEmailConverterCommon(null));
    NotificationEmail notificationAsEmail = converter.getNotificationAsEmail(notification);
    String body = notificationAsEmail.getBody();
    assertNotNull(body);
    assertTrue(body.contains(htmlSeveralRecords));
    // make sure the bad entries are not included
    assertFalse(body.contains("bad"));
    assertFalse(body.contains("hostBad"));
    System.clearProperty("athenz.notification_workflow_url");
    System.clearProperty("notification_support_text");
    System.clearProperty("notification_support_url");
    System.clearProperty("athenz.notification_athenz_ui_url");
}
Also used : NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Example 2 with NotificationEmail

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

the class AWSZTSHealthNotificationTaskTest method testGetEmailBody.

@Test
public void testGetEmailBody() {
    System.setProperty("athenz.notification_workflow_url", "https://athenz.example.com/workflow");
    System.setProperty("athenz.notification_support_text", "#Athenz slack channel");
    System.setProperty("athenz.notification_support_url", "https://link.to.athenz.channel.com");
    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;Sun Mar 15 15:08:07 IST 2020;Error message");
    Notification notification = new Notification();
    notification.setDetails(details);
    AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToEmailConverter converter = new AWSZTSHealthNotificationTask.AWSZTSHealthNotificationToEmailConverter(new NotificationToEmailConverterCommon(null));
    NotificationEmail notificationAsEmail = converter.getNotificationAsEmail(notification);
    String body = notificationAsEmail.getBody();
    assertNotNull(body);
    assertTrue(body.contains("zts.url"));
    assertTrue(body.contains("domain0"));
    assertTrue(body.contains("role0"));
    assertTrue(body.contains("Sun Mar 15 15:08:07 IST 2020"));
    assertTrue(body.contains("Error message"));
    // Make sure support text and url do appear
    assertTrue(body.contains("slack"));
    assertTrue(body.contains("link.to.athenz.channel.com"));
    System.clearProperty("athenz.notification_workflow_url");
    System.clearProperty("notification_support_text");
    System.clearProperty("notification_support_url");
}
Also used : NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Notification(com.yahoo.athenz.common.server.notification.Notification) ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) Test(org.testng.annotations.Test)

Example 3 with NotificationEmail

use of com.yahoo.athenz.common.server.notification.NotificationEmail 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 4 with NotificationEmail

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

the class CertFailedRefreshNotificationTaskTest method testGetEmailBodySingleRecord.

@Test
public void testGetEmailBodySingleRecord() {
    System.setProperty("athenz.notification_workflow_url", "https://athenz.example.com/workflow");
    System.setProperty("athenz.notification_support_text", "#Athenz slack channel");
    System.setProperty("athenz.notification_support_url", "https://link.to.athenz.channel.com");
    System.setProperty("athenz.notification_athenz_ui_url", "https://ui-athenz.example.com/");
    Map<String, String> details = new HashMap<>();
    details.put("domain", "dom1");
    details.put(NOTIFICATION_DETAILS_UNREFRESHED_CERTS, "service1;provider1;instanceid1;Sun Mar 15 15:08:07 IST 2020;;hostName1");
    Notification notification = new Notification();
    notification.setDetails(details);
    CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter converter = new CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter(serverName, httpsPort, new NotificationToEmailConverterCommon(null));
    NotificationEmail notificationAsEmail = converter.getNotificationAsEmail(notification);
    String body = notificationAsEmail.getBody();
    assertNotNull(body);
    assertTrue(body.contains(htmlSingleRecord));
    System.clearProperty("athenz.notification_workflow_url");
    System.clearProperty("notification_support_text");
    System.clearProperty("notification_support_url");
    System.clearProperty("athenz.notification_athenz_ui_url");
}
Also used : NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Example 5 with NotificationEmail

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

the class CertFailedRefreshNotificationTaskTest method getEmailSubject.

@Test
public void getEmailSubject() {
    Notification notification = new Notification();
    CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter converter = new CertFailedRefreshNotificationTask.CertFailedRefreshNotificationToEmailConverter(serverName, httpsPort, notificationToEmailConverterCommon);
    NotificationEmail notificationAsEmail = converter.getNotificationAsEmail(notification);
    String subject = notificationAsEmail.getSubject();
    Assert.assertEquals(subject, "Athenz Unrefreshed Certificates Notification");
}
Also used : NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Aggregations

NotificationEmail (com.yahoo.athenz.common.server.notification.NotificationEmail)6 Notification (com.yahoo.athenz.common.server.notification.Notification)5 Test (org.testng.annotations.Test)5 NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)3 ZTSClientNotification (com.yahoo.athenz.zts.ZTSClientNotification)2