use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testUpdatePrincipalByStateFromAuthorityExceptionUpdateGroupMembership.
@Test
public void testUpdatePrincipalByStateFromAuthorityExceptionUpdateGroupMembership() {
JDBCConnection jdbcConn = Mockito.mock(JDBCConnection.class);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(jdbcConn);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
Mockito.when(jdbcConn.updatePrincipal("user.user1", 2)).thenReturn(true);
Mockito.when(jdbcConn.updatePrincipal("user.user2", 2)).thenReturn(true);
DomainRoleMember drm = new DomainRoleMember();
List<MemberRole> memberRoles = new ArrayList<>();
drm.setMemberRoles(memberRoles);
Mockito.when(jdbcConn.getPrincipalRoles("user.user1", null)).thenReturn(drm);
Mockito.when(jdbcConn.getPrincipalRoles("user.user2", null)).thenReturn(drm);
Mockito.when(jdbcConn.getPrincipalGroups("user.user1", null)).thenThrow(new ResourceException(ResourceException.NOT_FOUND, "not found"));
Mockito.when(jdbcConn.getPrincipalGroups("user.user2", null)).thenThrow(new ResourceException(ResourceException.CONFLICT, "conflict"));
List<Principal> changedPrincipals = new ArrayList<>();
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user1", "user", null));
changedPrincipals.add(ZMSUtils.createPrincipalForName("user.user2", "user", null));
try {
zms.dbService.updatePrincipalByStateFromAuthority(changedPrincipals, true);
fail();
} catch (ResourceException rex) {
assertEquals(rex.getCode(), ResourceException.CONFLICT);
}
Mockito.verify(jdbcConn, atLeastOnce()).getPrincipalGroups("user.user1", null);
Mockito.verify(jdbcConn, atLeastOnce()).getPrincipalGroups("user.user2", null);
zms.dbService.store = savedStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class AWSObjectStoreFactoryTest method testCreateWithReplica.
@Test
public void testCreateWithReplica() {
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_MASTER_INSTANCE, "instance");
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_REPLICA_INSTANCE, "replica");
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_USER, "rds-user");
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "30000");
AWSObjectStoreFactory factory = new TestAWSObjectStoreFactory();
ObjectStore store = factory.create(null);
// sleep a couple of seconds for the updater to run
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
assertNotNull(store);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class AWSObjectStoreFactoryTest method testCreate.
@Test
public void testCreate() {
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_MASTER_INSTANCE, "instance");
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_USER, "rds-user");
System.setProperty(ZMSConsts.ZMS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "1");
System.clearProperty(ZMSConsts.ZMS_PROP_AWS_RDS_REPLICA_INSTANCE);
AWSObjectStoreFactory factory = new TestAWSObjectStoreFactory();
ObjectStore store = factory.create(null);
// sleep a couple of seconds for the updater to run
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
assertNotNull(store);
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testExecutePutRoleFailure.
@Test
public void testExecutePutRoleFailure() {
String domainName = "executeputroledom1";
String roleName = "role1";
Role role1 = createRoleObject(domainName, roleName, null, "user.joe", "user.jane");
Mockito.when(mockObjStore.getConnection(false, true)).thenReturn(mockJdbcConn);
Mockito.when(mockJdbcConn.insertRole(anyString(), any(Role.class))).thenReturn(false);
Domain domain = new Domain().setName(domainName);
Mockito.when(mockJdbcConn.getDomain(domainName)).thenReturn(domain);
ObjectStore saveStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
try {
zms.dbService.executePutRole(mockDomRsrcCtx, domainName, roleName, role1, auditRef, "putRole");
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.INTERNAL_SERVER_ERROR);
}
zms.dbService.store = saveStore;
}
use of com.yahoo.athenz.zms.store.ObjectStore in project athenz by yahoo.
the class DBServiceTest method testEnforceRoleUserAuthorityRestrictionsNoUpdate.
@Test
public void testEnforceRoleUserAuthorityRestrictionsNoUpdate() {
Authority savedAuthority = zms.dbService.zmsConfig.getUserAuthority();
Authority authority = Mockito.mock(Authority.class);
Mockito.when(authority.getDateAttribute("user.joe", "elevated-clearance")).thenReturn(null);
zms.dbService.zmsConfig.setUserAuthority(authority);
final String domainName = "authority-test";
final String roleName = "auth-role";
ObjectStoreConnection mockConn = Mockito.mock(ObjectStoreConnection.class);
Mockito.when(mockConn.insertRoleMember(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(true);
Mockito.when(mockConn.updateDomainModTimestamp(domainName)).thenReturn(true);
Mockito.when(mockObjStore.getConnection(true, true)).thenReturn(mockConn);
// first we're going to return a null role and then a role
// with no members - in both cases we return without processing
// any code
Role role = new Role().setUserAuthorityExpiration("elevated-clearance");
List<RoleMember> roleMembers = new ArrayList<>();
roleMembers.add(new RoleMember().setMemberName("user.joe").setExpiration(Timestamp.fromMillis(System.currentTimeMillis() - 10000)));
Mockito.when(mockConn.getRole(domainName, roleName)).thenReturn(role);
Mockito.when(mockConn.listRoleMembers(domainName, roleName, false)).thenReturn(roleMembers);
ObjectStore savedStore = zms.dbService.store;
zms.dbService.store = mockObjStore;
// the request should complete successfully
zms.dbService.enforceRoleUserAuthorityRestrictions(domainName, roleName, null);
zms.dbService.zmsConfig.setUserAuthority(savedAuthority);
zms.dbService.store = savedStore;
}
Aggregations