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");
}
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");
}
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);
}
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);
}
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());
}
Aggregations