Skip to content

Commit

Permalink
Use __OW_CLOUD to detect internal/runtime (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage authored Sep 10, 2024
1 parent 8cffb7d commit c99aca7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
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

0 comments on commit c99aca7

Please sign in to comment.