Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use __OW_CLOUD to detect internal/runtime #184

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function withHiddenFields (sourceObj, fieldsToHide) {
* @returns {boolean} returns true if in Adobe Runtime
*/
function isInternalToAdobeRuntime () {
const { __OW_NAMESPACE, __OW_API_HOST, __OW_ACTIVATION_ID } = process.env
return !!(__OW_NAMESPACE && __OW_API_HOST && __OW_ACTIVATION_ID)
const { __OW_CLOUD } = process.env
return !!(__OW_CLOUD)
}

/**
Expand Down
31 changes: 15 additions & 16 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,17 @@ describe('isInternalToAdobeRuntime', () => {
})

test('in runtime context', () => {
process.env.__OW_NAMESPACE = 'some-namespace'
process.env.__OW_API_HOST = 'some-server-dot-com'
process.env.__OW_ACTIVATION_ID = 'some-activation-id'

process.env.__OW_CLOUD = 'aws'
expect(isInternalToAdobeRuntime()).toBeTruthy()
})

test('not in runtime context', () => {
// make doubly sure the env vars are not there
delete process.env.__OW_NAMESPACE
delete process.env.__OW_API_HOST
delete process.env.__OW_ACTIVATION_ID

process.env.__OW_CLOUD = undefined
expect(isInternalToAdobeRuntime()).toBeFalsy()
})

test('in runtime context - endpoints should be internal', () => {
process.env.__OW_NAMESPACE = 'some-namespace'
process.env.__OW_API_HOST = 'some-server-dot-com'
process.env.__OW_ACTIVATION_ID = 'some-activation-id'
process.env.__OW_CLOUD = 'aws'

expect(isInternalToAdobeRuntime()).toBeTruthy()
jest.isolateModules(() => {
Expand All @@ -85,10 +76,7 @@ describe('isInternalToAdobeRuntime', () => {
})

test('not in runtime context - endpoints should be public', () => {
// make doubly sure the env vars are not there
delete process.env.__OW_NAMESPACE
delete process.env.__OW_API_HOST
delete process.env.__OW_ACTIVATION_ID
process.env.__OW_CLOUD = undefined

expect(isInternalToAdobeRuntime()).toBeFalsy()
jest.isolateModules(() => {
Expand All @@ -97,6 +85,17 @@ describe('isInternalToAdobeRuntime', () => {
expect(constants.ENDPOINTS.stage).toEqual(constants.ENDPOINT_STAGE)
})
})

test('in runtime context - endpoints should be internal (ensure order of tests does not matter)', () => {
process.env.__OW_CLOUD = 'aws'

expect(isInternalToAdobeRuntime()).toBeTruthy()
jest.isolateModules(() => {
const constants = require('../lib/constants')
expect(constants.ENDPOINTS.prod).toEqual(constants.ENDPOINT_PROD_INTERNAL)
expect(constants.ENDPOINTS.stage).toEqual(constants.ENDPOINT_STAGE_INTERNAL)
})
})
})

describe('formatAjvErrors', () => {
Expand Down