diff --git a/packages/developer-portal/src/components/apps/edit/__tests__/__snapshots__/app-listing-tab.test.tsx.snap b/packages/developer-portal/src/components/apps/edit/__tests__/__snapshots__/app-listing-tab.test.tsx.snap index f360b6fa58..f35760ee46 100644 --- a/packages/developer-portal/src/components/apps/edit/__tests__/__snapshots__/app-listing-tab.test.tsx.snap +++ b/packages/developer-portal/src/components/apps/edit/__tests__/__snapshots__/app-listing-tab.test.tsx.snap @@ -100,7 +100,7 @@ exports[`AppListingTab should match a snapshot 1`] = ` classname="" id="test-static-id" name="launchUri" - placeholder="HTTPS or HTTP only for localhost" + placeholder="HTTPS or HTTP only for localhost/dev.reapit" type="text" value="Mock field value" /> @@ -629,7 +629,7 @@ exports[`AppListingTab should match a snapshot 1`] = ` classname="" id="test-static-id" name="launchUri" - placeholder="HTTPS or HTTP only for localhost" + placeholder="HTTPS or HTTP only for localhost/dev.reapit" type="text" value="Mock field value" /> @@ -1278,7 +1278,7 @@ exports[`AppListingTab should match a snapshot with errors and messages 1`] = ` classname="el-has-input-error" id="test-static-id" name="launchUri" - placeholder="HTTPS or HTTP only for localhost" + placeholder="HTTPS or HTTP only for localhost/dev.reapit" type="text" /> { if (!value) return true - return whiteListLocalhostAndIsValidUrl(value) + return isWhitelistedLocalDevelopmentUrlAndValidUrl(value) }, }), @@ -123,7 +123,7 @@ export const appEditValidationSchema = object().shape({ message: homePage.errorMessage, test: (value) => { if (!value) return true - return whiteListLocalhostAndIsValidUrl(value) || isValidHttpUrl(value) + return isWhitelistedLocalDevelopmentUrlAndValidUrl(value) || isValidHttpUrl(value) }, }), diff --git a/packages/developer-portal/src/components/apps/new/__tests__/__snapshots__/helper-content.test.tsx.snap b/packages/developer-portal/src/components/apps/new/__tests__/__snapshots__/helper-content.test.tsx.snap index c0154d1432..8a08694727 100644 --- a/packages/developer-portal/src/components/apps/new/__tests__/__snapshots__/helper-content.test.tsx.snap +++ b/packages/developer-portal/src/components/apps/new/__tests__/__snapshots__/helper-content.test.tsx.snap @@ -399,7 +399,7 @@ exports[`HelperContent should match a snapshot 1`] = ` Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
Create React App Template - however, any localhost (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes. + however, any localhost or dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, inclusive of white space and trailing slashes.
{ We have pre-populated the URIs that you need when using our{' '} - Create React App Template however, any localhost (for - local development), or https URI is acceptable. Please note, the URIs must match those in your app exactly, - inclusive of white space and trailing slashes. + Create React App Template however, any localhost or + dev.reapit (for local development), or https URI is acceptable. Please note, the URIs must match those in your + app exactly, inclusive of white space and trailing slashes.
diff --git a/packages/developer-portal/src/components/apps/new/index.tsx b/packages/developer-portal/src/components/apps/new/index.tsx index 8067132d10..72b891f5ff 100644 --- a/packages/developer-portal/src/components/apps/new/index.tsx +++ b/packages/developer-portal/src/components/apps/new/index.tsx @@ -22,7 +22,7 @@ import { StepOptionsContent } from './step-options-content' import { yupResolver } from '@hookform/resolvers/yup' import { useForm, UseFormTrigger } from 'react-hook-form' import { object, SchemaOf, string, TestFunction } from 'yup' -import { whiteListLocalhostAndIsValidUrl } from '@reapit/utils-common' +import { isWhitelistedLocalDevelopmentUrlAndValidUrl } from '@reapit/utils-common' import errorMessages from '../../../constants/error-messages' import { AnyObject } from 'yup/lib/types' import { Marketplace } from '@reapit/foundations-ts-definitions' @@ -54,15 +54,15 @@ const authCodeSchema: SchemaOf = object().shape({ .trim() .required(errorMessages.FIELD_REQUIRED) .test({ - test: whiteListLocalhostAndIsValidUrl as TestFunction, - message: 'Should be a secure https url or http if localhost', + test: isWhitelistedLocalDevelopmentUrlAndValidUrl as TestFunction, + message: 'Should be a secure https url or http if localhost or dev.reapit', }), signoutUris: string() .trim() .required(errorMessages.FIELD_REQUIRED) .test({ - test: whiteListLocalhostAndIsValidUrl as TestFunction, - message: 'Should be a secure https url or http if localhost', + test: isWhitelistedLocalDevelopmentUrlAndValidUrl as TestFunction, + message: 'Should be a secure https url or http if localhost or dev.reapit', }), scopes: string().trim(), }) diff --git a/packages/utils-common/src/validators/__tests__/index.test.ts b/packages/utils-common/src/validators/__tests__/index.test.ts index c3ba48e385..e9eb620a10 100644 --- a/packages/utils-common/src/validators/__tests__/index.test.ts +++ b/packages/utils-common/src/validators/__tests__/index.test.ts @@ -7,6 +7,7 @@ import { isValidHttpUrl, whiteListLocalhostAndIsValidUrl, hasSpecialChars, + isWhitelistedLocalDevelopmentUrlAndValidUrl, } from '..' describe('isImageType', () => { @@ -49,10 +50,12 @@ describe('isValidUrlWithCustomScheme', () => { const urls2 = 'myapp://link.com, http://localhost' const urls3 = 'https://link.com, http://localhost:9090' const urls4 = 'https://link.com, https://localhost' + const urls5 = 'https://link.com, http://dev.reapit:8080' expect(isValidUrlWithCustomScheme(urls1)).toBe(true) expect(isValidUrlWithCustomScheme(urls2)).toBe(true) expect(isValidUrlWithCustomScheme(urls3)).toBe(true) expect(isValidUrlWithCustomScheme(urls4)).toBe(true) + expect(isValidUrlWithCustomScheme(urls5)).toBe(true) }) it('should return false with invalid urls', () => { const urls1 = 'myapp:link.com, myapp://link2' @@ -60,11 +63,13 @@ describe('isValidUrlWithCustomScheme', () => { const urls3 = 'http://link.com, http://localhost:9090' const urls4 = 'link-com, https://localhost' const urls5 = 'app2://link-com, https://localhost' + const urls6 = 'link-com, http://dev.app' expect(isValidUrlWithCustomScheme(urls1)).toBe(false) expect(isValidUrlWithCustomScheme(urls2)).toBe(false) expect(isValidUrlWithCustomScheme(urls3)).toBe(false) expect(isValidUrlWithCustomScheme(urls4)).toBe(false) expect(isValidUrlWithCustomScheme(urls5)).toBe(false) + expect(isValidUrlWithCustomScheme(urls6)).toBe(false) }) }) @@ -111,6 +116,20 @@ describe('whiteListLocalhostAndIsValidUrl', () => { }) }) +describe('isWhitelistedLocalDevelopmentUrlAndValidUrl', () => { + it('valid url test', () => { + ;['https://www.google.com', 'http://localhost:8080', 'http://dev.reapit', 'http://dev.reapit:8080'].forEach((url) => + expect(isWhitelistedLocalDevelopmentUrlAndValidUrl(url)).toBeTruthy(), + ) + }) + + it('invalid url test', () => { + ;['invalid url test', 'htt://www.google.com', 'http://invalid.app'].forEach((url) => + expect(isWhitelistedLocalDevelopmentUrlAndValidUrl(url)).toBeFalsy(), + ) + }) +}) + describe('isValidHttpUrl', () => { it('valid http url test', () => { ;['http://www.google.com', 'http://www.googlee.com'].forEach((url) => expect(isValidHttpUrl(url)).toBeTruthy()) diff --git a/packages/utils-common/src/validators/index.ts b/packages/utils-common/src/validators/index.ts index 0628118312..b21127afd7 100644 --- a/packages/utils-common/src/validators/index.ts +++ b/packages/utils-common/src/validators/index.ts @@ -22,9 +22,9 @@ export const checkValidCustomScheme = (url: string): boolean => { return false } const [, protocol, link] = result - // allow http only for localhost + // allow http only for localhost and dev.reapit addresses if (protocol === 'http') { - return link.indexOf('localhost') === 0 + return link.indexOf('localhost') === 0 || link.indexOf('dev.reapit') === 0 } return !!protocol && !!link @@ -50,6 +50,10 @@ export const whiteListLocalhostAndIsValidUrl = (url: string) => { return isValidHttpsUrl(url) || /http?:\/\/localhost/.test(url) } +export const isWhitelistedLocalDevelopmentUrlAndValidUrl = (url: string) => { + return isValidHttpsUrl(url) || /http?:\/\/localhost/.test(url) || /http?:\/\/dev.reapit/.test(url) +} + export const hasSpecialChars = (value: string): boolean => { if (!value) return false