From c9bc530df0dc5989e32ba23b137c656e51715637 Mon Sep 17 00:00:00 2001 From: aaronmyatt Date: Sun, 6 Dec 2020 15:29:54 +0800 Subject: [PATCH] tests custom cors settings --- .../@node-red/editor-api/lib/index_spec.js | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/test/unit/@node-red/editor-api/lib/index_spec.js b/test/unit/@node-red/editor-api/lib/index_spec.js index 44048e6df..2f84030aa 100644 --- a/test/unit/@node-red/editor-api/lib/index_spec.js +++ b/test/unit/@node-red/editor-api/lib/index_spec.js @@ -112,15 +112,6 @@ describe("api/index", function() { }); }); - //adminAuth: { - // type: "credentials", - // users: [{ - // username: "admin", - // password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.", - // permissions: "*" - // }] - //}, - describe('initialises api with authentication enabled', function(done) { it('enables an oauth/openID based authentication mechanism',function(done) { @@ -144,4 +135,25 @@ describe("api/index", function() { }); + describe('initialises api with custom cors config', function (done) { + const httpAdminCors = { + origin: "*", + methods: "GET,PUT,POST,DELETE" + }; + + it('uses default cors middleware when user settings absent', function(done){ + api.init({ httpAdminRoot: true }, {}, {}, {}); + const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'corsMiddleware') + should(middlewareFound).be.length(1); + done(); + }) + + it('enables custom cors middleware when settings present', function(done){ + api.init({ httpAdminRoot: true, httpAdminCors }, {}, {}, {}); + const middlewareFound = api.httpAdmin._router.stack.filter((layer) => layer.name === 'corsMiddleware') + should(middlewareFound).be.length(2); + done(); + }) + }); + });