From 63b8d31bcfcaf41bd7fa3eb7f6d687d48f9cdc80 Mon Sep 17 00:00:00 2001 From: Stepan Kuzmin Date: Tue, 1 Oct 2024 13:34:34 +0300 Subject: [PATCH] Fix env substitution in access token generation (internal-1893) * Fix ENV substitution in generate-access-token-script.js * fix CSP urls --- .eslintrc | 2 +- debug/access_token.js | 10 +++++----- package.json | 2 +- test/integration/csp-tests/fixtures/csp.html | 2 +- test/integration/csp-tests/fixtures/strict.html | 2 +- vitest.config.csp.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index e8508a3d813..684f236235f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,7 @@ "parserOptions": { "projectService": { "defaultProject": "./tsconfig.json", - "allowDefaultProject": ["*.js", "debug/*.html"] + "allowDefaultProject": ["*.js", "debug/*", "build/*"] } }, "plugins": [ diff --git a/debug/access_token.js b/debug/access_token.js index 13812ac2f76..14ad443abf9 100644 --- a/debug/access_token.js +++ b/debug/access_token.js @@ -4,13 +4,14 @@ mapboxgl.accessToken = getAccessToken(); function getAccessToken() { const accessToken = [ - typeof process !== 'undefined' && process.env.MapboxAccessToken, - typeof process !== 'undefined' && process.env.MAPBOX_ACCESS_TOKEN, + process.env.MapboxAccessToken, + process.env.MAPBOX_ACCESS_TOKEN, getURLParameter('access_token'), localStorage.getItem('accessToken'), // this token is a fallback for CI and testing. it is domain restricted to localhost 'pk.eyJ1IjoibWFwYm94LWdsLWpzIiwiYSI6ImNram9ybGI1ajExYjQyeGxlemppb2pwYjIifQ.LGy5UGNIsXUZdYMvfYRiAQ' ].find(Boolean); + try { localStorage.setItem('accessToken', accessToken); } catch (_) { @@ -20,7 +21,6 @@ function getAccessToken() { } function getURLParameter(name) { - var regexp = new RegExp('[?&]' + name + '=([^&#]*)', 'i'); - var output = regexp.exec(window.location.href); - return output && output[1]; + const url = new URL(window.location.href); + return url.searchParams.get(name); } diff --git a/package.json b/package.json index 03724d0906e..8ab2a02f74d 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "test-build": "tsx ./node_modules/.bin/tape test/build/**/*.test.js", "watch-render": "cross-env SUITE_NAME=render testem -f test/integration/testem/testem.js", "watch-query": "SUITE_NAME=query testem -f test/integration/testem/testem.js", - "test-csp": "vitest --config vitest.config.csp.js --run", + "test-csp": "npm run build-token && vitest --config vitest.config.csp.ts --run", "test-render": "cross-env SUITE_NAME=render testem ci -f test/integration/testem/testem.js", "test-render-firefox": "cross-env BROWSER=Firefox SUITE_NAME=render testem ci -f test/integration/testem/testem.js", "test-render-safari": "cross-env BROWSER=Safari SUITE_NAME=render testem ci -f test/integration/testem/testem.js", diff --git a/test/integration/csp-tests/fixtures/csp.html b/test/integration/csp-tests/fixtures/csp.html index 20e7bd0133b..d16a3b022aa 100644 --- a/test/integration/csp-tests/fixtures/csp.html +++ b/test/integration/csp-tests/fixtures/csp.html @@ -6,7 +6,7 @@
- + - +