use of com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon in project athenz by yahoo.
the class CertFailedRefreshNotificationTaskTest method setup.
@BeforeClass
public void setup() {
instanceCertManager = Mockito.mock(InstanceCertManager.class);
dataStore = Mockito.mock(DataStore.class);
hostnameResolver = Mockito.mock(HostnameResolver.class);
notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
}
use of com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon 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");
}
use of com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon 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");
}
use of com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon in project athenz by yahoo.
the class ZTSClientNotificationSenderImpl method init.
public boolean init(NotificationManager notificationManager, RolesProvider rolesProvider, String serverName) {
this.isInit = false;
this.notificationManager = notificationManager;
this.rolesProvider = rolesProvider;
this.serverName = serverName;
if (notificationManager != null) {
this.notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(notificationManager.getNotificationUserAuthority());
}
if (this.notificationManager != null && this.rolesProvider != null && !StringUtil.isEmpty(this.serverName) && this.notificationToEmailConverterCommon != null) {
this.isInit = true;
} else {
LOGGER.warn("ZTSClientNotificationSenderImpl must be initiated with all arguments before it can be used");
}
return this.isInit;
}
use of com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon 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);
}
Aggregations