Skip to content
Source
Sign inSign up
Open History to see the last commit

oauthScope.test.ts

35 lines1.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { encodeOAuthScope, parseAllowedOAuthScope, parseOAuthScope } from "./oauthScope.ts";
4​
5describe("OAuth scopes", () => {
6 it("parses an RFC 6749 space-delimited scope set without duplicating permissions", () => {
7 expect(parseOAuthScope("orchestration:read access:write orchestration:read")).toEqual([
8 "orchestration:read",
9 "access:write",
10 ]);
11 });
12​
13 it("rejects whitespace that is not the SP delimiter or introduces empty tokens", () => {
14 expect(parseOAuthScope("orchestration:read\taccess:write")).toBeNull();
15 expect(parseOAuthScope("orchestration:read access:write")).toBeNull();
16 });
17​
18 it("encodes and restricts requested scopes to the allowed capability set", () => {
19 expect(encodeOAuthScope(["orchestration:read", "access:write"])).toBe(
20 "orchestration:read access:write",
21 );
22 expect(
23 parseAllowedOAuthScope({
24 value: "orchestration:read access:write",
25 allowedScopes: new Set(["orchestration:read", "access:write"] as const),
26 }),
27 ).toEqual(["orchestration:read", "access:write"]);
28 expect(
29 parseAllowedOAuthScope({
30 value: "orchestration:read relay:write",
31 allowedScopes: new Set(["orchestration:read", "access:write"] as const),
32 }),
33 ).toBeNull();
34 });
35});