Skip to content

Commit

Permalink
chore: make https configurable in url patterns (#812)
Browse files Browse the repository at this point in the history
enable local sandbox where tls connections might not be feasible
  • Loading branch information
evegufy authored May 22, 2024
1 parent 545c128 commit e84d40e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
14 changes: 7 additions & 7 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ npm/npmjs/-/bonjour-service/1.1.1, MIT, approved, #7474
npm/npmjs/-/boolbase/1.0.0, ISC, approved, clearlydefined
npm/npmjs/-/brace-expansion/1.1.11, MIT, approved, clearlydefined
npm/npmjs/-/brace-expansion/2.0.1, MIT, approved, clearlydefined
npm/npmjs/-/braces/3.0.2, MIT, approved, clearlydefined
npm/npmjs/-/braces/3.0.2, MIT, approved, #14866
npm/npmjs/-/browser-process-hrtime/1.0.0, BSD-2-Clause, approved, clearlydefined
npm/npmjs/-/browserslist/4.22.1, MIT, approved, #10780
npm/npmjs/-/bser/2.1.1, Apache-2.0, approved, clearlydefined
Expand Down Expand Up @@ -235,7 +235,7 @@ npm/npmjs/-/error-stack-parser/2.1.4, MIT, approved, clearlydefined
npm/npmjs/-/es-abstract/1.22.2, MIT, approved, #9656
npm/npmjs/-/es-array-method-boxes-properly/1.0.0, MIT, approved, clearlydefined
npm/npmjs/-/es-get-iterator/1.1.3, MIT, approved, clearlydefined
npm/npmjs/-/es-iterator-helpers/1.0.15, MIT, approved, clearlydefined
npm/npmjs/-/es-iterator-helpers/1.0.15, MIT, approved, #13907
npm/npmjs/-/es-module-lexer/1.3.1, MIT, approved, #8964
npm/npmjs/-/es-set-tostringtag/2.0.1, MIT, approved, #6218
npm/npmjs/-/es-shim-unscopables/1.0.0, MIT, approved, clearlydefined
Expand Down Expand Up @@ -639,7 +639,7 @@ npm/npmjs/-/path-type/4.0.0, MIT, approved, clearlydefined
npm/npmjs/-/performance-now/2.1.0, MIT, approved, clearlydefined
npm/npmjs/-/phone/3.1.41, MIT, approved, #10500
npm/npmjs/-/picocolors/0.2.1, ISC, approved, clearlydefined
npm/npmjs/-/picocolors/1.0.0, ISC, approved, clearlydefined
npm/npmjs/-/picocolors/1.0.0, ISC, approved, #14718
npm/npmjs/-/picomatch/2.3.1, MIT, approved, clearlydefined
npm/npmjs/-/pify/2.3.0, MIT, approved, clearlydefined
npm/npmjs/-/pirates/4.0.6, MIT, approved, #680
Expand Down Expand Up @@ -771,7 +771,7 @@ npm/npmjs/-/recursive-readdir/2.2.3, MIT, approved, clearlydefined
npm/npmjs/-/redent/3.0.0, MIT, approved, clearlydefined
npm/npmjs/-/redux-thunk/2.4.2, MIT, approved, clearlydefined
npm/npmjs/-/redux/4.2.1, CC0-1.0 AND MIT, approved, #7046
npm/npmjs/-/reflect.getprototypeof/1.0.4, MIT, approved, clearlydefined
npm/npmjs/-/reflect.getprototypeof/1.0.4, MIT, approved, #13910
npm/npmjs/-/regenerate-unicode-properties/10.1.1, MIT, approved, #10903
npm/npmjs/-/regenerate/1.4.2, MIT, approved, clearlydefined
npm/npmjs/-/regenerator-runtime/0.13.11, MIT, approved, #4978
Expand Down Expand Up @@ -813,7 +813,7 @@ npm/npmjs/-/sass-loader/12.6.0, MIT, approved, clearlydefined
npm/npmjs/-/sass/1.69.0, MIT, approved, #11033
npm/npmjs/-/sax/1.2.4, ISC AND MIT AND ISC, approved, #5889
npm/npmjs/-/saxes/5.0.1, ISC, approved, clearlydefined
npm/npmjs/-/scheduler/0.23.0, MIT, approved, clearlydefined
npm/npmjs/-/scheduler/0.23.0, MIT, approved, #14589
npm/npmjs/-/schema-utils/2.7.0, MIT, approved, clearlydefined
npm/npmjs/-/schema-utils/2.7.1, MIT, approved, clearlydefined
npm/npmjs/-/schema-utils/3.3.0, MIT, approved, #8952
Expand Down Expand Up @@ -1307,7 +1307,7 @@ npm/npmjs/@types/jest/29.5.5, MIT, approved, #11951
npm/npmjs/@types/json-schema/7.0.13, MIT, approved, clearlydefined
npm/npmjs/@types/json5/0.0.29, MIT, approved, clearlydefined
npm/npmjs/@types/lodash.debounce/4.0.7, MIT, approved, clearlydefined
npm/npmjs/@types/lodash.uniq/4.5.7, MIT, approved, clearlydefined
npm/npmjs/@types/lodash.uniq/4.5.7, MIT, approved, #13930
npm/npmjs/@types/lodash/4.14.199, MIT, approved, #4131
npm/npmjs/@types/mime/1.3.3, MIT, approved, #10834
npm/npmjs/@types/mime/3.0.2, MIT, approved, #10805
Expand All @@ -1319,7 +1319,7 @@ npm/npmjs/@types/prettier/2.7.3, MIT, approved, #9030
npm/npmjs/@types/prop-types/15.7.11, MIT, approved, clearlydefined
npm/npmjs/@types/prop-types/15.7.8, MIT, approved, clearlydefined
npm/npmjs/@types/q/1.5.6, MIT, approved, clearlydefined
npm/npmjs/@types/qs/6.9.8, MIT, approved, clearlydefined
npm/npmjs/@types/qs/6.9.8, MIT, approved, #13991
npm/npmjs/@types/range-parser/1.2.5, MIT, approved, #10795
npm/npmjs/@types/react-dom/18.2.11, MIT, approved, #8256
npm/npmjs/@types/react-redux/7.1.27, MIT, approved, #10970
Expand Down
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div id="app"></div>
<!-- Do NOT change 'ENV' without changing 'custom_env_vars_anchor' in scripts/inject-dynamic-env.sh as well -->
<script>
const ENV = {PORTAL_ASSETS_URL:"http://localhost:3000/assets",PORTAL_BACKEND_URL:"https://portal-backend.example.org",CENTRALIDP_URL:"https://centralidp.example.org/auth",BPDM_API_URL:"https://business-partners.example.org/pool/api",SEMANTICS_URL:"https://semantics.example.org",MANAGED_IDENTITY_WALLETS_NEW_URL:"https://managed-identity-wallets-new.example.org"}
const ENV = {REQUIRE_HTTPS_URL_PATTERN:"true",PORTAL_ASSETS_URL:"http://localhost:3000/assets",PORTAL_BACKEND_URL:"https://portal-backend.example.org",CENTRALIDP_URL:"https://centralidp.example.org/auth",BPDM_API_URL:"https://business-partners.example.org/pool/api",SEMANTICS_URL:"https://semantics.example.org",MANAGED_IDENTITY_WALLETS_NEW_URL:"https://managed-identity-wallets-new.example.org"}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions scripts/inject-dynamic-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
###############################################################

# Define custom variable
custom_env_vars='{PORTAL_ASSETS_URL:"'$PORTAL_ASSETS_URL'",PORTAL_BACKEND_URL:"'$PORTAL_BACKEND_URL'",CENTRALIDP_URL:"'$CENTRALIDP_URL'",BPDM_API_URL:"'$BPDM_API_URL'",SEMANTICS_URL:"'$SEMANTICS_URL'",MANAGED_IDENTITY_WALLETS_NEW_URL:"'$MANAGED_IDENTITY_WALLETS_NEW_URL'"}'
custom_env_vars='{REQUIRE_HTTPS_URL_PATTERN:"'$REQUIRE_HTTPS_URL_PATTERN'",PORTAL_ASSETS_URL:"'$PORTAL_ASSETS_URL'",PORTAL_BACKEND_URL:"'$PORTAL_BACKEND_URL'",CENTRALIDP_URL:"'$CENTRALIDP_URL'",BPDM_API_URL:"'$BPDM_API_URL'",SEMANTICS_URL:"'$SEMANTICS_URL'",MANAGED_IDENTITY_WALLETS_NEW_URL:"'$MANAGED_IDENTITY_WALLETS_NEW_URL'"}'
# Define anchor variable
custom_env_vars_anchor='{PORTAL_ASSETS_URL:"http://localhost:3000/assets",PORTAL_BACKEND_URL:"https://portal-backend.example.org",CENTRALIDP_URL:"https://centralidp.example.org/auth",BPDM_API_URL:"https://business-partners.example.org/pool/api",SEMANTICS_URL:"https://semantics.example.org",MANAGED_IDENTITY_WALLETS_NEW_URL:"https://managed-identity-wallets-new.example.org"}'
custom_env_vars_anchor='{REQUIRE_HTTPS_URL_PATTERN:"true",PORTAL_ASSETS_URL:"http://localhost:3000/assets",PORTAL_BACKEND_URL:"https://portal-backend.example.org",CENTRALIDP_URL:"https://centralidp.example.org/auth",BPDM_API_URL:"https://business-partners.example.org/pool/api",SEMANTICS_URL:"https://semantics.example.org",MANAGED_IDENTITY_WALLETS_NEW_URL:"https://managed-identity-wallets-new.example.org"}'
# Read content of the reference index.html file into the index_html_reference variable
index_html_reference=`cat /usr/share/nginx/html/index.html.reference`
# Replace the anchor variable with the custom variable in the index.html file
Expand Down
5 changes: 5 additions & 0 deletions src/services/EnvironmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

declare const ENV: Record<string, string>

// get the value of REQUIRE_HTTPS_URL_PATTERN environment variable, defaulting to 'true' if not set
export const getRequireHttpsUrlPattern = () =>
typeof ENV === 'undefined' ? 'true' : ENV.REQUIRE_HTTPS_URL_PATTERN

export const getApiBase = () =>
typeof ENV === 'undefined' ? '' : ENV.PORTAL_BACKEND_URL

Expand All @@ -44,6 +48,7 @@ export const getManagedIdentityWalletsNewBase = () =>
export const getClientIdManagedIdentityWallets = () => 'Cl5-CX-Custodian'

const EnvironmentService = {
getRequireHttpsUrlPattern,
getApiBase,
getAssetBase,
getBpdmApiBase,
Expand Down
19 changes: 14 additions & 5 deletions src/types/Patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

import { getRequireHttpsUrlPattern } from 'services/EnvironmentService'

// check the REQUIRE_HTTPS_URL_PATTERN environment variable, defaulting to !== 'false' if not set
const requireHttpsUrlPattern = getRequireHttpsUrlPattern() !== 'false'

const DOMAIN =
/([a-z0-9]|[a-z0-9][a-z0-9-]{0,61}[a-z0-9])(\.([a-z0-9]|[a-z0-9][a-z0-9-]{0,61}[a-z0-9])){1,10}/i
const URLPATH = /(\/[a-z0-9-._~:/?#[\]@!$&'()*+,;=%]{0,500}){0,20}/
// construct regex patterns for URL based on the REQUIRE_HTTPS_URL_PATTERN environment variable
const urlProtocol = requireHttpsUrlPattern ? 'https' : 'https?'
const urlPattern = new RegExp(
`^(${urlProtocol})://(${DOMAIN.source})(:\\d{1,5})?(${URLPATH.source})?$`,
'i'
)
const prefixUrlPattern = new RegExp(`^${urlProtocol}:`, 'i')

export const Patterns = {
ID: /^[a-z0-9_.@-]{1,80}$/i,
Expand All @@ -29,10 +41,7 @@ export const Patterns = {
MAIL: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*))@(([a-z0-9-]+\.)+[a-z]{2,})$/,
DOMAIN: new RegExp(`^${DOMAIN.source}$`, 'i'),
PATH: new RegExp(`^${URLPATH.source}$`, 'i'),
URL: new RegExp(
`^(https)://(${DOMAIN.source})(:\\d{1,5})?(${URLPATH.source})?$`,
'i'
),
URL: urlPattern,
UUID: /^[a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8}$/i,
EXTID: /^[a-z0-9]{6,36}$/i,
COMPANY_NAME:
Expand All @@ -43,7 +52,7 @@ export const Patterns = {
regionName: /^[0-9A-Za-z- ]{2,20}$/,
prefix: {
BPN: /^BPNL/i,
URL: /^https:/i,
URL: prefixUrlPattern,
MAIL: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@/,
},
SEARCH: /^[a-zA-ZÀ-ÿ0-9 !?@&_\-.]{3,80}$/,
Expand Down

0 comments on commit e84d40e

Please sign in to comment.