2023-08-01 22:45:08 +01:00
|
|
|
import { getDomainFromEmail } from "../../src/utils/sanitizer.utils";
|
2023-08-01 23:09:20 +01:00
|
|
|
import { removeNonNumeric } from "../../src/utils/sanitizer.utils";
|
2023-09-28 20:02:58 +01:00
|
|
|
import { removeNonAlpha } from "../../src/utils/sanitizer.utils";
|
|
|
|
import { removeNonAlphanumeric } from "../../src/utils/sanitizer.utils";
|
2023-08-01 21:49:00 +01:00
|
|
|
|
2023-08-26 00:38:26 +01:00
|
|
|
describe("Sanitize Email", () => {
|
2023-08-01 22:45:08 +01:00
|
|
|
const inputs = [
|
|
|
|
"this+is+an-_email@example.com",
|
|
|
|
'"unusual email"@example.com',
|
|
|
|
"(brackets)addr@example.com",
|
|
|
|
"I%Have{Special}%Characters@example.com",
|
|
|
|
"Basic.address@example.com",
|
2023-08-26 00:38:26 +01:00
|
|
|
`"very.(),:;<>[]\".VERY.\"very\ \"very\".unusual"@example.com`,
|
2023-09-24 20:46:33 +01:00
|
|
|
"THIS_EMAIL_CONTAINS_CAPITALISED_DOMAIN@EXAMPLE.COM",
|
2023-08-26 00:38:26 +01:00
|
|
|
];
|
|
|
|
const expectedOutput = "example.com";
|
2023-08-01 22:45:08 +01:00
|
|
|
for (const addr of inputs) {
|
|
|
|
test(`Should return only domain: ${addr}`, () => {
|
|
|
|
expect(getDomainFromEmail(addr)).toEqual(expectedOutput);
|
2023-08-26 00:38:26 +01:00
|
|
|
});
|
2023-08-01 22:45:08 +01:00
|
|
|
}
|
|
|
|
});
|
2023-08-01 23:09:20 +01:00
|
|
|
|
2023-08-26 00:38:26 +01:00
|
|
|
describe("Remove non-numeric", () => {
|
|
|
|
const inputs = ["abc123", "<%43)($£@:}jfkd4"];
|
|
|
|
const expectedOutputs = ["123", "434"];
|
2023-08-01 23:09:20 +01:00
|
|
|
for (const key in inputs) {
|
|
|
|
const input = inputs[key];
|
|
|
|
const desired = expectedOutputs[key];
|
|
|
|
test(`Should return only numbers: ${key}`, () => {
|
|
|
|
expect(removeNonNumeric(input)).toEqual(desired);
|
2023-08-26 00:38:26 +01:00
|
|
|
});
|
2023-08-01 23:09:20 +01:00
|
|
|
}
|
2023-08-26 00:38:26 +01:00
|
|
|
});
|
2023-09-28 20:02:58 +01:00
|
|
|
|
|
|
|
describe("Remove non-Alpha", () => {
|
|
|
|
const inputs = ["DROP/*comment*/sampletable", "10; DROP TABLE members /*"];
|
|
|
|
const outputs = ["DROPcommentsampletable", "DROPTABLEmembers"];
|
|
|
|
for (const key in inputs) {
|
|
|
|
const input = inputs[key];
|
|
|
|
const desired = outputs[key];
|
|
|
|
test(`Should return with only letters: ${key}`, () => {
|
|
|
|
expect(removeNonAlpha(input)).toEqual(desired);
|
2023-09-28 21:48:27 +01:00
|
|
|
});
|
2023-09-28 20:02:58 +01:00
|
|
|
}
|
2023-09-28 21:48:27 +01:00
|
|
|
});
|
2023-09-28 20:02:58 +01:00
|
|
|
|
|
|
|
describe("Remove non-alphanumeric", () => {
|
2023-09-28 21:48:27 +01:00
|
|
|
const inputs = [
|
|
|
|
"DROP/*comment*/sampletable",
|
|
|
|
"10; DROP TABLE members /*",
|
|
|
|
"1F44",
|
|
|
|
];
|
2023-09-28 20:02:58 +01:00
|
|
|
const outputs = ["DROPcommentsampletable", "10DROPTABLEmembers", "1F44"];
|
|
|
|
for (const key in inputs) {
|
|
|
|
const input = inputs[key];
|
|
|
|
const desired = outputs[key];
|
|
|
|
test(`Should return with only alphanumeric: ${key}`, () => {
|
|
|
|
expect(removeNonAlphanumeric(input)).toEqual(desired);
|
2023-09-28 21:48:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|