Skip to content

Commit

Permalink
fix: throw helpful error when appId is not numeric (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
joekrill authored Sep 28, 2022
1 parent 524fc44 commit 30785b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
13 changes: 12 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand Down

0 comments on commit 30785b5

Please sign in to comment.