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);
}
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));
}
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"));
}
Aggregations