Search in sources :

Example 1 with InternalApplicationUserPermission

use of com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission in project notifications-backend by RedHatInsights.

the class InternalPermissionsServiceTest method accessListTest.

@Test
public void accessListTest() {
    String appRole = "Acrc-app-team";
    String otherRole = "Bcrc-other-team-role";
    Header turnpikeAdminHeader = TestHelpers.createTurnpikeIdentityHeader("admin", adminRole);
    Header turnpikeAppDev = TestHelpers.createTurnpikeIdentityHeader("app-admin", appRole);
    String bundleId = CrudTestHelpers.createBundle(turnpikeAdminHeader, "test-access-list-bundle", "Test access list Bundle", 200).get();
    String appDisplayName = "Test access list App";
    String appId = CrudTestHelpers.createApp(turnpikeAdminHeader, bundleId, "test-access-list-app", appDisplayName, null, 200).get();
    // app devs can't access it
    CrudTestHelpers.getAccessList(turnpikeAppDev, FORBIDDEN);
    // admins can access it
    List<InternalApplicationUserPermission> accessList = CrudTestHelpers.getAccessList(turnpikeAdminHeader, OK).get();
    // appId is not in the list
    assertEquals(0, accessList.stream().filter(a -> a.applicationId.toString().equals(appId)).count());
    CrudTestHelpers.createInternalRoleAccess(turnpikeAdminHeader, appRole, appId, OK);
    accessList = CrudTestHelpers.getAccessList(turnpikeAdminHeader, OK).get();
    // It should be in the list now
    List<InternalApplicationUserPermission> filtered = accessList.stream().filter(a -> a.applicationId.toString().equals(appId)).collect(Collectors.toList());
    assertEquals(1, filtered.size());
    assertEquals(appId, filtered.get(0).applicationId.toString());
    assertEquals(appDisplayName, filtered.get(0).applicationDisplayName);
    assertEquals(appRole, filtered.get(0).role);
    // Adding other role to the same app
    CrudTestHelpers.createInternalRoleAccess(turnpikeAdminHeader, otherRole, appId, OK);
    accessList = CrudTestHelpers.getAccessList(turnpikeAdminHeader, OK).get();
    filtered = accessList.stream().filter(a -> a.applicationId.toString().equals(appId)).sorted(Comparator.comparing(t -> t.role)).collect(Collectors.toList());
    assertEquals(2, filtered.size());
    assertEquals(appId, filtered.get(0).applicationId.toString());
    assertEquals(appDisplayName, filtered.get(0).applicationDisplayName);
    assertEquals(appRole, filtered.get(0).role);
    assertEquals(appId, filtered.get(1).applicationId.toString());
    assertEquals(appDisplayName, filtered.get(1).applicationDisplayName);
    assertEquals(otherRole, filtered.get(1).role);
}
Also used : QuarkusTestResource(io.quarkus.test.common.QuarkusTestResource) JSON(io.restassured.http.ContentType.JSON) TestLifecycleManager(com.redhat.cloud.notifications.TestLifecycleManager) Header(io.restassured.http.Header) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) List(java.util.List) InternalUserPermissions(com.redhat.cloud.notifications.routers.internal.models.InternalUserPermissions) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CrudTestHelpers(com.redhat.cloud.notifications.CrudTestHelpers) TestHelpers(com.redhat.cloud.notifications.TestHelpers) RestAssured.given(io.restassured.RestAssured.given) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest) Comparator(java.util.Comparator) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) Header(io.restassured.http.Header) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) DbIsolatedTest(com.redhat.cloud.notifications.db.DbIsolatedTest)

Example 2 with InternalApplicationUserPermission

use of com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission in project notifications-backend by RedHatInsights.

the class CrudTestHelpers method getAccessList.

public static Optional<List<InternalApplicationUserPermission>> getAccessList(Header identity, int expected) {
    String responseBody = given().header(identity).when().get("internal/access").then().statusCode(expected).extract().asString();
    if (familyOf(expected) == SUCCESSFUL) {
        JsonArray json = new JsonArray(responseBody);
        List<InternalApplicationUserPermission> accessList = json.stream().map(o -> {
            JsonObject jsonObject = (JsonObject) o;
            assertNotNull(jsonObject.getString("application_id"));
            assertNotNull(jsonObject.getString("application_display_name"));
            assertNotNull(jsonObject.getString("role"));
            return jsonObject.mapTo(InternalApplicationUserPermission.class);
        }).collect(Collectors.toList());
        return Optional.of(accessList);
    }
    return Optional.empty();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ValidatableResponse(io.restassured.response.ValidatableResponse) AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Header(io.restassured.http.Header) API_INTERNAL(com.redhat.cloud.notifications.Constants.API_INTERNAL) EventType(com.redhat.cloud.notifications.models.EventType) Template(com.redhat.cloud.notifications.models.Template) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) RequestSpecification(io.restassured.specification.RequestSpecification) Map(java.util.Map) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate) JsonObject(io.vertx.core.json.JsonObject) InternalRoleAccess(com.redhat.cloud.notifications.models.InternalRoleAccess) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nullable(javax.annotation.Nullable) Application(com.redhat.cloud.notifications.models.Application) JSON(io.restassured.http.ContentType.JSON) TEXT(io.restassured.http.ContentType.TEXT) OK(org.jboss.resteasy.reactive.RestResponse.StatusCode.OK) AddApplicationRequest(com.redhat.cloud.notifications.routers.internal.models.AddApplicationRequest) Family.familyOf(javax.ws.rs.core.Response.Status.Family.familyOf) Bundle(com.redhat.cloud.notifications.models.Bundle) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AddAccessRequest(com.redhat.cloud.notifications.routers.internal.models.AddAccessRequest) Matchers.any(org.hamcrest.Matchers.any) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) Matchers.is(org.hamcrest.Matchers.is) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) Matchers.containsString(org.hamcrest.Matchers.containsString) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString)

Aggregations

InternalApplicationUserPermission (com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission)2 RestAssured.given (io.restassured.RestAssured.given)2 JSON (io.restassured.http.ContentType.JSON)2 Header (io.restassured.http.Header)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 API_INTERNAL (com.redhat.cloud.notifications.Constants.API_INTERNAL)1 CrudTestHelpers (com.redhat.cloud.notifications.CrudTestHelpers)1 TestHelpers (com.redhat.cloud.notifications.TestHelpers)1 TestLifecycleManager (com.redhat.cloud.notifications.TestLifecycleManager)1 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)1 AggregationEmailTemplate (com.redhat.cloud.notifications.models.AggregationEmailTemplate)1 Application (com.redhat.cloud.notifications.models.Application)1 BehaviorGroup (com.redhat.cloud.notifications.models.BehaviorGroup)1 Bundle (com.redhat.cloud.notifications.models.Bundle)1 EventType (com.redhat.cloud.notifications.models.EventType)1 InstantEmailTemplate (com.redhat.cloud.notifications.models.InstantEmailTemplate)1