Skip to content

Commit

Permalink
assert that API_TOKEN is available
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix committed May 9, 2024
1 parent 3dfd5b6 commit bd736dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ export async function handlePublish(
});
}

if (typeof env.API_TOKEN !== "string" || !env.API_TOKEN) {
return new Response(null, {
status: 500, // Internal Server Error
});
}

const authResponse = checkRequestAuthentication(
request,
"admin",
Expand Down
1 change: 1 addition & 0 deletions test/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { handlePublish } from "../src/publish";

async function sendPublishForm(form: FormData): Promise<Response> {
assert(typeof env.API_TOKEN === "string" && env.API_TOKEN);
return await handlePublish(
new Request("https://example.com/v1/publish", {
body: form,
Expand Down

0 comments on commit bd736dd

Please sign in to comment.