mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
jws encryption support (#74)
This commit is contained in:
@@ -133,10 +133,7 @@ describe("EncryptedAccessTokens", () => {
|
||||
describe("encrypt and decrypt", () => {
|
||||
it("should be able to round trip the token", () => {
|
||||
const authToken = `the token - ${uuid()}`;
|
||||
const hash = {
|
||||
encryptedData: "the encrypted token",
|
||||
iv: "vi",
|
||||
};
|
||||
const hash = "the encrypted token";
|
||||
|
||||
encryption.encrypt.mockReturnValue(hash);
|
||||
encryption.decrypt.mockReturnValue(authToken);
|
||||
@@ -144,9 +141,7 @@ describe("EncryptedAccessTokens", () => {
|
||||
const accessToken = accessTokens.mint(authToken);
|
||||
|
||||
expect(accessToken).not.toContain(authToken);
|
||||
expect(accessToken).toEqual(
|
||||
Buffer.from(JSON.stringify(hash)).toString("base64")
|
||||
);
|
||||
expect(accessToken).toEqual(hash);
|
||||
|
||||
expect(accessTokens.authTokenFor(accessToken)).toEqual(authToken);
|
||||
|
||||
@@ -157,17 +152,12 @@ describe("EncryptedAccessTokens", () => {
|
||||
|
||||
describe("when the token is a valid Hash but doesnt decrypt", () => {
|
||||
it("should return undefined", () => {
|
||||
const hash = {
|
||||
encryptedData: "valid hash",
|
||||
iv: "vi",
|
||||
};
|
||||
const hash = "valid hash";
|
||||
encryption.decrypt.mockImplementation(() => {
|
||||
throw "Boooooom decryption failed!!!";
|
||||
});
|
||||
expect(
|
||||
accessTokens.authTokenFor(
|
||||
Buffer.from(JSON.stringify(hash)).toString("base64")
|
||||
)
|
||||
accessTokens.authTokenFor(hash)
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,45 @@
|
||||
import encryption from '../src/encryption';
|
||||
|
||||
describe("encrypt", () => {
|
||||
const e = encryption("secret squirrel");
|
||||
import { cryptoEncryption, jwsEncryption } from '../src/encryption';
|
||||
|
||||
describe("jwsEncryption", () => {
|
||||
it("can encrypt and decrypt", () => {
|
||||
const e = jwsEncryption("secret squirrel");
|
||||
|
||||
const value = "bobs your uncle"
|
||||
const hash = e.encrypt(value)
|
||||
expect(hash.encryptedData).not.toEqual(value);
|
||||
expect(hash).not.toContain(value);
|
||||
expect(e.decrypt(hash)).toEqual(value);
|
||||
});
|
||||
})
|
||||
|
||||
it("returns different values for different secrets", () => {
|
||||
const e1 = jwsEncryption("e1");
|
||||
const e2 = jwsEncryption("e2");
|
||||
|
||||
const value = "bobs your uncle"
|
||||
const h1 = e1.encrypt(value)
|
||||
const h2 = e2.encrypt(value)
|
||||
|
||||
expect(h1).not.toEqual(h2);
|
||||
});
|
||||
})
|
||||
|
||||
describe("cryptoEncryption", () => {
|
||||
it("can encrypt and decrypt", () => {
|
||||
const e = cryptoEncryption("secret squirrel");
|
||||
|
||||
const value = "bobs your uncle"
|
||||
const hash = e.encrypt(value)
|
||||
expect(hash).not.toContain(value);
|
||||
expect(e.decrypt(hash)).toEqual(value);
|
||||
});
|
||||
|
||||
it("returns different values for different secrets", () => {
|
||||
const e1 = cryptoEncryption("e1");
|
||||
const e2 = cryptoEncryption("e2");
|
||||
|
||||
const value = "bobs your uncle"
|
||||
const h1 = e1.encrypt(value)
|
||||
const h2 = e2.encrypt(value)
|
||||
|
||||
expect(h1).not.toEqual(h2);
|
||||
});
|
||||
})
|
||||
|
||||
@@ -55,7 +55,7 @@ import { AccessTokens } from "../src/access_tokens";
|
||||
import dayjs from "dayjs";
|
||||
import url, { URLBuilder } from "../src/url_builder";
|
||||
import { iconForGenre } from "../src/icon";
|
||||
import { jwtTokenSigner } from "../src/encryption";
|
||||
import { jwtSigner } from "../src/encryption";
|
||||
|
||||
const parseXML = (value: string) => new DOMParserImpl().parseFromString(value);
|
||||
|
||||
@@ -597,7 +597,7 @@ describe("wsdl api", () => {
|
||||
|
||||
[bonobUrlWithoutContextPath, bonobUrlWithContextPath].forEach((bonobUrl) => {
|
||||
describe(`bonob with url ${bonobUrl}`, () => {
|
||||
const tokenSigner = jwtTokenSigner(`smapi-test-secret-${uuid()}`);
|
||||
const tokenSigner = jwtSigner(`smapi-test-secret-${uuid()}`);
|
||||
const jwtSign = tokenSigner.sign;
|
||||
|
||||
const authToken = `authToken-${uuid()}`;
|
||||
|
||||
Reference in New Issue
Block a user