From c2ea1015f6634cd306d764df76f684a6d08e1efb Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Thu, 22 Apr 2021 09:54:18 -0700 Subject: [PATCH 1/2] test: throw helpful error when `appId` or `privateKey` is set to a falsy value --- test/deprecations.test.ts | 2 +- test/index.test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/test/deprecations.test.ts b/test/deprecations.test.ts index bc4488f3a..04f6c2f13 100644 --- a/test/deprecations.test.ts +++ b/test/deprecations.test.ts @@ -33,7 +33,7 @@ describe("deprecations", () => { const warn = jest.fn(); const auth = createAppAuth({ appId: "1", - privateKey: "", + privateKey: "1", clientId: "12345678901234567890", clientSecret: "1234567890123456789012345678901234567890", log: { warn }, diff --git a/test/index.test.ts b/test/index.test.ts index a6999ec99..9b3cfe125 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -2135,3 +2135,33 @@ test("factory auth option", async () => { }) ); }); + +it("throws helpful error if `appId` is not set properly (#184)", async () => { + expect(() => { + createAppAuth({ + // @ts-ignore + appId: undefined, + privateKey: PRIVATE_KEY, + }); + }).toThrowError("[@octokit/auth-app] appId option is required"); +}); + +it("throws helpful error if `privateKey` is not set properly (#184)", async () => { + expect(() => { + createAppAuth({ + appId: APP_ID, + // @ts-ignore + privateKey: undefined, + }); + }).toThrowError("[@octokit/auth-app] privateKey option is required"); +}); + +it("throws helpful error if `installationId` is set to a falsy value in createAppAuth() (#184)", async () => { + expect(() => { + createAppAuth({ + appId: APP_ID, + privateKey: PRIVATE_KEY, + installationId: "", + }); + }).toThrowError("[@octokit/auth-app] installationId is set to a falsy value"); +}); From c3121f97b8647957457b7efe63c1928b2da2e3e0 Mon Sep 17 00:00:00 2001 From: Gregor Martynus <39992+gr2m@users.noreply.github.com> Date: Thu, 22 Apr 2021 09:56:07 -0700 Subject: [PATCH 2/2] feat: throw helpful error when `appId` or `privateKey` is set to a falsy value --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 602f73897..47ebf090f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,18 @@ export { export const createAppAuth: StrategyInterface = function createAppAuth( options: StrategyOptions ) { + if (!options.appId) { + throw new Error("[@octokit/auth-app] appId option is required"); + } + if (!options.privateKey) { + throw new Error("[@octokit/auth-app] privateKey option is required"); + } + if ("installationId" in options && !options.installationId) { + throw new Error( + "[@octokit/auth-app] installationId is set to a falsy value" + ); + } + const log = Object.assign( { warn: console.warn.bind(console),