Search in sources :

Example 6 with Notification

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

the class ZMSImpl method sendGroupMembershipApprovalNotification.

void sendGroupMembershipApprovalNotification(final String domain, final String org, final String groupName, final String member, final String auditRef, final String principal, final Group group) {
    Map<String, String> details = new HashMap<>();
    details.put(NOTIFICATION_DETAILS_DOMAIN, domain);
    details.put(NOTIFICATION_DETAILS_GROUP, groupName);
    details.put(NOTIFICATION_DETAILS_MEMBER, member);
    details.put(NOTIFICATION_DETAILS_REASON, auditRef);
    details.put(NOTIFICATION_DETAILS_REQUESTER, principal);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Sending Group Membership Approval notification after putGroupMembership");
    }
    List<Notification> notifications = new PutGroupMembershipNotificationTask(domain, org, group, details, dbService, userDomainPrefix, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PutGroupMembershipNotificationTask(com.yahoo.athenz.zms.notification.PutGroupMembershipNotificationTask) Notification(com.yahoo.athenz.common.server.notification.Notification)

Example 7 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testSeveralProviders.

@Test
public void testSeveralProviders() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    Mockito.when(hostnameResolver.isValidHostname(anyString())).thenReturn(true);
    // Configure 3 providers in property
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider1, provider2, provider3");
    // Create 7 records, each in it's own domain (domain0, domain1... domain6)
    for (int i = 0; i < 7; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, dataStore);
    }
    // Set one record in provider1, two records in provider2 and three records in provider3
    records.get(0).setProvider("provider1");
    records.get(1).setProvider("provider2");
    records.get(2).setProvider("provider2");
    records.get(3).setProvider("provider3");
    records.get(4).setProvider("provider3");
    records.get(5).setProvider("provider3");
    // Set one record in a provider not configured in properties (shouldn't be retrieved)
    records.get(6).setProvider("providerNotInProperty");
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), eq("provider1"))).thenReturn(records.subList(0, 1));
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), eq("provider2"))).thenReturn(records.subList(1, 3));
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), eq("provider3"))).thenReturn(records.subList(3, 6));
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), eq("providerNotInProperty"))).thenReturn(records.subList(6, 7));
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(instanceCertManager, dataStore, hostnameResolver, userDomainPrefix, serverName, httpsPort, notificationToEmailConverterCommon);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(6, notifications.size());
    notifications.sort(Comparator.comparing(notif -> notif.getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS)));
    // Assert one records for provider1:
    String expectedDetail = "service0;provider1;instanceID0;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName0";
    assertEquals(expectedDetail, notifications.get(0).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    // Assert two records for provider2:
    expectedDetail = "service1;provider2;instanceID1;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName1";
    assertEquals(expectedDetail, notifications.get(1).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    expectedDetail = "service2;provider2;instanceID2;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName2";
    assertEquals(expectedDetail, notifications.get(2).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    // Assert three records for provider3:
    expectedDetail = "service3;provider3;instanceID3;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName3";
    assertEquals(expectedDetail, notifications.get(3).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    expectedDetail = "service4;provider3;instanceID4;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName4";
    assertEquals(expectedDetail, notifications.get(4).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    expectedDetail = "service5;provider3;instanceID5;" + Timestamp.fromMillis(currentDate.getTime()) + ";;hostName5";
    assertEquals(expectedDetail, notifications.get(5).getDetails().get(NOTIFICATION_DETAILS_UNREFRESHED_CERTS));
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST);
}
Also used : ZTSTestUtils(com.yahoo.athenz.zts.ZTSTestUtils) InstanceCertManager(com.yahoo.athenz.zts.cert.InstanceCertManager) java.util(java.util) NotificationEmail(com.yahoo.athenz.common.server.notification.NotificationEmail) ArgumentMatchers(org.mockito.ArgumentMatchers) NotificationMetric(com.yahoo.athenz.common.server.notification.NotificationMetric) TagValueList(com.yahoo.athenz.zms.TagValueList) BeforeClass(org.testng.annotations.BeforeClass) DomainData(com.yahoo.athenz.zms.DomainData) Test(org.testng.annotations.Test) HostnameResolver(com.yahoo.athenz.common.server.dns.HostnameResolver) NotificationToEmailConverterCommon(com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon) DataStore(com.yahoo.athenz.zts.store.DataStore) Notification(com.yahoo.athenz.common.server.notification.Notification) Mockito(org.mockito.Mockito) Timestamp(com.yahoo.rdl.Timestamp) Assert(org.testng.Assert) NotificationServiceConstants(com.yahoo.athenz.common.server.notification.NotificationServiceConstants) ZTS_PROP_NOTIFICATION_CERT_FAIL_IGNORED_SERVICES_LIST(com.yahoo.athenz.zts.ZTSConsts.ZTS_PROP_NOTIFICATION_CERT_FAIL_IGNORED_SERVICES_LIST) ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST(com.yahoo.athenz.zts.ZTSConsts.ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) AssertJUnit.assertEquals(org.testng.AssertJUnit.assertEquals) MetricNotificationService(com.yahoo.athenz.common.server.notification.impl.MetricNotificationService) Assert.assertFalse(org.testng.Assert.assertFalse) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Example 8 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testValidServices.

@Test
public void testValidServices() {
    String globStrings = "domain0.service0, " + "???????.service1, " + "domain4.????????, ";
    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(3, notifications.size());
    assertEquals("domain5", notifications.get(0).getDetails().get("domain"));
    assertEquals("domain2", notifications.get(1).getDetails().get("domain"));
    assertEquals("domain3", notifications.get(2).getDetails().get("domain"));
    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 9 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testSomeRecordsSnoozed.

@Test
public void testSomeRecordsSnoozed() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    DataStore snoozedDataStore = Mockito.mock(DataStore.class);
    for (int i = 0; i < 8; ++i) {
        X509CertRecord record = getMockX509CertRecord(currentDate, i);
        records.add(record);
        NotificationTestsCommon.mockDomainData(i, snoozedDataStore);
        DomainData domainData = new DomainData();
        // Make even domains snooze
        if (i % 2 == 0) {
            Map<String, TagValueList> tags = new HashMap<>();
            tags.put("zts.DisableCertRefreshNotifications", new TagValueList().setList(Arrays.asList("true")));
            domainData.setTags(tags);
        }
        Mockito.when(snoozedDataStore.getDomainData("domain" + i)).thenReturn(domainData);
        Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + i))).thenReturn(true);
    }
    // Have zts.DisableCertRefreshNotifications tag for domain 8 but with value other then "true"
    X509CertRecord record = getMockX509CertRecord(currentDate, 8);
    records.add(record);
    NotificationTestsCommon.mockDomainData(8, snoozedDataStore);
    DomainData domainData = new DomainData();
    Map<String, TagValueList> tags = new HashMap<>();
    tags.put("zts.DisableCertRefreshNotifications", new TagValueList().setList(Arrays.asList("false", "False", "Not True")));
    domainData.setTags(tags);
    Mockito.when(snoozedDataStore.getDomainData("domain" + 8)).thenReturn(domainData);
    Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + 8))).thenReturn(true);
    // Have zts.DisableCertRefreshNotifications tag for domain 9 with several values (one of them is true case insensitive)
    record = getMockX509CertRecord(currentDate, 9);
    records.add(record);
    NotificationTestsCommon.mockDomainData(9, snoozedDataStore);
    domainData = new DomainData();
    tags = new HashMap<>();
    tags.put("zts.DisableCertRefreshNotifications", new TagValueList().setList(Arrays.asList("false", "test", "tRue")));
    domainData.setTags(tags);
    Mockito.when(snoozedDataStore.getDomainData("domain" + 9)).thenReturn(domainData);
    Mockito.when(hostnameResolver.isValidHostname(eq("hostName" + 9))).thenReturn(true);
    Mockito.when(instanceCertManager.getUnrefreshedCertsNotifications(eq(serverName), anyString())).thenReturn(records);
    CertFailedRefreshNotificationTask certFailedRefreshNotificationTask = new CertFailedRefreshNotificationTask(instanceCertManager, snoozedDataStore, hostnameResolver, userDomainPrefix, serverName, httpsPort, notificationToEmailConverterCommon);
    List<Notification> notifications = certFailedRefreshNotificationTask.getNotifications();
    assertEquals(5, notifications.size());
    assertEquals("domain8", notifications.get(0).getDetails().get("domain"));
    assertEquals("domain7", notifications.get(1).getDetails().get("domain"));
    assertEquals("domain5", notifications.get(2).getDetails().get("domain"));
    assertEquals("domain3", notifications.get(3).getDetails().get("domain"));
    assertEquals("domain1", notifications.get(4).getDetails().get("domain"));
    System.clearProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST);
}
Also used : DomainData(com.yahoo.athenz.zms.DomainData) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) DataStore(com.yahoo.athenz.zts.store.DataStore) TagValueList(com.yahoo.athenz.zms.TagValueList) Test(org.testng.annotations.Test)

Example 10 with Notification

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

the class CertFailedRefreshNotificationTaskTest method testNoValidHosts.

@Test
public void testNoValidHosts() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    // Create 6 mock records. None of them 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(false);
    }
    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);
}
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