Search in sources :

Example 11 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord 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 12 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord 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 13 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class CertFailedRefreshNotificationTaskTest method getMockX509CertRecord.

private X509CertRecord getMockX509CertRecord(Date date, int recordId) {
    X509CertRecord record = new X509CertRecord();
    record.setHostName("hostName" + recordId);
    record.setCurrentTime(date);
    record.setInstanceId("instanceID" + recordId);
    record.setProvider("provider");
    record.setService("domain" + recordId + ".service" + recordId);
    return record;
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord)

Example 14 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord 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)

Example 15 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class CertFailedRefreshNotificationTaskTest method testNoValidRecipient.

@Test
public void testNoValidRecipient() {
    Date currentDate = new Date();
    List<X509CertRecord> records = new ArrayList<>();
    System.setProperty(ZTS_PROP_NOTIFICATION_CERT_FAIL_PROVIDER_LIST, "provider");
    X509CertRecord record = getMockX509CertRecord(currentDate, 1);
    records.add(record);
    String domainName = "domain1";
    Mockito.when(dataStore.getRolesByDomain(eq(domainName))).thenReturn(new ArrayList<>());
    Mockito.when(hostnameResolver.isValidHostname(eq("hostName1"))).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);
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Notification(com.yahoo.athenz.common.server.notification.Notification) Test(org.testng.annotations.Test)

Aggregations

X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)80 Test (org.testng.annotations.Test)64 DataStore (com.yahoo.athenz.zts.store.DataStore)25 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)23 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)22 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)22 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)22 Path (java.nio.file.Path)22 X509Certificate (java.security.cert.X509Certificate)22 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)18 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)16 Date (java.util.Date)13 Notification (com.yahoo.athenz.common.server.notification.Notification)10 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)5 File (java.io.File)5 Timestamp (java.sql.Timestamp)5 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)4 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4