Skip to content
Open
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
1 change: 1 addition & 0 deletions changelog.d/1105.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix /oauth responding with 405 despite GitHub being configured.
15 changes: 15 additions & 0 deletions spec/github.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe("GitHub", () => {
webhook: {
secret: randomUUID(),
},
oauth: {
client_id: "GITHUB_ID",
client_secret: "GITHUB_SECRET",
redirect_uri: "http://example.org/redirectme",
},
// So we can mock out the URL
enterpriseUrl: `http://localhost:${githubPort}`,
auth: {
Expand Down Expand Up @@ -168,4 +173,14 @@ describe("GitHub", () => {
expect(body).toContain("My test pull request");
},
);

test.each(["/oauth", "/github/oauth"])(
"should redirect invalid oauth requests to oauth.html",
async (path) => {
// This simply tests that oauth requests do not end up being ignored.
const req = await fetch(`http://localhost:${webhooksPort}${path}`);
expect(req.url.startsWith(`http://localhost:${webhooksPort}/oauth.html`))
.to.be.true;
},
);
});
8 changes: 5 additions & 3 deletions src/Webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
this.config.widgets?.parsedPublicUrl,
);
this.expressRouter.use("/github", this.github.getRouter());
// LEGACY PATH - Will be removed in a future release.
this.expressRouter.get(
"/oauth",
this.github.onGetOAuth.bind(this.github),
);
}

if (this.config.gitlab) {
Expand Down Expand Up @@ -94,9 +99,6 @@

// LEGACY PATHS. These will be removed in a future version.
this.expressRouter.post("/", this.onPayload.bind(this));
if (this.github) {
this.expressRouter.get("/oauth", this.github.onGetOAuth.bind(this));
}
}

public stop() {
Expand Down
14 changes: 7 additions & 7 deletions src/github/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@

const { setup_action: setupAction, state } = req.query;
log.info("Got new oauth request", { state, setupAction });
if (!this.config.oauth) {
throw new ApiError(
"Bridge is not configured with OAuth support",
ErrCode.DisabledFeature,
);
}
try {
if (!this.config.oauth) {
throw new ApiError(
"Bridge is not configured with OAuth support",
ErrCode.DisabledFeature,
);
}
if (req.query.error) {
throw new ApiError(
`GitHub Error: ${req.query.error} ${req.query.error_description}`,
Expand Down Expand Up @@ -291,9 +291,9 @@

public getRouter() {
const router = Router();
router.get("/oauth", this.onGetOAuth.bind(this));
router.use(json({ verify: this.verifyRequest.bind(this) }));
router.post("/webhook", this.onWebhook.bind(this));
router.get("/oauth", this.onGetOAuth.bind(this));
return router;
}
}
Loading