use of com.yahoo.athenz.zms.store.AthenzDomain 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.store.AthenzDomain 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"));
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class DBServiceTest method testGetPublicKeyFromCache.
@Test
public void testGetPublicKeyFromCache() {
final String domainName1 = "getcachepublickey";
final String domainName2 = "getcachepublickey2";
AthenzDomain athenzDomain1 = new AthenzDomain(domainName1);
ServiceIdentity service1 = createServiceObject(domainName1, "service1", "http://localhost", "/usr/bin/java", "root", "users", "host1");
ServiceIdentity service2 = createServiceObject(domainName1, "service2", "http://localhost", "/usr/bin/java", "root", "users", "host1");
ServiceIdentity service3 = new ServiceIdentity();
service3.setName(ResourceUtils.serviceResourceName(domainName1, "service3"));
List<ServiceIdentity> services = new ArrayList<>();
services.add(service1);
services.add(service2);
services.add(service3);
athenzDomain1.setServices(services);
DataCache dataCache1 = new DataCache(athenzDomain1, 101);
AthenzDomain athenzDomain2 = new AthenzDomain(domainName2);
DataCache dataCache2 = new DataCache(athenzDomain2, 101);
zms.dbService.cacheStore.put(domainName1, dataCache1);
zms.dbService.cacheStore.put(domainName2, dataCache2);
PublicKeyEntry key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "1");
assertNotNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "2");
assertNotNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "1");
assertNotNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "2");
assertNotNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service1", "3");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service2", "3");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service3", "1");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service4", "1");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName1, "service5", "2");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName2, "service1", "1");
assertNull(key);
key = zms.dbService.getPublicKeyFromCache(domainName2, "service2", "1");
assertNull(key);
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class DBServiceTest method testGetRolesByDomain.
@Test
public void testGetRolesByDomain() {
ObjectStore saveStore = zms.dbService.store;
AthenzDomain athenzDomain = new AthenzDomain("test1");
Domain domain = new Domain().setName("test1").setMemberExpiryDays(100).setModified(Timestamp.fromCurrentTime());
athenzDomain.setDomain(domain);
Role testRole = new Role();
testRole.setName("admin");
List<Role> roles = new ArrayList<>();
roles.add(testRole);
athenzDomain.setRoles(roles);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getDomain(eq("test1"))).thenReturn(domain);
Mockito.when(mockJdbcConn.getAthenzDomain(eq("test1"))).thenReturn(athenzDomain);
zms.dbService.store = mockObjStore;
List<Role> rolesFetched = zms.dbService.getRolesByDomain("test1");
assertEquals(1, rolesFetched.size());
assertEquals("admin", rolesFetched.get(0).getName());
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.AthenzDomain in project athenz by yahoo.
the class DBServiceTest method testSetMembersInDomainEmptyMembers.
@Test
public void testSetMembersInDomainEmptyMembers() {
String domainName = "no-role-members";
List<RoleMember> roleMembers = new ArrayList<>();
roleMembers.add(new RoleMember().setMemberName("user.admin"));
Role role = new Role().setMembers(null).setRoleMembers(roleMembers);
List<Role> roles = new ArrayList<>();
roles.add(role);
Domain domain = new Domain().setModified(Timestamp.fromCurrentTime());
AthenzDomain athenzDomain = new AthenzDomain(domainName);
athenzDomain.setDomain(domain);
athenzDomain.setRoles(roles);
Mockito.when(mockObjStore.getConnection(true, false)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.getAthenzDomain(domainName)).thenReturn(athenzDomain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
AthenzDomain resAthenzDomain = zms.dbService.getAthenzDomain(domainName, false);
assertNotNull(resAthenzDomain.getRoles());
List<RoleMember> roleMembersResult = resAthenzDomain.getRoles().get(0).getRoleMembers();
assertEquals(roleMembersResult.size(), 1);
assertEquals(roleMembersResult.get(0).getMemberName(), "user.admin");
zms.dbService.store = saveStore;
}
Aggregations