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/backend/misc.test.ts
Views: 687
import { is_valid_username } from "./misc";12describe("checking that a user's first or last name is valid", () => {3it("works for usual valid names", () => {4expect(is_valid_username("harald")).toBe(undefined);5expect(is_valid_username("ABC FOO-BAR")).toBe(undefined);6// DNS-like substrings easily trigger a violation. these are fine, though7// this was relaxed in commit cafbf9c900f9178expect(is_valid_username("is.test.ok")).not.toBe(undefined);9return expect(is_valid_username("is.a.test")).not.toBe(undefined);10});1112it("blocks suspicious names", () => {13expect(is_valid_username("OPEN http://foo.com")).not.toBe(undefined);14expect(is_valid_username("https://earn-money.cc is good")).not.toBe(15undefined16);17return expect(is_valid_username("OPEN mailto:[email protected]")).not.toBe(18undefined19);20});2122it("is not fooled to easily", () => {23expect(is_valid_username("OPEN hTTp://foo.com")).not.toBe(undefined);24expect(is_valid_username("httpS://earn-money.cc is good")).not.toBe(25undefined26);27expect(is_valid_username("OPEN MAILTO:[email protected]")).not.toBe(undefined);28expect(is_valid_username("test.account.dot")).toContain("test.account.dot");29expect(is_valid_username("no spam EARN-A-LOT-OF.money Now")).toContain(30".money"31);32return expect(is_valid_username("spam abc.co earn")).toContain(".co");33});34});3536import { getUid } from "./misc";37describe("get the UNIX uid associated to a project_id (used on cocalc-docker)", () => {38it("throws an error when input is not a valid uuid", () => {39expect(() => {40getUid("foobar");41}).toThrow();42});4344it("returns a valid number on a valid uuid", () => {45const uid = getUid("812abe34-a382-4bd1-9071-29b6f4334f03");46expect(uid).toBeGreaterThan(65537);47expect(uid).toBeLessThan(2 ** 29);48});49});505152