UNPKG

@teamsight/flight

Version:

Lambda life cycles

55 lines 2.75 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const TypeMoq = require("typemoq"); const json_web_token_manager_1 = require("./json-web-token-manager"); describe("jwt", () => { let tokenStore; let jwt; beforeEach(() => __awaiter(this, void 0, void 0, function* () { tokenStore = TypeMoq.Mock.ofType(); jwt = new json_web_token_manager_1.JsonWebTokenManager(tokenStore.object); })); it("Create and Process correctly", () => __awaiter(this, void 0, void 0, function* () { const opts = { tokenId: "tokenId", secret: "tokenSecret", audience: "me", expiresInHours: 1, payload: { hello: "world" }, subject: "user123" }; tokenStore .setup(x => x.getSecretForId(TypeMoq.It.isValue(opts.tokenId))) .returns(() => Promise.resolve(opts.secret)); const token = jwt.create(opts); const processed = yield jwt.process(token, opts.audience); processed.should.match({ sub: opts.subject, hello: "world", header: { kid: "tokenId" } }); })); it("Create server", () => __awaiter(this, void 0, void 0, function* () { const token = jwt.createServer(); token.length.should.be.greaterThan(1); })); it.skip("Process", () => __awaiter(this, void 0, void 0, function* () { const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkFQUF9TRUNSRVQifQ.eyJzZXJ2aWNlIjoidGVhbXNpZ2h0Iiwib3duZXJJZCI6IjViODIxZjc1YjQ4ZmJhNjFiZjAzNDdlZSIsIm9yZ0lkIjoiNWI4MjFmNzViNDhmYmFmY2YyMDM0N2VmIiwiaWF0IjoxNTM1MjU0Mzg5LCJleHAiOjE1MzU4NTkxODksImF1ZCI6InRzIiwic3ViIjoiNWI4MjFmNzViNDhmYmE2MWJmMDM0N2VlIn0.p6hkXO-W8GqdA5k7p8OeTvTp6i-bGU2mGmC6d7xs_rc"; tokenStore .setup(x => x.getSecretForId(TypeMoq.It.isValue("APP_SECRET"))) .returns(() => Promise.resolve("4b87b7ff8b3349649d0001178e4f0753")); const result = yield jwt.process(token, "ts"); console.log(result); })); }); //# sourceMappingURL=json-web-token-manager.test.js.map