Search in sources :

Example 26 with Notification

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

use of com.yahoo.athenz.common.server.notification.Notification 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)

Example 28 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testValidHosts.

@Test
public void testValidHosts() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    // Create 6 mock records. Only even records host are valid
    boolean isValidHost = true;
    for (int i = 0; i < 6; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, dataStore);
        Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + i))).thenReturn(isValidHost);
        isValidHost = !isValidHost;
    }
    // Make a 7th record with no host (but make it valid). It shouldn't return
    X509CertRecord record = getMockX509CertRecord(currentDate, 7);
    record.setHostName(null);
    records.add(record);
    NotificationTestsCommon.mockDomainData(7, dataStore);
    Mockito.when(hostnameResolver.isValidHostname(eq(null))).thenReturn(true);
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), anyString())).thenReturn(records);
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(instanceCertManager, dataStore, hostnameResolver, userDomainPrefix, serverName, httpsPort, notificationToEmailConverterCommon);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(3, notifications.size());
    assertEquals("domain4", notifications.get(0).getDetails().get("domain"));
    assertEquals("domain2", notifications.get(1).getDetails().get("domain"));
    assertEquals("domain0", notifications.get(2).getDetails().get("domain"));
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST);
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Example 29 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testNoValidServices.

@Test
public void testNoValidServices() {
    String globStrings = "*";
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_IGNORED_SERVICES_LIST, globStrings);
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    for (int i = 0; i < 6; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, dataStore);
        Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + i))).thenReturn(true);
    }
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), anyString())).thenReturn(records);
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(instanceCertManager, dataStore, hostnameResolver, userDomainPrefix, serverName, httpsPort, notificationToEmailConverterCommon);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(new ArrayList<>(), notifications);
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST);
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_IGNORED_SERVICES_LIST);
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Example 30 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testNoProviders.

@Test
public void testNoProviders() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    // Create 6 records, each in it's own domain (domain0, domain1... domain5)
    for (int i = 0; i < 6; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, dataStore);
    }
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), anyString())).thenReturn(records);
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(instanceCertManager, dataStore, hostnameResolver, userDomainPrefix, serverName, httpsPort, notificationToEmailConverterCommon);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(0, notifications.size());
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) 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