Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw helpful error when appId is not numeric #402

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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