From 4dc8239b412e7872071dd282e403fea887e42764 Mon Sep 17 00:00:00 2001 From: Joe Krill Date: Wed, 28 Sep 2022 11:32:51 -0400 Subject: [PATCH] throw helpful error when `appId` is not numeric --- 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 e433438c5..29846f027 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 ce9bab763..7453ae128 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({