Search in sources :

Example 1 with ZTSClientNotification

use of com.yahoo.athenz.zts.ZTSClientNotification in project athenz by yahoo.

the class AWSZTSHealthNotificationTaskTest method testGetNotifications.

@Test
public void testGetNotifications() {
    System.setProperty(ZTSConsts.ZTS_PROP_NOTIFICATION_AWS_HEALTH_DOMAIN, "testDomain");
    ZTSClientNotification clientNotification = new ZTSClientNotification("zts.url", "role", "AWS", 1592346376, false, "testDomain");
    RoleMember roleMember1 = new RoleMember();
    roleMember1.setMemberName("user.test1");
    RoleMember roleMember2 = new RoleMember();
    roleMember2.setMemberName("user.test2");
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(roleMember1);
    roleMembers.add(roleMember2);
    Role adminRole = new Role();
    adminRole.setRoleMembers(roleMembers);
    adminRole.setName("testDomain:role.admin");
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    when(dataStore.getRolesByDomain(eq("testDomain"))).thenReturn(roles);
    AWSZTSHealthNotificationTask awsztsHealthNotificationTask = new AWSZTSHealthNotificationTask(clientNotification, dataStore, userDomainPrefix, serverName, notificationToEmailConverterCommon);
    List<Notification> notifications = awsztsHealthNotificationTask.getNotifications();
    assertEquals(1, notifications.size());
    assertTrue(notifications.get(0).getRecipients().contains("user.test1"));
    assertTrue(notifications.get(0).getRecipients().contains("user.test2"));
    Timestamp expiration = Timestamp.fromMillis(clientNotification.getExpiration() * 1000);
    assertEquals("zts.url;testDomain;role;" + expiration + ";Fail to get token of type AWS. ", notifications.get(0).getDetails().get("awsZtsHealth"));
    assertEquals("testServer", notifications.get(0).getDetails().get("affectedZts"));
    System.clearProperty(ZTSConsts.ZTS_PROP_NOTIFICATION_AWS_HEALTH_DOMAIN);
}
Also used : Role(com.yahoo.athenz.zms.Role) ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) Timestamp(com.yahoo.rdl.Timestamp) RoleMember(com.yahoo.athenz.zms.RoleMember) Notification(com.yahoo.athenz.common.server.notification.Notification) ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) Test(org.testng.annotations.Test)

Example 2 with ZTSClientNotification

use of com.yahoo.athenz.zts.ZTSClientNotification in project athenz by yahoo.

the class ZTSClientNotificationSenderImplTest method testSendNotificationNotInit.

@Test
public void testSendNotificationNotInit() {
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    ztsClientNotificationSender.init(notificationManager, null, null);
    ZTSClientNotification ztsClientNotification = Mockito.mock(ZTSClientNotification.class);
    ztsClientNotificationSender.sendNotification(ztsClientNotification);
    Mockito.verify(notificationManager, Mockito.times(0)).sendNotifications(any());
}
Also used : ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) Test(org.testng.annotations.Test)

Example 3 with ZTSClientNotification

use of com.yahoo.athenz.zts.ZTSClientNotification in project athenz by yahoo.

the class ZTSClientNotificationSenderImplTest method testSendNotificationInit.

@Test
public void testSendNotificationInit() {
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
    String serverName = "testServer";
    ztsClientNotificationSender.init(notificationManager, rolesProvider, serverName);
    ZTSClientNotification ztsClientNotification = Mockito.mock(ZTSClientNotification.class);
    ztsClientNotificationSender.sendNotification(ztsClientNotification);
    Mockito.verify(notificationManager, Mockito.times(1)).sendNotifications(any());
}
Also used : ZTSClientNotification(com.yahoo.athenz.zts.ZTSClientNotification) NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Aggregations

ZTSClientNotification (com.yahoo.athenz.zts.ZTSClientNotification)3 Test (org.testng.annotations.Test)3 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)1 Notification (com.yahoo.athenz.common.server.notification.Notification)1 Role (com.yahoo.athenz.zms.Role)1 RoleMember (com.yahoo.athenz.zms.RoleMember)1 Timestamp (com.yahoo.rdl.Timestamp)1