Search in sources :

Example 11 with DBService

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

the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationNullOrgRole.

@Test
public void testGenerateAndSendPostPutMembershipNotificationNullOrgRole() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    notificationManager.shutdown();
    Map<String, String> details = new HashMap<>();
    details.put("domain", "testdomain1");
    details.put("role", "role1");
    List<RoleMember> roleMembers = new ArrayList<>();
    RoleMember rm = new RoleMember().setMemberName("user.domapprover1").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("user.domapprover2").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
    roleMembers.add(rm);
    Role domainRole = new Role().setName("sys.auth.audit.domain:role.testdomain1").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(domainRole);
    AthenzDomain athenzDomain = new AthenzDomain("sys.auth.audit.domain");
    athenzDomain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("sys.auth.audit.domain")).thenReturn(athenzDomain.getRoles());
    ArgumentCaptor<Notification> captor = ArgumentCaptor.forClass(Notification.class);
    Role notifyRole = new Role().setAuditEnabled(true).setSelfServe(false);
    List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, details, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
    Notification notification = new Notification();
    notification.addRecipient("user.domapprover1").addRecipient("user.domapprover2");
    notification.addDetails("domain", "testdomain1").addDetails("role", "role1");
    PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter converter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToEmailConverter(notificationToEmailConverterCommon);
    notification.setNotificationToEmailConverter(converter);
    PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter metricConverter = new PutRoleMembershipNotificationTask.PutMembershipNotificationToMetricConverter();
    notification.setNotificationToMetricConverter(metricConverter);
    Mockito.verify(mockNotificationService, atLeastOnce()).notify(captor.capture());
    Notification actualNotification = captor.getValue();
    assertEquals(actualNotification, notification);
}
Also used : DBService(com.yahoo.athenz.zms.DBService) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) MetricNotificationService(com.yahoo.athenz.common.server.notification.impl.MetricNotificationService) Role(com.yahoo.athenz.zms.Role) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Example 12 with DBService

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

the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationNullNotificationSvc.

@Test
public void testGenerateAndSendPostPutMembershipNotificationNullNotificationSvc() {
    DBService dbsvc = Mockito.mock(DBService.class);
    Mockito.when(dbsvc.getPendingMembershipApproverRoles(1)).thenReturn(Collections.emptySet());
    NotificationServiceFactory testfact = () -> null;
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    notificationManager.shutdown();
    Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(false);
    List<Notification> notifications = new PutRoleMembershipNotificationTask("testdomain1", "neworg", notifyRole, null, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
    verify(mockNotificationService, never()).notify(any(Notification.class));
}
Also used : DBService(com.yahoo.athenz.zms.DBService) Role(com.yahoo.athenz.zms.Role) ZMSNotificationManagerTest.getNotificationManager(com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager) MetricNotificationService(com.yahoo.athenz.common.server.notification.impl.MetricNotificationService) Test(org.testng.annotations.Test)

Example 13 with DBService

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

the class DomainRoleMembersFetcherTest method testGetDomainRoleMembers.

@Test
public void testGetDomainRoleMembers() {
    DBService dbsvc = Mockito.mock(DBService.class);
    String domainName = "domain1";
    AthenzDomain domainData = new AthenzDomain(domainName);
    Role adminRole = new Role();
    adminRole.setName(domainName + ":role.admin");
    RoleMember roleMember1 = new RoleMember();
    roleMember1.setMemberName("user.domain1rolemember1");
    RoleMember roleMember2 = new RoleMember();
    roleMember2.setMemberName("user.domain1rolemember2");
    adminRole.setRoleMembers(Arrays.asList(roleMember1, roleMember2));
    domainData.setRoles(Collections.singletonList(adminRole));
    Mockito.when(dbsvc.getRolesByDomain(eq("domain1"))).thenReturn(domainData.getRoles());
    DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(dbsvc, USER_DOMAIN_PREFIX);
    Set<String> domainRoleMembers = domainRoleMembersFetcher.getDomainRoleMembers("domain1", "domain1:role.admin");
    assertEquals(2, domainRoleMembers.size());
    assertTrue(domainRoleMembers.contains("user.domain1rolemember1"));
    assertTrue(domainRoleMembers.contains("user.domain1rolemember2"));
}
Also used : DBService(com.yahoo.athenz.zms.DBService) Role(com.yahoo.athenz.zms.Role) AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) DomainRoleMembersFetcher(com.yahoo.athenz.common.server.notification.DomainRoleMembersFetcher) RoleMember(com.yahoo.athenz.zms.RoleMember) Test(org.testng.annotations.Test)

Aggregations

DBService (com.yahoo.athenz.zms.DBService)13 Test (org.testng.annotations.Test)13 Role (com.yahoo.athenz.zms.Role)9 ZMSNotificationManagerTest.getNotificationManager (com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager)9 MetricNotificationService (com.yahoo.athenz.common.server.notification.impl.MetricNotificationService)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)6 DomainRoleMembersFetcher (com.yahoo.athenz.common.server.notification.DomainRoleMembersFetcher)2 NotificationTask (com.yahoo.athenz.common.server.notification.NotificationTask)1 NotificationToEmailConverterCommon (com.yahoo.athenz.common.server.notification.NotificationToEmailConverterCommon)1