Skip to content

Commit

Permalink
Merge branch 'master' into disable-cognito-mailer-deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
plittlewood-rpt authored Oct 14, 2024
2 parents c577d82 + 00436ae commit 3fd5f22
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
Expand Down Expand Up @@ -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"
/>
Expand Down Expand Up @@ -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"
/>
<mock-styled.span
Expand Down Expand Up @@ -2019,7 +2019,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"
/>
<mock-styled.span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const formFields: Record<keyof AppEditFormSchema, InputGroupProps & { nam
launchUri: {
name: 'launchUri',
label: 'Launch URI',
placeholder: 'HTTPS or HTTP only for localhost',
placeholder: 'HTTPS or HTTP only for localhost/dev.reapit',
errorMessage: 'Invalid Launch URI',
type: 'text',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
emailRegex,
isValidUrlWithCustomScheme,
isValidLimitToClientIds,
whiteListLocalhostAndIsValidUrl,
isWhitelistedLocalDevelopmentUrlAndValidUrl,
isValidHttpUrl,
isValidHttpsUrl,
} from '@reapit/utils-common'
Expand Down Expand Up @@ -82,7 +82,7 @@ export const appEditValidationSchema = object().shape({
if (authFlow === USER_SESSION) {
return schema.required(errorMessages.FIELD_REQUIRED).test({
name: 'isValidLaunchUri',
test: whiteListLocalhostAndIsValidUrl,
test: isWhitelistedLocalDevelopmentUrlAndValidUrl,
message: launchUri.errorMessage,
})
}
Expand All @@ -95,7 +95,7 @@ export const appEditValidationSchema = object().shape({
message: launchUri.errorMessage,
test: (value) => {
if (!value) return true
return whiteListLocalhostAndIsValidUrl(value)
return isWhitelistedLocalDevelopmentUrlAndValidUrl(value)
},
}),

Expand Down Expand Up @@ -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)
},
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ exports[`HelperContent should match a snapshot 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down Expand Up @@ -823,7 +823,7 @@ exports[`HelperContent should match a snapshot 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ exports[`AppsNew should match a snapshot 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down Expand Up @@ -1975,7 +1975,7 @@ exports[`AppsNew should match a snapshot 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down Expand Up @@ -3062,7 +3062,7 @@ exports[`AppsNew should match snapshot for mobile view 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down Expand Up @@ -4083,7 +4083,7 @@ exports[`AppsNew should match snapshot for mobile view 1`] = `
<a>
Create React App Template
</a>
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.
</mock-styled.p>
</div>
<div
Expand Down
6 changes: 3 additions & 3 deletions packages/developer-portal/src/components/apps/new/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const appWizardSteps: AppNewWizardSteps = {
[AppNewStepId.agencyCloudStep]: {
headingText: 'Authentication',
headerText:
'Please supply at least one redirect and logout uri. A non-https localhost uri is acceptable for quick start development.',
'Please supply at least one redirect and logout uri. A non-https localhost or dev.reapit uri is acceptable for quick start development.',
iconName: 'userAuthInfographic',
},
[AppNewStepId.dataFeedStep]: {
Expand All @@ -73,13 +73,13 @@ export const appWizardSteps: AppNewWizardSteps = {
[AppNewStepId.clientSideStep]: {
headingText: 'Authentication',
headerText:
'Please supply at least one redirect and logout uri. A non-https localhost uri is acceptable for quick start development.',
'Please supply at least one redirect and logout uri. A non-https localhost or dev.reapit uri is acceptable for quick start development.',
iconName: 'userAuthInfographic',
},
[AppNewStepId.rcRedirectsStep]: {
headingText: 'Authentication',
headerText:
'Please supply at least one redirect and logout uri. A non-https localhost uri is acceptable for quick start development.',
'Please supply at least one redirect and logout uri. A non-https localhost or dev.reapit uri is acceptable for quick start development.',
iconName: 'userAuthInfographic',
},
[AppNewStepId.websiteFeedStep]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ export const HelperContent: FC = () => {
</BodyText>
<BodyText hasGreyText>
We have pre-populated the URIs that you need when using our{' '}
<a onClick={openNewPage(ExternalPages.craDocs)}>Create React App Template</a> 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.
<a onClick={openNewPage(ExternalPages.craDocs)}>Create React App Template</a> 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.
</BodyText>
</div>
<div className={cx(shouldShowStep(AppNewStepId.permissionsStep) ? elFadeIn : stepIsHidden)}>
Expand Down
10 changes: 5 additions & 5 deletions packages/developer-portal/src/components/apps/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -54,15 +54,15 @@ const authCodeSchema: SchemaOf<CreateAppFormSchema> = object().shape({
.trim()
.required(errorMessages.FIELD_REQUIRED)
.test({
test: whiteListLocalhostAndIsValidUrl as TestFunction<string | undefined, AnyObject>,
message: 'Should be a secure https url or http if localhost',
test: isWhitelistedLocalDevelopmentUrlAndValidUrl as TestFunction<string | undefined, AnyObject>,
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<string | undefined, AnyObject>,
message: 'Should be a secure https url or http if localhost',
test: isWhitelistedLocalDevelopmentUrlAndValidUrl as TestFunction<string | undefined, AnyObject>,
message: 'Should be a secure https url or http if localhost or dev.reapit',
}),
scopes: string().trim(),
})
Expand Down
19 changes: 19 additions & 0 deletions packages/utils-common/src/validators/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isValidHttpUrl,
whiteListLocalhostAndIsValidUrl,
hasSpecialChars,
isWhitelistedLocalDevelopmentUrlAndValidUrl,
} from '..'

describe('isImageType', () => {
Expand Down Expand Up @@ -49,22 +50,26 @@ 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'
const urls2 = 'myapp:/link.com, http://localhost'
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)
})
})

Expand Down Expand Up @@ -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())
Expand Down
8 changes: 6 additions & 2 deletions packages/utils-common/src/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 3fd5f22

Please sign in to comment.