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);
}
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();
}
Aggregations