Path: blob/master/src/packages/backend/conat/test/persist/permissions.test.ts
1451 views
/*12pnpm test ./permissions.test.ts34*/5import { SERVICE } from "@cocalc/conat/persist/util";6import { assertHasWritePermission } from "@cocalc/conat/persist/auth";78const uuid = "00000000-0000-4000-8000-000000000000";9const uuid2 = "00000000-0000-4000-8000-000000000002";1011describe("test subject permissions directly by calling assertHasWritePermission", () => {12it("checks a bunch of things that should work don't throw", () => {13// these don't throw14assertHasWritePermission({15subject: `${SERVICE}.hub`,16path: "hub/foo",17});1819assertHasWritePermission({20subject: `${SERVICE}.hub`,21path: "hub/foo/blah xxx~!/xxxx",22});2324assertHasWritePermission({25subject: `${SERVICE}.project-${uuid}`,26path: `projects/${uuid}/a.txt`,27});2829assertHasWritePermission({30subject: `${SERVICE}.account-${uuid}`,31path: `accounts/${uuid}/c/d.txt`,32});33});3435it("now check many things that are NOT allowed", () => {36const BAD = [37{ subject: `${SERVICE}.fubar`, path: "hub/foo/bar" },38{ subject: `fluber.hub`, path: "hub/foo" },39{40subject: `${SERVICE}.projects-${uuid}`,41path: `projects/${uuid}/foo`,42},43{44subject: `${SERVICE}.accounts-${uuid}`,45path: `accounts/${uuid}/foo`,46},47{48subject: `${SERVICE}.project-${uuid}`,49path: `accounts/${uuid}/foo`,50},51{52subject: `${SERVICE}.account-${uuid}`,53path: `projects/${uuid}/foo`,54},55{56subject: `${SERVICE}.account-${uuid}`,57path: `accounts/${uuid2}/foo`,58},59{60subject: `${SERVICE}.project-${uuid}`,61path: `projects/${uuid2}/foo`,62},63{64subject: `${SERVICE}.project-${uuid}`,65path: `projects/${uuid}/`,66},67{68subject: `${SERVICE}.project-${uuid}`,69path: `projects/${uuid}`,70},71{72subject: `${SERVICE}.project-${uuid}`,73path: `projects/${uuid}/foo/`,74},75{76subject: `${SERVICE}.project-${uuid}`,77path: `projects/${uuid}/${"a".repeat(100000)}`,78},79{80subject: `${SERVICE}.project-${uuid}x`,81path: `projects/${uuid}x/a.txt`,82},83];8485for (const { subject, path } of BAD) {86expect(() => assertHasWritePermission({ subject, path })).toThrow();87}88});89});909192