Skip to content
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
21 changes: 13 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const archiver = require('archiver')
// this is a static list that comes from here: https://developer.adobe.com/runtime/docs/guides/reference/runtimes/
const SupportedRuntimes = ['sequence', 'blackbox', 'nodejs:10', 'nodejs:12', 'nodejs:14', 'nodejs:16', 'nodejs:18', 'nodejs:20', 'nodejs:22']

const SUPPORTED_ADOBE_ANNOTATION_ENDPOINTS = [
'https://adobeioruntime.net',
'https://deploy-service.dev.app-builder.corp.adp.adobe.io/runtime',
'https://deploy-service.stg.app-builder.corp.adp.adobe.io/runtime',
'https://deploy-service.app-builder.adp.adobe.io/runtime'
const SUPPORTED_ADOBE_ANNOTATION_ENDPOINT_REGEXES = [
/http(s)?:\/\/localhost/,
/http(s)?:\/\/127\.0\.0\.1/,
/https:\/\/adobeioruntime\.net/,
/https:\/\/deploy-service.*\.app-builder\.corp\.adp\.adobe\.io\/runtime/,
/https:\/\/deploy-service.*\.app-builder\.adp\.adobe\.io\/runtime/
]
const NON_CUSTOM_ADOBE_APIHOSTS_REGEXES = [
/adobeioruntime\.net/,
/deploy-service.*\.app-builder\.corp\.adp\.adobe\.io\/runtime/,
/deploy-service.*\.app-builder\.adp\.adobe\.io\/runtime/
]

const DEFAULT_PACKAGE_RESERVED_NAME = 'default'
Expand Down Expand Up @@ -1201,7 +1207,7 @@ function processPackage (packages,
let pkgs = packages
let deploymentPkgs = deploymentPackages

const isAdobeEndpoint = SUPPORTED_ADOBE_ANNOTATION_ENDPOINTS.includes(owOptions.apihost)
const isAdobeEndpoint = SUPPORTED_ADOBE_ANNOTATION_ENDPOINT_REGEXES.some(regex => regex.test(owOptions.apihost))
if (isAdobeEndpoint) {
// rewrite packages in case there are any `require-adobe-auth` annotations
// this is a temporary feature and will be replaced by a native support in Adobe I/O Runtime
Expand Down Expand Up @@ -1853,9 +1859,8 @@ function getActionUrls (appConfig, /* istanbul ignore next */ isRemoteDev = fals
const config = replacePackagePlaceHolder(appConfig)
const cleanApihost = removeProtocolFromURL(config.ow.apihost)
const cleanHostname = removeProtocolFromURL(config.app.hostname)
const endpointHosts = SUPPORTED_ADOBE_ANNOTATION_ENDPOINTS.map(endpoint => removeProtocolFromURL(endpoint))

const apihostIsCustom = !endpointHosts.includes(cleanApihost)
const apihostIsCustom = !NON_CUSTOM_ADOBE_APIHOSTS_REGEXES.some(regex => regex.test(cleanApihost))

const hostnameIsCustom = cleanHostname !== removeProtocolFromURL(config.app.defaultHostname)

Expand Down
114 changes: 114 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,120 @@ describe('require-adobe-auth annotation', () => {
triggers: []
})
})

test('apihost: localhost', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'http://localhost' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})

test('apihost: 127.0.0.1', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'https://127.0.0.1' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})

test('apihost: adobeioruntime.net', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'https://adobeioruntime.net' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})

test('apihost: deploy-service-va6.dev.app-builder.corp.adp.adobe.io/runtime', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'https://deploy-service-va6.dev.app-builder.corp.adp.adobe.io/runtime' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})

test('apihost: deploy-service-va6.stg.app-builder.corp.adp.adobe.io/runtime', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'https://deploy-service-va6.stg.app-builder.corp.adp.adobe.io/runtime' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})

test('apihost: deploy-service-va6.app-builder.adp.adobe.io/runtime', () => {
const spy = jest.spyOn(fs, 'readFileSync')
const fakeCode = 'fake action code'
spy.mockImplementation(() => fakeCode)

// basic case 1 action using the annotation
const res = utils.processPackage(BASIC_PACKAGE, {}, {}, {}, false, { apihost: 'https://deploy-service-va6.app-builder.adp.adobe.io/runtime' })
expect(res).toEqual({
actions: [
{ name: 'pkg1/__secured_theaction', annotations: { 'web-export': false, 'raw-http': false }, action: fakeCode },
{ name: 'pkg1/theaction', action: '', annotations: { 'web-export': true, 'raw-http': false }, exec: { components: [HEADLESS_VALIDATOR, 'pkg1/__secured_theaction'], kind: 'sequence' } }
],
apis: [],
pkgAndDeps: [{ name: 'pkg1' }],
rules: [],
triggers: []
})
})
})

describe('syncProject', () => {
Expand Down
Loading