test(core): prove Views cannot grant access
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
|
AuthInfo,
|
||||||
DashboardWidgetsUiCapability,
|
DashboardWidgetsUiCapability,
|
||||||
OrganizationFunctionActionContext,
|
OrganizationFunctionActionContext,
|
||||||
OrganizationFunctionActionContribution,
|
OrganizationFunctionActionContribution,
|
||||||
@@ -17,7 +18,7 @@ import {
|
|||||||
visibleRoutesForProjection
|
visibleRoutesForProjection
|
||||||
} from "../src/platform/views";
|
} from "../src/platform/views";
|
||||||
import { groupNavigationItems } from "../src/platform/productAreas";
|
import { groupNavigationItems } from "../src/platform/productAreas";
|
||||||
import { scopeGrants } from "../src/utils/permissions";
|
import { hasAnyScope, scopeGrants } from "../src/utils/permissions";
|
||||||
|
|
||||||
function assert(condition: unknown, message: string): void {
|
function assert(condition: unknown, message: string): void {
|
||||||
if (!condition) throw new Error(message);
|
if (!condition) throw new Error(message);
|
||||||
@@ -194,7 +195,7 @@ assert(
|
|||||||
|
|
||||||
const viewAwareFiles: PlatformWebModule = {
|
const viewAwareFiles: PlatformWebModule = {
|
||||||
...files,
|
...files,
|
||||||
navItems: [{ to: "/files", label: "Files", order: 20 }],
|
navItems: [{ to: "/files", label: "Files", order: 20, anyOf: ["files:file:read"] }],
|
||||||
viewSurfaces: [
|
viewSurfaces: [
|
||||||
{
|
{
|
||||||
id: "files.settings.connectors",
|
id: "files.settings.connectors",
|
||||||
@@ -265,6 +266,28 @@ assert(
|
|||||||
visibleRoutesForProjection([viewAwareFiles], filesView).length === 1,
|
visibleRoutesForProjection([viewAwareFiles], filesView).length === 1,
|
||||||
"selected routes should remain in the effective route list"
|
"selected routes should remain in the effective route list"
|
||||||
);
|
);
|
||||||
|
const unauthorizedFilesUser = {
|
||||||
|
user: { id: "user-1", account_id: "account-1", email: "viewer@example.test" },
|
||||||
|
tenant: { id: "tenant-1", slug: "test", name: "Test" },
|
||||||
|
scopes: [],
|
||||||
|
roles: [],
|
||||||
|
groups: [],
|
||||||
|
principal: {
|
||||||
|
account_id: "account-1",
|
||||||
|
tenant_id: "tenant-1",
|
||||||
|
scopes: [],
|
||||||
|
group_ids: [],
|
||||||
|
auth_method: "session"
|
||||||
|
},
|
||||||
|
profile_loaded: true,
|
||||||
|
roles_loaded: true,
|
||||||
|
groups_loaded: true
|
||||||
|
} satisfies AuthInfo;
|
||||||
|
assert(
|
||||||
|
isViewSurfaceVisible(filesView, "files.nav.files", viewCatalogue) &&
|
||||||
|
!hasAnyScope(unauthorizedFilesUser, ["files:file:read"]),
|
||||||
|
"View visibility must not add the Access permission required by a module"
|
||||||
|
);
|
||||||
|
|
||||||
const missingParentView = {
|
const missingParentView = {
|
||||||
...filesView,
|
...filesView,
|
||||||
|
|||||||
Reference in New Issue
Block a user