Search in sources :

Example 1 with TagValueList

use of com.yahoo.athenz.zms.TagValueList 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 2 with TagValueList

use of com.yahoo.athenz.zms.TagValueList in project athenz by yahoo.

the class CertFailedRefreshNotificationTaskTest method testAllRecordsSnoozed.

@Test
public void testAllRecordsSnoozed() {
    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 all domains snooze
        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);
    }
    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(new ArrayList<>(), notifications);
    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)

Aggregations

X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)2 Notification (com.yahoo.athenz.common.server.notification.Notification)2 DomainData (com.yahoo.athenz.zms.DomainData)2 TagValueList (com.yahoo.athenz.zms.TagValueList)2 DataStore (com.yahoo.athenz.zts.store.DataStore)2 Test (org.testng.annotations.Test)2