Search in sources :

Example 6 with NotificationToEmailConverterCommon

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);
}
Also used : InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) DataStore(com.yahoo.athenz.zts.store.DataStore) BeforeClass(org.testng.annotations.BeforeClass)

Example 7 with NotificationToEmailConverterCommon

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");
}
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 8 with NotificationToEmailConverterCommon

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");
}
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 9 with NotificationToEmailConverterCommon

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;
}
Also used : NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)

Example 10 with NotificationToEmailConverterCommon

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);
}
Also used : Notification(com.yahoo.athenz.common.server.notification.Notification) Mockito(org.mockito.Mockito) java.util(java.util) Timestamp(com.yahoo.rdl.Timestamp) NotificationServiceConstants(com.yahoo.athenz.common.server.notification.NotificationServiceConstants) com.yahoo.athenz.zms(com.yahoo.athenz.zms) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Test(org.testng.annotations.Test) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) USER_DOMAIN_PREFIX(com.yahoo.athenz.common.ServerCommonConsts.USER_DOMAIN_PREFIX) Timestamp(com.yahoo.rdl.Timestamp) Notification(com.yahoo.athenz.common.server.notification.Notification) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) Test(org.testng.annotations.Test)

Aggregations

NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)13 Notification (com.yahoo.athenz.common.server.notification.Notification)8 Test (org.testng.annotations.Test)8 NotificationEmail (com.yahoo.athenz.common.server.notification.NotificationEmail)4 NotificationServiceConstants (com.yahoo.athenz.common.server.notification.NotificationServiceConstants)4 Timestamp (com.yahoo.rdl.Timestamp)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 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)3 AssertJUnit.assertTrue (org.testng.AssertJUnit.assertTrue)3 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)2 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)2 DataStore (com.yahoo.athenz.zts.store.DataStore)2 BeforeClass (org.testng.annotations.BeforeClass)2 Authority (com.yahoo.athenz.auth.Authority)1 Principal (com.yahoo.athenz.auth.Principal)1