diff --git a/packages/api-file-manager/src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts b/packages/api-file-manager/src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts index b669edae558..00d228aadae 100644 --- a/packages/api-file-manager/src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts +++ b/packages/api-file-manager/src/delivery/AssetDelivery/privateFiles/NotAuthorizedAssetReply.ts @@ -7,7 +7,7 @@ export class NotAuthorizedAssetReply extends AssetReply { code: 403, headers: ResponseHeaders.create({ "cache-control": "no-store", - "content-type": "application/json" + "content-type": "application/json; charset=utf-8" }), body: () => ({ error: "Not authorized!", code: "NOT_AUTHORIZED" }) }); diff --git a/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts b/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts index 30c5ee289e4..a4930637516 100644 --- a/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts +++ b/packages/api-headless-cms/__tests__/contentAPI/httpOptions.test.ts @@ -34,7 +34,6 @@ describe("HTTP Options request", () => { body: "", headers: { ...versionHeaders, - "content-type": "application/json; charset=utf-8", "access-control-allow-headers": "*", "access-control-allow-methods": ["OPTIONS", "POST"].sort().join(","), "access-control-allow-origin": "*", diff --git a/packages/handler/__tests__/headers.test.ts b/packages/handler/__tests__/headers.test.ts index 86895317c16..a0e83c6d113 100644 --- a/packages/handler/__tests__/headers.test.ts +++ b/packages/handler/__tests__/headers.test.ts @@ -59,7 +59,6 @@ describe("ResponseHeaders class", () => { cookies: [], headers: { "cache-control": "public, max-age=86400", - "content-type": "application/json; charset=utf-8", "access-control-allow-origin": "*", "access-control-allow-headers": "*", "access-control-allow-methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH", diff --git a/packages/handler/__tests__/onRequest.test.ts b/packages/handler/__tests__/onRequest.test.ts index 7f5c5e95a97..32634689c15 100644 --- a/packages/handler/__tests__/onRequest.test.ts +++ b/packages/handler/__tests__/onRequest.test.ts @@ -4,9 +4,14 @@ import { createHandlerOnRequest } from "~/plugins/HandlerOnRequestPlugin"; jest.setTimeout(5000); -const createOptionsRoute = () => { - return createRoute(({ onOptions }) => { - onOptions("/webiny-test", async (request, reply) => { +const createRoutes = () => { + return createRoute(({ onPost, onOptions }) => { + onPost("/webiny-test", async (_, reply) => { + return reply.send({ + weGotToPostReply: true + }); + }); + onOptions("/webiny-test", async (_, reply) => { return reply.send({ weGotToOptionsReply: true }); @@ -17,37 +22,66 @@ const createOptionsRoute = () => { describe("fastify onRequest event", () => { it("should return our built-in headers when sending options request", async () => { const app = createHandler({ - plugins: [createOptionsRoute()] + plugins: [createRoutes()] }); - const result = await app.inject({ + const optionsResult = await app.inject({ path: "/webiny-test", method: "OPTIONS", query: {}, - payload: JSON.stringify({}) + payload: JSON.stringify({}), + headers: { + "content-type": "application/json" + } }); - expect(result).toMatchObject({ + expect(optionsResult).toMatchObject({ statusCode: 204, cookies: [], headers: { "cache-control": "public, max-age=86400", - "content-type": "application/json; charset=utf-8", "access-control-allow-origin": "*", "access-control-allow-headers": "*", - "access-control-allow-methods": "OPTIONS", + "access-control-allow-methods": "OPTIONS,POST", "access-control-max-age": "86400", - connection: "keep-alive" + connection: "keep-alive", + date: expect.toBeDateString() }, body: "", payload: "" }); + + const postResult = await app.inject({ + path: "/webiny-test", + method: "POST", + query: {}, + payload: JSON.stringify({}), + headers: { + "content-type": "application/json" + } + }); + + expect(postResult).toMatchObject({ + statusCode: 200, + cookies: [], + headers: { + "cache-control": "no-store", + "content-type": "application/json; charset=utf-8", + "access-control-allow-origin": "*", + "access-control-allow-headers": "*", + "access-control-allow-methods": "OPTIONS,POST", + connection: "keep-alive", + date: expect.toBeDateString() + }, + body: JSON.stringify({ weGotToPostReply: true }), + payload: JSON.stringify({ weGotToPostReply: true }) + }); }); it("should return users headers set via the plugin", async () => { const app = createHandler({ plugins: [ - createOptionsRoute(), + createRoutes(), createHandlerOnRequest(async (request, reply) => { const raw = reply.code(205).hijack().raw; @@ -82,7 +116,7 @@ describe("fastify onRequest event", () => { it("should throw a log if user did not end onRequest plugin correctly", async () => { const app = createHandler({ plugins: [ - createOptionsRoute(), + createRoutes(), createHandlerOnRequest(async (request, reply) => { const raw = reply.code(205).hijack().raw; diff --git a/packages/handler/__tests__/routes.test.ts b/packages/handler/__tests__/routes.test.ts index 5db4b701b5b..92cc6922a11 100644 --- a/packages/handler/__tests__/routes.test.ts +++ b/packages/handler/__tests__/routes.test.ts @@ -53,13 +53,15 @@ describe("route plugins", () => { HEAD: ["/webiny-get", "/webiny-head", "/webiny-all"], UNLOCK: ["/webiny-all"], TRACE: ["/webiny-all"], + REPORT: ["/webiny-all"], SEARCH: ["/webiny-all"], LOCK: ["/webiny-all"], MOVE: ["/webiny-all"], PROPPATCH: ["/webiny-all"], COPY: ["/webiny-all"], PROPFIND: ["/webiny-all"], - MKCOL: ["/webiny-all"] + MKCOL: ["/webiny-all"], + MKCALENDAR: ["/webiny-all"] }; expect(app.webiny.routes.defined).toEqual(expected);