use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class DomainRoleMembersFetcherTest method testNoDomain.
@Test
public void testNoDomain() {
DBService dbsvc = Mockito.mock(DBService.class);
DomainRoleMembersFetcher domainRoleMembersFetcher = new DomainRoleMembersFetcher(dbsvc, USER_DOMAIN_PREFIX);
Set<String> domainRoleMembers = domainRoleMembersFetcher.getDomainRoleMembers("domain1", "domain1:role.admin");
assertEquals(new HashSet<>(), domainRoleMembers);
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotification.
@Test
public void testGenerateAndSendPostPutMembershipNotification() {
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);
roleMembers = new ArrayList<>();
rm = new RoleMember().setMemberName("user.orgapprover1").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("user.orgapprover2").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
roleMembers.add(rm);
Role orgRole = new Role().setName("sys.auth.audit.org:role.neworg").setRoleMembers(roleMembers);
List<Role> roles1 = new ArrayList<>();
roles1.add(orgRole);
AthenzDomain athenzDomain1 = new AthenzDomain("sys.auth.audit.org");
athenzDomain1.setRoles(roles1);
List<Role> roles2 = new ArrayList<>();
roles2.add(domainRole);
AthenzDomain athenzDomain2 = new AthenzDomain("sys.auth.audit.domain");
athenzDomain2.setRoles(roles2);
Mockito.when(dbsvc.getRolesByDomain("sys.auth.audit.org")).thenReturn(athenzDomain1.getRoles());
Mockito.when(dbsvc.getRolesByDomain("sys.auth.audit.domain")).thenReturn(athenzDomain2.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").addRecipient("user.orgapprover1").addRecipient("user.orgapprover2");
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 ZMSNotificationTaskFactoryTest method testNotificationTasksOrdering.
@Test
public void testNotificationTasksOrdering() {
DBService dbsvc = Mockito.mock(DBService.class);
ZMSNotificationTaskFactory zmsNotificationTaskFactory = new ZMSNotificationTaskFactory(dbsvc, USER_DOMAIN_PREFIX, new NotificationToEmailConverterCommon(null));
List<NotificationTask> notificationTasks = zmsNotificationTaskFactory.getNotificationTasks();
assertEquals(5, notificationTasks.size());
assertEquals(notificationTasks.get(0).getDescription(), "pending role membership approvals reminders");
assertEquals(notificationTasks.get(1).getDescription(), "pending group membership approvals reminders");
assertEquals(notificationTasks.get(2).getDescription(), "membership expiration reminders");
assertEquals(notificationTasks.get(3).getDescription(), "Periodic Review Reminder");
assertEquals(notificationTasks.get(4).getDescription(), "group membership expiration reminders");
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationNotifyRoles.
@Test
public void testGenerateAndSendPostPutMembershipNotificationNotifyRoles() {
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("athenz:role.approvers").setRoleMembers(roleMembers);
roleMembers = new ArrayList<>();
rm = new RoleMember().setMemberName("user.approver1").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("user.approver2").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
roleMembers.add(rm);
Role localRole = new Role().setName("testdomain1:role.notify").setRoleMembers(roleMembers);
List<Role> roles1 = new ArrayList<>();
roles1.add(localRole);
AthenzDomain athenzDomain1 = new AthenzDomain("coretech");
athenzDomain1.setRoles(roles1);
List<Role> roles2 = new ArrayList<>();
roles2.add(domainRole);
AthenzDomain athenzDomain2 = new AthenzDomain("athenz");
athenzDomain2.setRoles(roles2);
Mockito.when(dbsvc.getRolesByDomain("testdomain1")).thenReturn(athenzDomain1.getRoles());
Mockito.when(dbsvc.getRolesByDomain("athenz")).thenReturn(athenzDomain2.getRoles());
ArgumentCaptor<Notification> captor = ArgumentCaptor.forClass(Notification.class);
Role notifyRole = new Role().setAuditEnabled(false).setSelfServe(false).setReviewEnabled(true).setNotifyRoles("athenz:role.approvers,notify");
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").addRecipient("user.approver1").addRecipient("user.approver2");
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);
assertEquals(actualNotification, notification);
}
use of com.yahoo.athenz.zms.DBService in project athenz by yahoo.
the class PutRoleMembershipNotificationTaskTest method testGenerateAndSendPostPutMembershipNotificationNullDomainRole.
@Test
public void testGenerateAndSendPostPutMembershipNotificationNullDomainRole() {
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.orgapprover1").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("user.orgapprover2").setActive(true);
roleMembers.add(rm);
rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
roleMembers.add(rm);
Role orgRole = new Role().setName("sys.auth.audit.org:role.neworg").setRoleMembers(roleMembers);
List<Role> roles = new ArrayList<>();
roles.add(orgRole);
AthenzDomain athenzDomain = new AthenzDomain("sys.auth.audit.org");
athenzDomain.setRoles(roles);
Mockito.when(dbsvc.getRolesByDomain("sys.auth.audit.org")).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.orgapprover1").addRecipient("user.orgapprover2");
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);
}
Aggregations