From 686d1751aba83aa9a5b81e73e2249c707cacc5e4 Mon Sep 17 00:00:00 2001 From: Matthew Hilton Date: Mon, 9 Sep 2024 11:25:52 +1000 Subject: [PATCH] feat: ignore cors during connectivity check --- amd/build/connectivity_test.min.js | 2 +- amd/build/connectivity_test.min.js.map | 2 +- amd/src/connectivity_test.js | 13 ++++++++----- version.php | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/amd/build/connectivity_test.min.js b/amd/build/connectivity_test.min.js index ea6eebab3..a2fd0ec77 100644 --- a/amd/build/connectivity_test.min.js +++ b/amd/build/connectivity_test.min.js @@ -1,3 +1,3 @@ -define("auth_saml2/connectivity_test",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=(checkTarget,redirURL)=>{const http=new XMLHttpRequest;http.open("HEAD",checkTarget),http.addEventListener("load",(()=>{window.location=redirURL})),http.send()}})); +define("auth_saml2/connectivity_test",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=(checkTarget,redirURL)=>{fetch(checkTarget,{mode:"no-cors",method:"HEAD"}).then((()=>{window.location=redirURL})).catch((()=>{}))}})); //# sourceMappingURL=connectivity_test.min.js.map \ No newline at end of file diff --git a/amd/build/connectivity_test.min.js.map b/amd/build/connectivity_test.min.js.map index 4c517b419..78c01756b 100644 --- a/amd/build/connectivity_test.min.js.map +++ b/amd/build/connectivity_test.min.js.map @@ -1 +1 @@ -{"version":3,"file":"connectivity_test.min.js","sources":["../src/connectivity_test.js"],"sourcesContent":["\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to check connectivity to IdP endpoint from client.\n *\n * @module auth_saml2/connectivity_test\n * @copyright 2023 Peter Burnett \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = (checkTarget, redirURL) => {\n const http = new XMLHttpRequest();\n http.open('HEAD', checkTarget);\n http.addEventListener('load', () => {\n window.location = redirURL;\n });\n http.send();\n};\n"],"names":["checkTarget","redirURL","http","XMLHttpRequest","open","addEventListener","window","location","send"],"mappings":"iKAwBoB,CAACA,YAAaC,kBACxBC,KAAO,IAAIC,eACjBD,KAAKE,KAAK,OAAQJ,aAClBE,KAAKG,iBAAiB,QAAQ,KAC1BC,OAAOC,SAAWN,YAEtBC,KAAKM"} \ No newline at end of file +{"version":3,"file":"connectivity_test.min.js","sources":["../src/connectivity_test.js"],"sourcesContent":["\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Module to check connectivity to IdP endpoint from client.\n *\n * @module auth_saml2/connectivity_test\n * @copyright 2023 Peter Burnett \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = (checkTarget, redirURL) => {\n // We need to use no-cors to ignore cors, however,\n // this means we are returned an opaque response.\n // But an opaque response is info to say if the site is accessible or not.\n fetch(checkTarget, { mode: 'no-cors', method: 'HEAD' })\n .then(() => {\n window.location = redirURL;\n })\n // Do nothing with error, we don't care about it.\n .catch(() => {});\n};\n"],"names":["checkTarget","redirURL","fetch","mode","method","then","window","location","catch"],"mappings":"iKAwBoB,CAACA,YAAaC,YAI9BC,MAAMF,YAAa,CAAEG,KAAM,UAAWC,OAAQ,SAC7CC,MAAK,KACFC,OAAOC,SAAWN,YAGrBO,OAAM"} \ No newline at end of file diff --git a/amd/src/connectivity_test.js b/amd/src/connectivity_test.js index 3e484c26f..da0d4f181 100644 --- a/amd/src/connectivity_test.js +++ b/amd/src/connectivity_test.js @@ -23,10 +23,13 @@ */ export const init = (checkTarget, redirURL) => { - const http = new XMLHttpRequest(); - http.open('HEAD', checkTarget); - http.addEventListener('load', () => { + // We need to use no-cors to ignore cors, however, + // this means we are returned an opaque response. + // But an opaque response is info to say if the site is accessible or not. + fetch(checkTarget, { mode: 'no-cors', method: 'HEAD' }) + .then(() => { window.location = redirURL; - }); - http.send(); + }) + // Do nothing with error, we don't care about it. + .catch(() => {}); }; diff --git a/version.php b/version.php index d8a820ae3..7c8fd47a0 100644 --- a/version.php +++ b/version.php @@ -24,8 +24,8 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2024082000; // The current plugin version (Date: YYYYMMDDXX). -$plugin->release = 2024082000; // Match release exactly to version. +$plugin->version = 2024090900; // The current plugin version (Date: YYYYMMDDXX). +$plugin->release = 2024090900; // Match release exactly to version. $plugin->requires = 2017051509; // Requires PHP 7, 2017051509 = T12. M3.3 // Strictly we require either Moodle 3.5 OR // we require Totara 3.3, but the version number