From e8e788f4482e4165b5c64777867f1a23cab1f2f2 Mon Sep 17 00:00:00 2001 From: ngrecco Date: Wed, 11 Aug 2021 09:54:44 -0300 Subject: [PATCH 1/2] Update request.js When running the tests in a browser with a PATCH type request, "PATCH" method is sent in all lower case letters. When the request uses CORS, the preflight OPTIONS is triggered before the actual request. This request is sent with the following header: "Access-Control-Request-Method = patch" instead of "Access-Control-Request-Method = PATCH". This causes the "Access-Control-Allow-Methods = GET, POST, OPTIONS, PUT, PATCH, DELETE" to fail, because the expected method is "PATH" instead of "path". For further reading please refer to this stack overflow post: https://stackoverflow.com/questions/55250297/problem-with-patch-method-and-cors-preflight-request?rq=1 --- lib/request.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/request.js b/lib/request.js index 224cedb..69b8efd 100644 --- a/lib/request.js +++ b/lib/request.js @@ -266,6 +266,9 @@ module.exports.agent = TestAgent; */ function Test (app, method, path) { + method = method.toUpperCase(); // Do this in order to avoid "patch" beign sent as lowercase. + // This makes the preflight request -when running in browser- to be sent as "Access-Control-Request-Method = patch" instead of "Access-Control-Request-Method = PATCH" + // Which causes problems with those kind of requests. For further reference: https://stackoverflow.com/questions/55250297/problem-with-patch-method-and-cors-preflight-request?rq=1 Request.call(this, method, path); this.app = app; this.url = typeof app === 'string' ? app + path : serverAddress(app, path); From 49b9c8dfcc3954e158d589c8bed516bde1eb6e8f Mon Sep 17 00:00:00 2001 From: ngrecco Date: Wed, 11 Aug 2021 10:11:52 -0300 Subject: [PATCH 2/2] Update request.js --- lib/request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/request.js b/lib/request.js index 69b8efd..29e595f 100644 --- a/lib/request.js +++ b/lib/request.js @@ -266,7 +266,7 @@ module.exports.agent = TestAgent; */ function Test (app, method, path) { - method = method.toUpperCase(); // Do this in order to avoid "patch" beign sent as lowercase. + method = method.toUpperCase(); // Do this in order to avoid "patch" being sent as lowercase. // This makes the preflight request -when running in browser- to be sent as "Access-Control-Request-Method = patch" instead of "Access-Control-Request-Method = PATCH" // Which causes problems with those kind of requests. For further reference: https://stackoverflow.com/questions/55250297/problem-with-patch-method-and-cors-preflight-request?rq=1 Request.call(this, method, path);