Skip to content

Commit

Permalink
Merge pull request #1302 from nickgros/onesage-use-localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Oct 22, 2024
2 parents 7a4d8d8 + c9e56db commit 3121c27
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 37 deletions.
1 change: 1 addition & 0 deletions apps/SageAccountWeb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"scripts": {
"clean": "rimraf build coverage",
"start": "vite",
"preview": "vite preview",
"build": "vite build",
"test": "vitest",
"type-check": "tsc --noEmit"
Expand Down
5 changes: 3 additions & 2 deletions apps/SageAccountWeb/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SynapseUtilityFunctions,
useApplicationSessionContext,
useFramebuster,
SynapseConstants,
} from 'synapse-react-client'
import { AppContextProvider } from './AppContext'
import { useSourceApp } from './components/useSourceApp'
Expand All @@ -30,12 +31,12 @@ function AppInitializer(props: { children?: React.ReactNode }) {
const isDev: boolean = window.location.hostname.includes('dev')

const stagingConfig = {
REPO: 'https://repo-staging.prod.sagebase.org',
REPO: SynapseConstants.SYNAPSE_BACKEND_STAGING_URL,
PORTAL: 'https://staging.synapse.org/',
}

const devConfig = {
REPO: 'https://repo-dev.dev.sagebase.org',
REPO: SynapseConstants.SYNAPSE_BACKEND_DEV_URL,
PORTAL: 'https://portal-dev.dev.sagebase.org/',
}

Expand Down
10 changes: 7 additions & 3 deletions apps/synapse-oauth-signin/src/AppInitializer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { OAuthClientError } from './OAuthClientError'
import React, { useCallback, useEffect } from 'react'
import { ApplicationSessionManager, useFramebuster } from 'synapse-react-client'
import {
ApplicationSessionManager,
useFramebuster,
SynapseConstants,
} from 'synapse-react-client'
import { handleErrorRedirect } from './URLUtils'

function AppInitializer(
Expand All @@ -26,12 +30,12 @@ function AppInitializer(
const isDev: boolean = window.location.hostname.includes('dev')

const stagingConfig = {
REPO: 'https://repo-staging.prod.sagebase.org/',
REPO: SynapseConstants.SYNAPSE_BACKEND_STAGING_URL,
PORTAL: 'https://staging.synapse.org/',
}

const devConfig = {
REPO: 'https://repo-dev.dev.sagebase.org/',
REPO: SynapseConstants.SYNAPSE_BACKEND_DEV_URL,
PORTAL: 'https://portal-dev.dev.sagebase.org/',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe('StandaloneLoginForm', () => {
)
expect(callback).not.toHaveBeenCalled()
expect(window.location.assign).toHaveBeenCalledWith(
'https://accounts.synapse.org/changePassword?errorCode=PASSWORD_RESET_VIA_EMAIL_REQUIRED',
'http://localhost:3000/changePassword?errorCode=PASSWORD_RESET_VIA_EMAIL_REQUIRED',
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ export const SynapseHomepageNavBar: React.FunctionComponent<
const handleClosePortalResources = () => {
setPortalResourcesAnchorEl(null)
}
const oneSageURL = useOneSageURL()

const onLoginClicked = () => {
// Navigate to the LoginPlace, which will set a cookie that will be used to redirect back from OneSage
gotoPlace(LOGIN_LINK)
}

return (
<Box
sx={{
Expand Down Expand Up @@ -140,7 +145,7 @@ export const SynapseHomepageNavBar: React.FunctionComponent<
variant="outlined"
color="secondary"
sx={navButtonSx}
href={oneSageURL.toString()}
onClick={onLoginClicked}
>
Login
</Button>
Expand Down Expand Up @@ -273,7 +278,7 @@ export const SynapseHomepageNavBar: React.FunctionComponent<
sx={{ mb: '40px' }}
onClick={() => {
handleCloseMobileMenu()
gotoPlace(LOGIN_LINK)
onLoginClicked()
}}
>
Log In
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ exports[`SynapseHomepageV2 Snapshot test Basic home page 1`] = `
/>
<a
class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedLightPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorLightPrimary MuiButton-root MuiButton-contained MuiButton-containedLightPrimary MuiButton-sizeLarge MuiButton-containedSizeLarge MuiButton-colorLightPrimary css-n52da1-MuiButtonBase-root-MuiButton-root"
href="https://accounts.synapse.org/sageresources"
href="http://localhost:3000/sageresources"
tabindex="0"
target="_blank"
>
Expand Down Expand Up @@ -913,7 +913,7 @@ exports[`SynapseHomepageV2 Snapshot test Basic home page 1`] = `
</div>
<a
class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedSecondary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorSecondary MuiButton-root MuiButton-contained MuiButton-containedSecondary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorSecondary css-34fra2-MuiButtonBase-root-MuiButton-root"
href="https://accounts.synapse.org/register1"
href="http://localhost:3000/register1"
tabindex="0"
>
Register Now
Expand Down
6 changes: 6 additions & 0 deletions packages/synapse-react-client/src/utils/SynapseConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ export const PERSISTENT_LOCAL_STORAGE_KEYS = [
export const PRIVACY_POLICY_LINK =
'https://www.synapse.org/TrustCenter:PrivacyPolicy'

export const SYNAPSE_BACKEND_PRODUCTION_URL =
'https://repo-prod.prod.sagebase.org'
export const SYNAPSE_BACKEND_STAGING_URL =
'https://repo-staging.prod.sagebase.org'
export const SYNAPSE_BACKEND_DEV_URL = 'https://repo-dev.dev.sagebase.org'

export const ONE_SAGE_PRODUCTION_URL = 'https://accounts.synapse.org'
export const ONE_SAGE_STAGING_URL = 'https://staging.accounts.synapse.org'
export const ONE_SAGE_APPID_QUERY_PARAM_KEY = 'appId'
14 changes: 10 additions & 4 deletions packages/synapse-react-client/src/utils/functions/getEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
SYNAPSE_BACKEND_DEV_URL,
SYNAPSE_BACKEND_PRODUCTION_URL,
SYNAPSE_BACKEND_STAGING_URL,
} from '../SynapseConstants'

export enum BackendDestinationEnum {
REPO_ENDPOINT,
PORTAL_ENDPOINT,
Expand Down Expand Up @@ -27,7 +33,7 @@ const DEFAULT_SYNAPSE_PORTAL = getSynapsePortalEndpoint(
)

export const PRODUCTION_ENDPOINT_CONFIG: EndpointObject = {
REPO: 'https://repo-prod.prod.sagebase.org',
REPO: SYNAPSE_BACKEND_PRODUCTION_URL,
PORTAL: DEFAULT_SYNAPSE_PORTAL,
}

Expand Down Expand Up @@ -57,15 +63,15 @@ const MOCK_PORTAL_ORIGIN = 'https://mock-portal.sagebase.org/' satisfies string

export const STACK_MAP: Record<SynapseStack, EndpointObject> = {
production: {
REPO: 'https://repo-prod.prod.sagebase.org',
REPO: SYNAPSE_BACKEND_PRODUCTION_URL,
PORTAL: 'https://www.synapse.org/',
},
staging: {
REPO: 'https://repo-staging.prod.sagebase.org',
REPO: SYNAPSE_BACKEND_STAGING_URL,
PORTAL: 'https://staging.synapse.org/',
},
development: {
REPO: 'https://repo-dev.dev.sagebase.org',
REPO: SYNAPSE_BACKEND_DEV_URL,
PORTAL: 'https://portal-dev.dev.sagebase.org/',
},
mock: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('useDetectSSOCode tests', () => {
expect(mockSetAccessTokenCookie).not.toHaveBeenCalled()
expect(onSignInComplete).not.toHaveBeenCalled()
expect(window.location.replace).toHaveBeenCalledWith(
'https://accounts.synapse.org/register1',
'http://localhost:3000/register1',
)
expect(hookReturn.result.current.isLoading).toBe(false)
})
Expand Down
144 changes: 144 additions & 0 deletions packages/synapse-react-client/src/utils/hooks/useOneSageURL.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import {
SYNAPSE_BACKEND_DEV_URL,
SYNAPSE_BACKEND_PRODUCTION_URL,
SYNAPSE_BACKEND_STAGING_URL,
} from '../SynapseConstants'
import { getOneSageUrl } from './useOneSageURL'

describe('OneSage URL tests', () => {
describe('SynapseWebClient domains', () => {
test('production', () => {
const appId = 'synapse.org'
expect(
getOneSageUrl(
'synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
).toString(),
).toEqual('https://accounts.synapse.org/?appId=synapse.org')
expect(
getOneSageUrl(
'www.synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
).toString(),
).toEqual('https://accounts.synapse.org/?appId=synapse.org')
})
test('staging', () => {
const appId = 'staging.synapse.org'
const url = getOneSageUrl(
'staging.synapse.org',
SYNAPSE_BACKEND_STAGING_URL,
appId,
)
expect(url.toString()).toEqual(
'https://staging.accounts.synapse.org/?appId=staging.synapse.org',
)
})
test.todo('dev') // IT-3849
test('local', () => {
const appId = 'localhost'
expect(
getOneSageUrl(
'127.0.0.1',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
).toString(),
).toEqual('http://127.0.0.1:3000/?appId=localhost')
expect(
getOneSageUrl(
'127.0.0.1',
SYNAPSE_BACKEND_STAGING_URL,
appId,
).toString(),
).toEqual('http://127.0.0.1:3000/?appId=localhost')
expect(
getOneSageUrl('127.0.0.1', SYNAPSE_BACKEND_DEV_URL, appId).toString(),
).toEqual('http://127.0.0.1:3000/?appId=localhost')
expect(
getOneSageUrl(
'localhost',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
).toString(),
).toEqual('http://localhost:3000/?appId=localhost')
expect(
getOneSageUrl(
'localhost',
SYNAPSE_BACKEND_STAGING_URL,
appId,
).toString(),
).toEqual('http://localhost:3000/?appId=localhost')
expect(
getOneSageUrl('localhost', SYNAPSE_BACKEND_DEV_URL, appId).toString(),
).toEqual('http://localhost:3000/?appId=localhost')
})
})

describe('OneSage domains', () => {
test('production', () => {
const url = getOneSageUrl(
'accounts.synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
)
expect(url.toString()).toEqual('https://accounts.synapse.org/')
})
test('staging', () => {
const url = getOneSageUrl(
'staging.accounts.synapse.org',
SYNAPSE_BACKEND_STAGING_URL,
)
expect(url.toString()).toEqual('https://staging.accounts.synapse.org/')
})
test.todo('dev') // no site exists (IT-3849)
test('local', () => {
const url = getOneSageUrl('localhost', SYNAPSE_BACKEND_PRODUCTION_URL)
expect(url.toString()).toEqual('http://localhost:3000/')
})
})

describe('synapse-oauth-signin domains', () => {
test('production', () => {
const url = getOneSageUrl(
'signin.synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
)
expect(url.toString()).toEqual('https://accounts.synapse.org/')
})
test('staging', () => {
const url = getOneSageUrl(
'staging-signin.synapse.org',
SYNAPSE_BACKEND_STAGING_URL,
)
expect(url.toString()).toEqual('https://staging.accounts.synapse.org/')
})
test.todo('dev') // no site exists
test.todo('local') // these typically run on the same port, so we need to establish a convention to run them on different ports
})

describe('portal domain', () => {
const appId = 'myportal'

test('production', () => {
const url = getOneSageUrl(
'myportal.synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
)
expect(url.toString()).toEqual(
'https://accounts.synapse.org/?appId=myportal',
)
})
test('staging', () => {
// Staging portals typically use Synapse production as a backend
const url = getOneSageUrl(
'staging.myportal.synapse.org',
SYNAPSE_BACKEND_PRODUCTION_URL,
appId,
)
expect(url.toString()).toEqual(
'https://accounts.synapse.org/?appId=myportal',
)
})
})
})
Loading

0 comments on commit 3121c27

Please sign in to comment.