use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetServiceIdentity.
@Test
public void testGetServiceIdentity() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("test description").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_EXECTUABLE);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_GROUP);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_USER);
Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_PROVIDER_ENDPOINT);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ServiceIdentity service = jdbcConn.getServiceIdentity("my-domain", "service1");
assertNotNull(service);
assertEquals("my-domain.service1", service.getName());
assertNull(service.getExecutable());
assertNull(service.getGroup());
assertNull(service.getUser());
assertNull(service.getProviderEndpoint());
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testParseRoleMember.
@Test
public void testParseRoleMember() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
StringBuilder domain = new StringBuilder(512);
StringBuilder name = new StringBuilder(512);
assertTrue(jdbcConn.parsePrincipal("user.user", domain, name));
assertEquals("user", domain.toString());
assertEquals("user", name.toString());
domain.setLength(0);
name.setLength(0);
assertTrue(jdbcConn.parsePrincipal("coretech.storage.service", domain, name));
assertEquals("coretech.storage", domain.toString());
assertEquals("service", name.toString());
assertFalse(jdbcConn.parsePrincipal(".coretech", domain, name));
assertFalse(jdbcConn.parsePrincipal("coretech.storage.service.", domain, name));
assertFalse(jdbcConn.parsePrincipal("service", domain, name));
assertFalse(jdbcConn.parsePrincipal("", domain, name));
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetEntityNotFound.
@Test
public void testGetEntityNotFound() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(// for domain id
true).thenReturn(false);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Entity entity = jdbcConn.getEntity("my-domain", "entity1");
assertNull(entity);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetRoleNotFound.
@Test
public void testGetRoleNotFound() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(false);
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Role role = jdbcConn.getRole("my-domain", "role1");
assertNull(role);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testListResourceAccess.
@Test
public void testListResourceAccess() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(// up to here is role principals
false).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(// up to here is role assertions
false).thenReturn(// no trusted role
false);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("user.user1").thenReturn("user.user2").thenReturn(// up to here is role principals
"user.user3").thenReturn("dom1").thenReturn("dom1").thenReturn("dom2");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_DOMAIN_ID)).thenReturn("101").thenReturn("101").thenReturn(// up to here is role principals
"102").thenReturn("101").thenReturn("101").thenReturn("102");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE_NAME)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE)).thenReturn("resource1").thenReturn("resource2").thenReturn("resource3");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("update");
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT)).thenReturn("ALLOW");
ResourceAccessList resourceAccessList = jdbcConn.listResourceAccess(null, "update", "user");
List<ResourceAccess> resources = resourceAccessList.getResources();
assertEquals(3, resources.size());
boolean userUser1 = false;
boolean userUser2 = false;
boolean userUser3 = false;
for (ResourceAccess rsrcAccess : resources) {
switch(rsrcAccess.getPrincipal()) {
case "user.user1":
userUser1 = true;
assertEquals(2, rsrcAccess.getAssertions().size());
break;
case "user.user2":
userUser2 = true;
assertEquals(2, rsrcAccess.getAssertions().size());
break;
case "user.user3":
userUser3 = true;
assertEquals(1, rsrcAccess.getAssertions().size());
break;
}
}
assertTrue(userUser1);
assertTrue(userUser2);
assertTrue(userUser3);
jdbcConn.close();
}
Aggregations