Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/db-schema/name-rules.test.ts
Views: 687
// to access the non-exported RESERVED object1process.env["NODE_DEV"] = "TEST";23import * as NR from "@cocalc/util/db-schema/name-rules";45describe("Check RESERVED", () => {6const { RESERVED } = NR as any;7const { isReserved } = NR;89test("reserved names", () => {10expect(RESERVED.has("admin")).toBe(true);11expect(isReserved("admin")).toBe(true);12});1314it.each(Array.from(RESERVED))(15"'%s' must be lowercase and has no spaces",16(name: string) => {17expect(name).not.toEqual("");18expect(name.indexOf(" ")).toBe(-1);19expect(name.toLowerCase()).toBe(name);20// entire name must be of a-z,A-Z,0-9,_,. or -21expect(name).toMatch(/^[a-z\d\.\-_]+$/);22},23);24});2526test("checkAccountName", () => {27const { checkAccountName } = NR;2829expect(() =>30checkAccountName("3b38dd9c-f8bf-48c0-9d26-7cad4bac08eb"),31).toThrow(/.*UUID.*/);3233expect(() => checkAccountName("foo--bar")).toThrow(/.*hyphens.*/);3435// not more than 39 characters36expect(() =>37checkAccountName("1234567890123456789012345678901234567890"),38).toThrow(/.*39.*/);3940// not less than 1 character41expect(() => checkAccountName("")).toThrow(/.*1.*/);4243// not start with hyphen44expect(() => checkAccountName("-foo")).toThrow(/.*hyphen.*/);4546// not be "compute"47expect(() => checkAccountName("compute")).toThrow(/.*reserved.*/);48});4950test("checkProjectName", () => {51const { checkProjectName } = NR;5253// at most 100 characters54expect(() =>55checkProjectName(56"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",57),58).toThrow(/.*100.*/);5960// not less than 1 character61expect(() => checkProjectName("")).toThrow(/.*1.*/);6263// not start with hyphen64expect(() => checkProjectName("-foo")).toThrow(/.*hyphen.*/);6566// name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces67expect(() => checkProjectName("foo bar")).toThrow(/.*spaces.*/);68expect(() => checkProjectName("foo_bar")).toThrow(/.*spaces.*/);69expect(() => checkProjectName("foo-bar")).not.toThrow(/.*spaces.*/);70expect(() => checkProjectName("foo.bar")).not.toThrow(/.*spaces.*/);7172// allow v4 UUID73expect(() =>74checkProjectName("3b38dd9c-f8bf-48c0-9d26-7cad4bac08eb"),75).not.toThrow(/.*UUID.*/);76});7778test("checkPublicPathName", () => {79const { checkPublicPathName } = NR;8081// at most 100 characters82expect(() =>83checkPublicPathName(84"12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",85),86).toThrow(/.*100.*/);8788// not less than 1 character89expect(() => checkPublicPathName("")).toThrow(/.*1.*/);9091// not start with hyphen92expect(() => checkPublicPathName("-foo")).toThrow(/.*hyphen.*/);9394// name must contain only a-z,A-Z,0-9, . or -, and not start with hyphen or have spaces95expect(() => checkPublicPathName("foo bar")).toThrow(/.*spaces.*/);96expect(() => checkPublicPathName("foo_bar")).toThrow(/.*spaces.*/);97expect(() => checkPublicPathName("foo-bar")).not.toThrow(/.*spaces.*/);98expect(() => checkPublicPathName("foo.bar")).not.toThrow(/.*spaces.*/);99100// allow UUID101expect(() =>102checkPublicPathName("3b38dd9c-f8bf-48c0-9d26-7cad4bac08eb"),103).not.toThrow(/.*UUID.*/);104});105106107