Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/backend/sha1.test.ts
1447 views
1
import { sha1, sha1base64, uuidsha1 } from "./sha1";
2
import * as misc from "@cocalc/util/misc";
3
4
const cocalc = "CoCalc";
5
const hash = "c898c97dca68742a5a6331f9fa0ca02483cbfd25";
6
const uuid = "c898c97d-ca68-4742-a5a6-331f9fa0ca02";
7
8
describe("compute some sha1 hashes", () => {
9
// This is mainly for long term backwards compatibility
10
it("SageMathCloud/string", () => {
11
expect(sha1("SageMathCloud")).toBe(
12
"31acd8ca91346abcf6a49d2b1d88333f439d57a6",
13
);
14
});
15
16
it("CoCalc/string", () => {
17
expect(sha1(cocalc)).toBe(hash);
18
});
19
20
it("CoCalc/Buffer", () => {
21
expect(sha1(Buffer.from(cocalc))).toBe(hash);
22
});
23
});
24
25
describe("UUIDs", () => {
26
it("CoCalc/string", () => {
27
expect(uuidsha1(cocalc)).toBe(uuid);
28
});
29
30
it("CoCalc/Buffer", () => {
31
expect(uuidsha1(Buffer.from(cocalc))).toBe(uuid);
32
});
33
});
34
35
describe("compare this nodejs implementation to the pure javascript implementation", () => {
36
it("CoCalc/string", () => {
37
expect(sha1(cocalc)).toBe(misc.sha1(cocalc));
38
});
39
it("hash", () => {
40
expect(sha1(hash)).toBe(misc.sha1(hash));
41
});
42
it("uuid", () => {
43
expect(sha1(uuid)).toBe(misc.sha1(uuid));
44
});
45
});
46
47
describe("base64: compare this nodejs implementation to the pure javascript implementation", () => {
48
it("CoCalc/string", () => {
49
expect(sha1base64(cocalc)).toBe(misc.sha1base64(cocalc));
50
});
51
it("hash", () => {
52
expect(sha1base64(hash)).toBe(misc.sha1base64(hash));
53
});
54
it("uuid", () => {
55
expect(sha1base64(uuid)).toBe(misc.sha1base64(uuid));
56
});
57
});
58
59