Search in sources :

Example 61 with AthenzDomain

use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.

the class PutGroupMembershipNotificationTaskTest method testGenerateAndSendPostPutGroupMembershipNotificationSelfserve.

@Test
public void testGenerateAndSendPostPutGroupMembershipNotificationSelfserve() {
    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("group", "group1");
    List<RoleMember> roleMembers = new ArrayList<>();
    RoleMember rm = new RoleMember().setMemberName("user.domadmin1").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("user.domadmin2").setActive(true);
    roleMembers.add(rm);
    rm = new RoleMember().setMemberName("dom2.testsvc1").setActive(true);
    roleMembers.add(rm);
    Role adminRole = new Role().setName("testdomain1:role.admin").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    AthenzDomain athenzDomain = new AthenzDomain("testdomain1");
    athenzDomain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("testdomain1")).thenReturn(athenzDomain.getRoles());
    ArgumentCaptor<Notification> captor = ArgumentCaptor.forClass(Notification.class);
    Group notifyGroup = new Group().setAuditEnabled(false).setSelfServe(true);
    List<Notification> notifications = new PutGroupMembershipNotificationTask("testdomain1", "neworg", notifyGroup, details, dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    notificationManager.sendNotifications(notifications);
    Notification notification = new Notification();
    notification.addRecipient("user.domadmin1").addRecipient("user.domadmin2");
    notification.addDetails("domain", "testdomain1").addDetails("group", "group1");
    PutGroupMembershipNotificationTask.PutGroupMembershipNotificationToEmailConverter converter = new PutGroupMembershipNotificationTask.PutGroupMembershipNotificationToEmailConverter(notificationToEmailConverterCommon);
    notification.setNotificationToEmailConverter(converter);
    PutGroupMembershipNotificationTask.PutGroupMembershipNotificationToMetricConverter metricConverter = new PutGroupMembershipNotificationTask.PutGroupMembershipNotificationToMetricConverter();
    notification.setNotificationToMetricConverter(metricConverter);
    Mockito.verify(mockNotificationService, atLeastOnce()).notify(captor.capture());
    Notification actualNotification = captor.getValue();
    assertEquals(actualNotification, notification);
}
Also used : 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) Test(org.testng.annotations.Test)

Example 62 with AthenzDomain

use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.

the class RoleMemberExpiryNotificationTaskTest method testSendRoleMemberExpiryReminders.

@Test
public void testSendRoleMemberExpiryReminders() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    List<MemberRole> memberRoles = new ArrayList<>();
    memberRoles.add(new MemberRole().setRoleName("role1").setDomainName("athenz1").setMemberName("user.joe").setExpiration(Timestamp.fromMillis(100)));
    DomainRoleMember domainRoleMember = new DomainRoleMember().setMemberName("user.joe").setMemberRoles(memberRoles);
    Map<String, DomainRoleMember> expiryMembers = new HashMap<>();
    expiryMembers.put("user.joe", domainRoleMember);
    // we're going to return null for our first thread which will
    // run during init call and then the real data for the second
    // call
    Mockito.when(dbsvc.getRoleExpiryMembers(1, false)).thenReturn(null).thenReturn(expiryMembers);
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    ZMSTestUtils.sleep(1000);
    AthenzDomain domain = new AthenzDomain("athenz1");
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.jane"));
    Role adminRole = new Role().setName("athenz1:role.admin").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    domain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("athenz1")).thenReturn(domain.getRoles());
    List<Notification> notifications = new RoleMemberExpiryNotificationTask(dbsvc, USER_DOMAIN_PREFIX, new NotificationToEmailConverterCommon(null)).getNotifications();
    // we should get 2 notifications - one for user and one for domain
    assertEquals(notifications.size(), 2);
    // Verify contents of notifications is as expected
    Notification expectedFirstNotification = new Notification();
    expectedFirstNotification.addRecipient("user.joe");
    expectedFirstNotification.addDetails(NOTIFICATION_DETAILS_ROLES_LIST, "athenz1;role1;1970-01-01T00:00:00.100Z");
    expectedFirstNotification.addDetails("member", "user.joe");
    expectedFirstNotification.setNotificationToEmailConverter(new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToEmailConverter(new NotificationToEmailConverterCommon(null)));
    expectedFirstNotification.setNotificationToMetricConverter(new RoleMemberExpiryNotificationTask.RoleExpiryPrincipalNotificationToMetricConverter());
    Notification expectedSecondNotification = new Notification();
    expectedSecondNotification.addRecipient("user.jane");
    expectedSecondNotification.addDetails(NOTIFICATION_DETAILS_MEMBERS_LIST, "user.joe;role1;1970-01-01T00:00:00.100Z");
    expectedSecondNotification.addDetails("domain", "athenz1");
    expectedSecondNotification.setNotificationToEmailConverter(new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToEmailConverter(new NotificationToEmailConverterCommon(null)));
    expectedSecondNotification.setNotificationToMetricConverter(new RoleMemberExpiryNotificationTask.RoleExpiryDomainNotificationToMetricConverter());
    assertEquals(notifications.get(0), expectedFirstNotification);
    assertEquals(notifications.get(1), expectedSecondNotification);
    notificationManager.shutdown();
}
Also used : 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) Test(org.testng.annotations.Test)

Example 63 with AthenzDomain

use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.

the class GroupMemberExpiryNotificationTaskTest method testSendGroupMemberExpiryReminders.

@Test
public void testSendGroupMemberExpiryReminders() {
    DBService dbsvc = Mockito.mock(DBService.class);
    NotificationToEmailConverterCommon notificationToEmailConverterCommon = new NotificationToEmailConverterCommon(null);
    NotificationService mockNotificationService = Mockito.mock(NotificationService.class);
    NotificationServiceFactory testfact = () -> mockNotificationService;
    List<GroupMember> memberGroups = new ArrayList<>();
    memberGroups.add(new GroupMember().setGroupName("group1").setDomainName("athenz1").setMemberName("user.joe").setExpiration(Timestamp.fromMillis(100)));
    DomainGroupMember domainGroupMember = new DomainGroupMember().setMemberName("user.joe").setMemberGroups(memberGroups);
    Map<String, DomainGroupMember> expiryMembers = new HashMap<>();
    expiryMembers.put("user.joe", domainGroupMember);
    // we're going to return null for our first thread which will
    // run during init call and then the real data for the second
    // call
    Mockito.when(dbsvc.getGroupExpiryMembers(1)).thenReturn(null).thenReturn(expiryMembers);
    NotificationManager notificationManager = getNotificationManager(dbsvc, testfact);
    ZMSTestUtils.sleep(1000);
    AthenzDomain domain = new AthenzDomain("athenz1");
    List<RoleMember> roleMembers = new ArrayList<>();
    roleMembers.add(new RoleMember().setMemberName("user.jane"));
    Role adminRole = new Role().setName("athenz1:role.admin").setRoleMembers(roleMembers);
    List<Role> roles = new ArrayList<>();
    roles.add(adminRole);
    domain.setRoles(roles);
    Mockito.when(dbsvc.getRolesByDomain("athenz1")).thenReturn(domain.getRoles());
    List<Notification> notifications = new GroupMemberExpiryNotificationTask(dbsvc, USER_DOMAIN_PREFIX, notificationToEmailConverterCommon).getNotifications();
    // we should get 2 notifications - one for user and one for domain
    assertEquals(notifications.size(), 2);
    // Verify contents of notifications is as expected
    Notification expectedFirstNotification = new Notification();
    expectedFirstNotification.addRecipient("user.joe");
    expectedFirstNotification.addDetails(NOTIFICATION_DETAILS_ROLES_LIST, "athenz1;group1;1970-01-01T00:00:00.100Z");
    expectedFirstNotification.addDetails("member", "user.joe");
    expectedFirstNotification.setNotificationToEmailConverter(new GroupMemberExpiryNotificationTask.GroupExpiryPrincipalNotificationToEmailConverter(notificationToEmailConverterCommon));
    expectedFirstNotification.setNotificationToMetricConverter(new GroupMemberExpiryNotificationTask.GroupExpiryPrincipalNotificationToToMetricConverter());
    Notification expectedSecondNotification = new Notification();
    expectedSecondNotification.addRecipient("user.jane");
    expectedSecondNotification.addDetails(NOTIFICATION_DETAILS_MEMBERS_LIST, "user.joe;group1;1970-01-01T00:00:00.100Z");
    expectedSecondNotification.addDetails("domain", "athenz1");
    expectedSecondNotification.setNotificationToEmailConverter(new GroupMemberExpiryNotificationTask.GroupExpiryDomainNotificationToEmailConverter(notificationToEmailConverterCommon));
    expectedSecondNotification.setNotificationToMetricConverter(new GroupMemberExpiryNotificationTask.GroupExpiryDomainNotificationToMetricConverter());
    assertEquals(notifications.get(0), expectedFirstNotification);
    assertEquals(notifications.get(1), expectedSecondNotification);
    notificationManager.shutdown();
}
Also used : 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) Test(org.testng.annotations.Test)

Example 64 with AthenzDomain

use of com.yahoo.athenz.zms.store.AthenzDomain 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);
}
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 65 with AthenzDomain

use of com.yahoo.athenz.zms.store.AthenzDomain 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);
}
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)

Aggregations

AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)104 Test (org.testng.annotations.Test)28 Principal (com.yahoo.athenz.auth.Principal)14 Authority (com.yahoo.athenz.auth.Authority)13 MetricNotificationService (com.yahoo.athenz.common.server.notification.impl.MetricNotificationService)13 ZMSNotificationManagerTest.getNotificationManager (com.yahoo.athenz.zms.notification.ZMSNotificationManagerTest.getNotificationManager)13 DBService (com.yahoo.athenz.zms.DBService)6 Role (com.yahoo.athenz.zms.Role)6 RoleMember (com.yahoo.athenz.zms.RoleMember)6 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)3 ObjectStoreConnection (com.yahoo.athenz.zms.store.ObjectStoreConnection)3 java.sql (java.sql)3 SQLException (java.sql.SQLException)2 AuthzDetailsEntity (com.yahoo.athenz.common.config.AuthzDetailsEntity)1 DomainRoleMembersFetcher (com.yahoo.athenz.common.server.notification.DomainRoleMembersFetcher)1 DataCache (com.yahoo.athenz.zms.DBService.DataCache)1 Domain (com.yahoo.athenz.zms.Domain)1 ResourceException (com.yahoo.athenz.zms.ResourceException)1 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)1 Timestamp (com.yahoo.rdl.Timestamp)1