Commit d5631a21 authored by David Burke's avatar David Burke

fix tests

parent c5e34e5c
Pipeline #37198457 failed with stage
in 6 minutes and 8 seconds
......@@ -4054,7 +4054,6 @@
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz",
"integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=",
"dev": true,
"requires": {
"babel-runtime": "^6.26.0",
"core-js": "^2.5.0",
......@@ -4064,8 +4063,7 @@
"regenerator-runtime": {
"version": "0.10.5",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz",
"integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=",
"dev": true
"integrity": "sha1-M2w+/BIgrc7dosn6tntaeVWjNlg="
}
}
},
......@@ -4104,7 +4102,6 @@
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"dev": true,
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
......@@ -7873,6 +7870,44 @@
"pend": "~1.2.0"
}
},
"fetch-mock": {
"version": "7.2.5",
"resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-7.2.5.tgz",
"integrity": "sha512-ZdlNxw2xFE2VuGikqWYBcshbfMtWM0k7zWevYgjrFuTiJ1+S7+xjRMxDG1cy45xkpEcqzZAAeqL+uDL5qLZV7g==",
"requires": {
"babel-polyfill": "^6.26.0",
"glob-to-regexp": "^0.4.0",
"path-to-regexp": "^2.2.1",
"whatwg-url": "^6.5.0"
},
"dependencies": {
"glob-to-regexp": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.0.tgz",
"integrity": "sha512-fyPCII4vn9Gvjq2U/oDAfP433aiE64cyP/CJjRJcpVGjqqNdioUYn9+r0cSzT1XPwmGAHuTT7iv+rQT8u/YHKQ=="
},
"path-to-regexp": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz",
"integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w=="
},
"webidl-conversions": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
"integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg=="
},
"whatwg-url": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz",
"integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==",
"requires": {
"lodash.sortby": "^4.7.0",
"tr46": "^1.0.1",
"webidl-conversions": "^4.0.2"
}
}
}
},
"figgy-pudding": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz",
......@@ -8290,14 +8325,12 @@
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"optional": true
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
......@@ -8312,20 +8345,17 @@
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=",
"optional": true
"integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"optional": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"console-control-strings": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz",
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=",
"optional": true
"integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4="
},
"core-util-is": {
"version": "1.0.2",
......@@ -8442,8 +8472,7 @@
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"optional": true
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ini": {
"version": "1.3.5",
......@@ -8455,7 +8484,6 @@
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
......@@ -8470,7 +8498,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
......@@ -8478,14 +8505,12 @@
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"optional": true
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"minipass": {
"version": "2.2.4",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz",
"integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==",
"optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
......@@ -8504,7 +8529,6 @@
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"optional": true,
"requires": {
"minimist": "0.0.8"
}
......@@ -8585,8 +8609,7 @@
"number-is-nan": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=",
"optional": true
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
},
"object-assign": {
"version": "4.1.1",
......@@ -8598,7 +8621,6 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"optional": true,
"requires": {
"wrappy": "1"
}
......@@ -8720,7 +8742,6 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
......@@ -11768,8 +11789,7 @@
"lodash.sortby": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=",
"dev": true
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg="
},
"lodash.tail": {
"version": "4.1.1",
......@@ -15491,8 +15511,7 @@
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==",
"dev": true
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg=="
},
"regenerator-transform": {
"version": "0.13.3",
......@@ -18274,7 +18293,6 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz",
"integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=",
"dev": true,
"requires": {
"punycode": "^2.1.0"
},
......@@ -18282,8 +18300,7 @@
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
}
}
},
......
......@@ -165,7 +165,10 @@ export const getLoginErrorMessage = createSelector(
selectLoginState,
fromLogin.getErrorMessage
);
export const getLoginForm = createSelector(selectLoginState, fromLogin.getForm);
export const getLoginForm = createSelector(
selectLoginState,
fromLogin.getForm
);
export const selectAuthState = createSelector(
selectAccountState,
......
......@@ -6,7 +6,7 @@ import {
import { AuthInterceptor } from "./auth.interceptor";
import { HTTP_INTERCEPTORS, HttpClient } from "@angular/common/http";
import { StoreModule, Store } from "@ngrx/store";
import { reducers } from "~/app/account/account.reducer";
import { reducers } from "../account/account.reducer";
import { of } from "rxjs";
describe(`AuthHttpInterceptor`, () => {
......@@ -33,7 +33,7 @@ describe(`AuthHttpInterceptor`, () => {
});
store = TestBed.get(Store);
spyOn(store, "select").and.returnValue(of(token));
spyOn(store, "pipe").and.returnValue(of(token));
interceptor = TestBed.get(HTTP_INTERCEPTORS);
httpMock = TestBed.get(HttpTestingController);
http = TestBed.get(HttpClient);
......
This diff is collapsed.
import * as sodium from "libsodium-wrappers";
import { HASH_MEMORY } from "./constants";
import {
authenticatedEncryption,
decrypt,
decryptPrivateKey,
encrypt,
encryptPrivateKey,
fromBase64,
fromUTF8,
generateKeys,
hashPassword,
makeRandomTypableString,
rsaDecrypt,
rsaEncrypt,
toBase64,
toUTF8,
verifyOwner,
authenticatedEncryption,
decrypt,
decryptPrivateKey,
encrypt,
encryptPrivateKey,
fromBase64,
fromUTF8,
generateKeys,
hashPassword,
makeRandomTypableString,
rsaDecrypt,
rsaEncrypt,
toBase64,
toUTF8,
verifyOwner
} from "./crypto";
describe("crypto can", () => {
beforeEach(async () => {
await sodium.ready;
});
// Requires in browser usage, so disabled in CI
xit("Uses wasm", async () => {
expect((sodium as any).libsodium.usingWasm).toBe(true);
});
it("makes random string", () => {
const generated = makeRandomTypableString();
expect(generated).toBeTruthy();
expect(generated.indexOf("undefined")).toBe(-1);
});
// These boring tests without expects are nice because they fail sometimes when libsodium.js breaks.
it("test crypto_box_keypair", async () => {
sodium.crypto_box_keypair();
});
it("test hash", async () => {
const password = "hunter2";
const salt = new Uint8Array([88, 240, 185, 66, 195, 101, 160, 138, 137, 78, 1, 2, 3, 4, 5, 6]);
const hash = sodium.crypto_pwhash(
sodium.crypto_box_SEEDBYTES,
password,
salt,
sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
HASH_MEMORY / 2,
sodium.crypto_pwhash_ALG_DEFAULT,
);
});
it("test hash speed", async () => {
const password = "hunter2";
const salt = new Uint8Array([88, 240, 185, 66, 195, 101, 160, 138, 137, 78, 1, 2, 3, 4, 5, 6]);
const t0 = performance.now();
await hashPassword(password, salt, 2);
const t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
});
it("test base64", () => {
const testB64 = "2A28PjsDW/WpQqMXPLTIkL99VwnofGRqNL7wdJrzUyo=";
const result = sodium.from_base64(testB64, 1);
});
it("make and export RSA key", () => {
const keys = generateKeys();
expect(toBase64(keys.privateKey).length).toBe(44);
expect(toBase64(keys.publicKey).length).toBe(44);
});
it("export and import private key with password", () => {
const privateB64 = "2A28PjsDW/WpQqMXPLTIkL99VwnofGRqNL7wdJrzUyo=";
const password = "hunter2";
const encr = encryptPrivateKey(fromBase64(privateB64), password);
const decr = decryptPrivateKey(encr, password);
expect(privateB64).toEqual(toBase64(decr));
});
it("hash a password", () => {
const password = "hunter2";
const salt = new Uint8Array([88, 240, 185, 66, 195, 101, 160, 138, 137, 78, 1, 2, 3, 4, 5, 6]);
const hash = hashPassword(password, salt);
expect(hash[0]).toEqual(49);
});
it("encrypt private key with password", () => {
const password = "hunter2";
const keys = generateKeys();
const encr = encryptPrivateKey(keys.privateKey, password);
expect(encr).toBeTruthy();
});
it("RSA Encrypt and Decrypt", () => {
const keys = generateKeys();
const message = "test Ơ";
const ciphertext = rsaEncrypt(keys.publicKey, fromUTF8(message));
expect(ciphertext).toBeTruthy();
expect(toBase64(ciphertext)).not.toEqual(message);
const decryptedMessage = rsaDecrypt(keys.publicKey, keys.privateKey, ciphertext);
expect(toUTF8(decryptedMessage)).toEqual(message);
});
it("Prove identity", () => {
const keysBob = generateKeys();
const keysAlice = generateKeys();
const message = sodium.from_string("bleh");
const ciphertext = authenticatedEncryption(keysBob.publicKey, keysAlice.privateKey, message);
// Incorrect usage, expect failure.
let verified = verifyOwner(keysBob.publicKey, keysBob.privateKey, ciphertext);
expect(verified).toBeFalsy();
verified = verifyOwner(keysAlice.publicKey, keysBob.privateKey, ciphertext);
expect(verified).toBeTruthy();
});
it("Encrypt and decrypt text", () => {
const key = Buffer.from("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed", "hex");
const message = "hell dfd";
const ciphertext = encrypt(key, fromUTF8(message));
expect(toBase64(ciphertext)).not.toEqual(message);
const decryptedMessage = decrypt(key, ciphertext);
expect(toUTF8(decryptedMessage)).toBe(message);
});
beforeEach(async () => {
await sodium.ready;
});
// Requires in browser usage, so disabled in CI
xit("Uses wasm", async () => {
expect((sodium as any).libsodium.usingWasm).toBe(true);
});
it("makes random string", () => {
const generated = makeRandomTypableString();
expect(generated).toBeTruthy();
expect(generated.indexOf("undefined")).toBe(-1);
});
// These boring tests without expects are nice because they fail sometimes when libsodium.js breaks.
it("test crypto_box_keypair", async () => {
sodium.crypto_box_keypair();
});
it("test hash", async () => {
const password = "hunter2";
const salt = new Uint8Array([
88,
240,
185,
66,
195,
101,
160,
138,
137,
78,
1,
2,
3,
4,
5,
6
]);
sodium.crypto_pwhash(
sodium.crypto_box_SEEDBYTES,
password,
salt,
sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
HASH_MEMORY / 2,
sodium.crypto_pwhash_ALG_DEFAULT
);
});
it("test hash speed", async () => {
const password = "hunter2";
const salt = new Uint8Array([
88,
240,
185,
66,
195,
101,
160,
138,
137,
78,
1,
2,
3,
4,
5,
6
]);
const t0 = performance.now();
await hashPassword(password, salt, 2);
const t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
});
it("test base64", () => {
const testB64 = "2A28PjsDW/WpQqMXPLTIkL99VwnofGRqNL7wdJrzUyo=";
sodium.from_base64(testB64, 1);
});
it("make and export RSA key", () => {
const keys = generateKeys();
expect(toBase64(keys.privateKey).length).toBe(44);
expect(toBase64(keys.publicKey).length).toBe(44);
});
it("export and import private key with password", () => {
const privateB64 = "2A28PjsDW/WpQqMXPLTIkL99VwnofGRqNL7wdJrzUyo=";
const password = "hunter2";
const encr = encryptPrivateKey(fromBase64(privateB64), password);
const decr = decryptPrivateKey(encr, password);
expect(privateB64).toEqual(toBase64(decr));
});
it("hash a password", () => {
const password = "hunter2";
const salt = new Uint8Array([
88,
240,
185,
66,
195,
101,
160,
138,
137,
78,
1,
2,
3,
4,
5,
6
]);
const hash = hashPassword(password, salt);
expect(hash[0]).toEqual(49);
});
it("encrypt private key with password", () => {
const password = "hunter2";
const keys = generateKeys();
const encr = encryptPrivateKey(keys.privateKey, password);
expect(encr).toBeTruthy();
});
it("RSA Encrypt and Decrypt", () => {
const keys = generateKeys();
const message = "test Ơ";
const ciphertext = rsaEncrypt(keys.publicKey, fromUTF8(message));
expect(ciphertext).toBeTruthy();
expect(toBase64(ciphertext)).not.toEqual(message);
const decryptedMessage = rsaDecrypt(
keys.publicKey,
keys.privateKey,
ciphertext
);
expect(toUTF8(decryptedMessage)).toEqual(message);
});
it("Prove identity", () => {
const keysBob = generateKeys();
const keysAlice = generateKeys();
const message = sodium.from_string("bleh");
const ciphertext = authenticatedEncryption(
keysBob.publicKey,
keysAlice.privateKey,
message
);
// Incorrect usage, expect failure.
let verified = verifyOwner(
keysBob.publicKey,
keysBob.privateKey,
ciphertext
);
expect(verified).toBeFalsy();
verified = verifyOwner(keysAlice.publicKey, keysBob.privateKey, ciphertext);
expect(verified).toBeTruthy();
});
it("Encrypt and decrypt text", () => {
const key = Buffer.from(
"724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed",
"hex"
);
const message = "hell dfd";
const ciphertext = encrypt(key, fromUTF8(message));
expect(toBase64(ciphertext)).not.toEqual(message);
const decryptedMessage = decrypt(key, ciphertext);
expect(toUTF8(decryptedMessage)).toBe(message);
});
});
......@@ -19,5 +19,10 @@
"include": [
"**/*.spec.ts",
"**/*.d.ts"
],
"exclude": [
"**/*.tns.ts",
"**/*.android.ts",
"**/*.ios.ts",
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment