Password hashing library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

82 lines
2.8 KiB

import { expect, it } from "./deps.test.ts";
import { Hasher, HashOutputMode } from "./hashing.ts";
const assertEquals = (a: any, b: any) => expect(a).toEqual(b);
it("hasher", () => {
assertEquals(Hasher.tagFromURL(""), null);
assertEquals(Hasher.tagFromURL("http://"), null);
assertEquals(Hasher.tagFromURL("http://localhost"), "localhost");
assertEquals(Hasher.tagFromURL("http://localhost/"), "localhost");
assertEquals(Hasher.tagFromURL("http://localhost:22000"), "localhost");
assertEquals(Hasher.tagFromURL("http://localhost:22000/"), "localhost");
assertEquals(
Hasher.tagFromURL("http://localhost:22000/index.html"),
"localhost",
);
assertEquals(Hasher.tagFromURL("http://website.net"), "website");
assertEquals(Hasher.tagFromURL("http://website.net/"), "website");
assertEquals(Hasher.tagFromURL("http://website.co.uk"), "website");
assertEquals(Hasher.tagFromURL("http://website.co.jp/"), "website");
assertEquals(Hasher.tagFromURL("http://www.bigpage.com"), "bigpage");
assertEquals(Hasher.tagFromURL("https://www.securesite.com"), "securesite");
assertEquals(
Hasher.tagFromURL("http://domain.bigsite.com/page/path/?a=5"),
"bigsite",
);
assertEquals(
Hasher.tagFromURL("https://domains.securebigsite.com/?a=5&c=3"),
"securebigsite",
);
let hasher = new Hasher(
"5DB6DAF0-8F1D-4FB2-9845-F3E2390FB5BB",
"http://www.test.com/",
);
assertEquals(
hasher.getHash(
"password",
"test",
{ length: 12, mode: HashOutputMode.ALNUM },
),
"JNiDEjUp0oKs",
);
assertEquals(
hasher.getHash(
"password",
"test",
{ length: 16, mode: HashOutputMode.ALNUM },
),
"JNiDEjUp0oKsDFLi",
);
assertEquals(
hasher.getHash(
"password",
"test",
{ length: 12, mode: HashOutputMode.DIGITS },
),
"152463290522",
);
assertEquals(
hasher.getHash(
"password",
"test",
{ length: 12, mode: HashOutputMode.CHARS },
),
"JNi/'jUp0oKs",
);
assertEquals(hasher.tryHashing("password"), null);
assertEquals(hasher.tryHashing("password#"), "JNiDEjUp0oKs");
assertEquals(hasher.tryHashing("password@othersite#"), "D7w1bBtgYcAT");
assertEquals(hasher.tryHashing("password@othersite~d#"), "576163306621");
assertEquals(hasher.tryHashing("password@othersite~8#"), "D7w1bBtg");
assertEquals(hasher.tryHashing("password@othersite~14c#"), "DPw1bBtgYcAT!P");
assertEquals(hasher.tryHashing("password~c#"), "JNi/'jUp0oKs");
assertEquals(hasher.tryHashing("password~4#"), "JDe4");
assertEquals(hasher.tryHashing("password~10d#"), "1524632905");
hasher = new Hasher("5DB6DAF0-8F1D-4FB2-9845-F3E2390FB5BB");
assertEquals(hasher.tryHashing("password#"), null);
assertEquals(hasher.tryHashing("password@test#"), "JNiDEjUp0oKs");
});