Skip to content

Commit f4af7ed

Browse files
committed
update to new changes
1 parent 96eed6a commit f4af7ed

4 files changed

Lines changed: 12 additions & 38 deletions

File tree

src/lib/constants.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ module.exports = {
4040
STAGE_LAUNCH_PREFIX: 'https://experience-stage.adobe.com/?devMode=true#/custom-apps/?localDevUrl=',
4141
PRIVATE_KEY_PATH: `${DEV_KEYS_DIR}/private.key`,
4242
PUB_CERT_PATH: `${DEV_KEYS_DIR}/cert-pub.crt`,
43-
BUNDLE_OPTIONS,
44-
IMS_OAUTH_S2S_ENV_KEY: 'IMS_OAUTH_S2S'
43+
BUNDLE_OPTIONS
4544
}

src/lib/run-dev.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const coreLogger = require('@adobe/aio-lib-core-logging')
2525
const { getReasonPhrase } = require('http-status-codes')
2626

2727
const utils = require('./app-helper')
28-
const { SERVER_HOST, SERVER_DEFAULT_PORT, BUNDLER_DEFAULT_PORT, DEV_API_PREFIX, DEV_API_WEB_PREFIX, BUNDLE_OPTIONS, CHANGED_ASSETS_PRINT_LIMIT, IMS_OAUTH_S2S_ENV_KEY } = require('./constants')
28+
const { SERVER_HOST, SERVER_DEFAULT_PORT, BUNDLER_DEFAULT_PORT, DEV_API_PREFIX, DEV_API_WEB_PREFIX, BUNDLE_OPTIONS, CHANGED_ASSETS_PRINT_LIMIT } = require('./constants')
2929
const RAW_CONTENT_TYPES = ['application/octet-stream', 'multipart/form-data']
3030

3131
// for the include-ims-credentials annotation
@@ -89,10 +89,8 @@ async function runDev (runOptions, config, _inprocHookRunner) {
8989
// ex. console.log('AIO_DEV ', process.env.AIO_DEV ? 'dev' : 'prod')
9090
process.env.AIO_DEV = 'true'
9191

92-
// for the include-ims-credentials annotation
93-
try {
94-
imsAuthObject = JSON.parse(process.env[IMS_OAUTH_S2S_ENV_KEY])
95-
} catch (e) {}
92+
// include ims credentials inputs __ims_oauth_s2s and __ims_env
93+
imsAuthObject = rtLib.utils.loadIMSCredentialsFromEnv()
9694

9795
const serverPortToUse = parseInt(process.env.PORT) || SERVER_DEFAULT_PORT
9896
const serverPort = await getPort({ port: serverPortToUse })

test/lib/constants.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const {
2323
STAGE_LAUNCH_PREFIX,
2424
PRIVATE_KEY_PATH,
2525
PUB_CERT_PATH,
26-
BUNDLE_OPTIONS,
27-
IMS_OAUTH_S2S_ENV_KEY
26+
BUNDLE_OPTIONS
2827
} = require(CONSTANTS_PATH)
2928

3029
test('exports', () => {
@@ -40,7 +39,6 @@ test('exports', () => {
4039
expect(PRIVATE_KEY_PATH).toBeDefined()
4140
expect(PUB_CERT_PATH).toBeDefined()
4241
expect(BUNDLE_OPTIONS).toBeDefined()
43-
expect(IMS_OAUTH_S2S_ENV_KEY).toBeDefined()
4442
})
4543

4644
describe('override via env vars', () => {

test/lib/run-dev.test.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,9 +1259,9 @@ describe('runDev', () => {
12591259
expect(Object.keys(actionUrls).length).toEqual(0)
12601260
})
12611261

1262-
test('parses IMS_OAUTH_S2S environment variable', async () => {
1263-
const imsAuthData = { access_token: 'test-token', org_id: 'test-org' }
1264-
process.env.IMS_OAUTH_S2S = JSON.stringify(imsAuthData)
1262+
test('calls loadIMSCredentialsFromEnv for include-ims-credentials support', async () => {
1263+
const rtLib = jest.requireActual('@adobe/aio-lib-runtime')
1264+
const loadIMSCredentialsFromEnvSpy = jest.spyOn(rtLib.utils, 'loadIMSCredentialsFromEnv')
12651265

12661266
const actionPath = fixturePath('actions/successNoReturnAction.js')
12671267
const config = createConfig({
@@ -1279,31 +1279,10 @@ describe('runDev', () => {
12791279
const { actionUrls, serverCleanup } = await runDev(runOptions, config, hookRunner)
12801280

12811281
await serverCleanup()
1282-
// Verify runDev completes successfully when IMS_OAUTH_S2S env var is set with valid JSON
1283-
expect(Object.keys(actionUrls).length).toBeGreaterThan(0)
1284-
})
1285-
1286-
test('handles invalid IMS_OAUTH_S2S JSON gracefully', async () => {
1287-
process.env.IMS_OAUTH_S2S = 'not-valid-json'
1288-
1289-
const actionPath = fixturePath('actions/successNoReturnAction.js')
1290-
const config = createConfig({
1291-
hasFrontend: false,
1292-
hasBackend: true,
1293-
packageName: 'mypackage',
1294-
actions: {
1295-
myaction: {
1296-
function: actionPath
1297-
}
1298-
}
1299-
})
1300-
const runOptions = createRunOptions({ cert: 'my-cert', key: 'my-key' })
1301-
const hookRunner = () => {}
1302-
const { actionUrls, serverCleanup } = await runDev(runOptions, config, hookRunner)
13031282

1304-
await serverCleanup()
1305-
// Verify runDev completes successfully even when IMS_OAUTH_S2S contains invalid JSON
1283+
expect(loadIMSCredentialsFromEnvSpy).toHaveBeenCalled()
13061284
expect(Object.keys(actionUrls).length).toBeGreaterThan(0)
1285+
loadIMSCredentialsFromEnvSpy.mockRestore()
13071286
})
13081287

13091288
test('no front end, has back end', async () => {
@@ -1848,8 +1827,8 @@ describe('invokeAction', () => {
18481827
const response = await invokeAction({ actionRequestContext, logger: mockLogger })
18491828

18501829
expect(getIncludeIMSCredentialsAnnotationInputsSpy).toHaveBeenCalledWith(action, expect.anything())
1851-
expect(actionParams.__ow_ims_access_token).toBeUndefined()
1852-
expect(actionParams.__ow_ims_org_id).toBeUndefined()
1830+
expect(actionParams.__ims_oauth_s2s).toBeUndefined()
1831+
expect(actionParams.__ims_env).toBeUndefined()
18531832
expect(actionParams.existingParam).toEqual('value')
18541833
expect(response.statusCode).toEqual(200)
18551834
})

0 commit comments

Comments
 (0)