Search in sources :

Example 6 with TestAuditLogger

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());
}
Also used : User(com.yahoo.elide.core.security.User) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) SecurityContextUser(com.yahoo.elide.jsonapi.resources.SecurityContextUser) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) ElideResponse(com.yahoo.elide.ElideResponse) SecurityContext(javax.ws.rs.core.SecurityContext) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) TestAuditLogger(com.yahoo.elide.core.audit.TestAuditLogger) Elide(com.yahoo.elide.Elide) Principal(java.security.Principal) Test(org.junit.jupiter.api.Test)

Aggregations

TestAuditLogger (com.yahoo.elide.core.audit.TestAuditLogger)6 Test (org.junit.jupiter.api.Test)5 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)4 Elide (com.yahoo.elide.Elide)3 ElideResponse (com.yahoo.elide.ElideResponse)3 LogMessage (com.yahoo.elide.core.audit.LogMessage)2 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)2 ChangeSpec (com.yahoo.elide.core.security.ChangeSpec)2 User (com.yahoo.elide.core.security.User)2 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)2 SecurityContextUser (com.yahoo.elide.jsonapi.resources.SecurityContextUser)2 Child (example.Child)2 Parent (example.Parent)2 Principal (java.security.Principal)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 SecurityContext (javax.ws.rs.core.SecurityContext)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 ElideSettings (com.yahoo.elide.ElideSettings)1 RequestScope (com.yahoo.elide.core.RequestScope)1 AuditLogger (com.yahoo.elide.core.audit.AuditLogger)1