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

feat: throw helpful error when appId or privateKey is set to a falsy value #280

Merged
merged 2 commits into from
Apr 22, 2021
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
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion test/deprecations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("deprecations", () => {
const warn = jest.fn();
const auth = createAppAuth({
appId: "1",
privateKey: "",
privateKey: "1",
clientId: "12345678901234567890",
clientSecret: "1234567890123456789012345678901234567890",
log: { warn },
Expand Down
30 changes: 30 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});