use of com.yahoo.elide.core.audit.TestAuditLogger in project elide by yahoo.
the class AsyncIT method asyncQueryModelAdminReadPermissions.
/**
* Tests Read Permissions on AsyncQuery Model for Admin Role.
* @throws IOException IOException
*/
@Test
public void asyncQueryModelAdminReadPermissions() throws IOException {
ElideResponse response = null;
String id = "edc4a871-dff2-4054-804e-d80075c08959";
String query = "test-query";
com.yahoo.elide.async.models.AsyncQuery queryObj = new com.yahoo.elide.async.models.AsyncQuery();
queryObj.setId(id);
queryObj.setQuery(query);
queryObj.setQueryType(QueryType.JSONAPI_V1_0);
queryObj.setPrincipalName("owner-user");
dataStore.populateEntityDictionary(EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build());
DataStoreTransaction tx = dataStore.beginTransaction();
tx.createObject(queryObj, null);
tx.commit(null);
tx.close();
Elide elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(AsyncIntegrationTestApplicationResourceConfig.MAPPINGS).build()).withAuditLogger(new TestAuditLogger()).build());
elide.doScans();
User ownerUser = new User(() -> "owner-user");
SecurityContextUser securityContextAdminUser = new SecurityContextUser(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return () -> "1";
}
@Override
public boolean isUserInRole(String s) {
return true;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
SecurityContextUser securityContextNonAdminUser = new SecurityContextUser(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return () -> "2";
}
@Override
public boolean isUserInRole(String s) {
return false;
}
@Override
public boolean isSecure() {
return false;
}
@Override
public String getAuthenticationScheme() {
return null;
}
});
String baseUrl = "/";
// Principal is Owner
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), ownerUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
// Principal has Admin Role
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
// Principal without Admin Role
response = elide.get(baseUrl, "/asyncQuery/" + id, new MultivaluedHashMap<>(), securityContextNonAdminUser, NO_VERSION);
assertEquals(HttpStatus.SC_NOT_FOUND, response.getResponseCode());
}
Aggregations