From 30785b5ff0c2bcb2a552c07eec91a253c0517ae2 Mon Sep 17 00:00:00 2001 From: Joe Krill Date: Wed, 28 Sep 2022 13:16:25 -0400 Subject: [PATCH] fix: throw helpful error when `appId` is not numeric (#402) --- src/index.ts | 5 +++++ test/index.test.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index e433438c..29846f02 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,11 @@ export function createAppAuth(options: StrategyOptions): AuthInterface { if (!options.appId) { throw new Error("[@octokit/auth-app] appId option is required"); } + if (!Number.isFinite(+options.appId)) { + throw new Error( + "[@octokit/auth-app] appId option must be a number or numeric string" + ); + } if (!options.privateKey) { throw new Error("[@octokit/auth-app] privateKey option is required"); } diff --git a/test/index.test.ts b/test/index.test.ts index ce9bab76..7453ae12 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -2343,7 +2343,7 @@ test("Do not intercept auth.hook(request, 'POST https://github.com/login/oauth/a }); }); -it("throws helpful error if `appId` is not set properly (#184)", async () => { +it("throws helpful error if `appId` is not set (#184)", async () => { expect(() => { createAppAuth({ // @ts-ignore @@ -2353,6 +2353,17 @@ it("throws helpful error if `appId` is not set properly (#184)", async () => { }).toThrowError("[@octokit/auth-app] appId option is required"); }); +it("throws helpful error if `appId` is not set to a numeric value", async () => { + expect(() => { + createAppAuth({ + appId: "not-a-number", + privateKey: PRIVATE_KEY, + }); + }).toThrowError( + "[@octokit/auth-app] appId option must be a number or numeric string" + ); +}); + it("throws helpful error if `privateKey` is not set properly (#184)", async () => { expect(() => { createAppAuth({