Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { strict as assert } from "node:assert";
import { after, describe, it } from "node:test";

import { mockAgent } from "@indiekit-test/mock-agent";
import { testServer } from "@indiekit-test/server";
import supertest from "supertest";

await mockAgent("indiekit");

const server = await testServer({
application: {
tokenEndpoint: "https://token-endpoint.example",
introspectionEndpoint: "https://token-endpoint.example/introspect",
},
});

describe("endpoint-micropub GET /micropub", () => {
it("Returns 403 error when me does not match publication in api GET request", async () => {
const result = await supertest(server)
.get("/micropub")
.auth("another", { type: "bearer" })
.set("accept", "application/json")
.query({ q: "config" });

assert.equal(result.status, 403);
});

after(() => server.close());
});
6 changes: 5 additions & 1 deletion packages/indiekit/lib/indieauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@ export const IndieAuth = class {

next();
} catch (error) {
if (request.method === "GET") {
const isApiRequest =
request.headers.authorization?.toLowerCase().startsWith("bearer ") ||
request.headers.accept?.includes("application/json");

if (!isApiRequest && request.method === "GET") {
return response.redirect(
`/session/login?redirect=${request.originalUrl}`,
);
Expand Down