CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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