diff --git a/src/BaseCommand.js b/src/BaseCommand.js index d78354045..83c1e5b6d 100644 --- a/src/BaseCommand.js +++ b/src/BaseCommand.js @@ -21,7 +21,7 @@ const STAGE_LAUNCH_PREFIX = 'https://experience-stage.adobe.com/?devMode=true#/c const appConfig = require('@adobe/aio-cli-lib-app-config') const inquirer = require('inquirer') const { CONSOLE_API_KEYS, APPLICATION_CONFIG_KEY, EXTENSIONS_CONFIG_KEY } = require('./lib/defaults') -const { getCliInfo } = require('./lib/app-helper') +const { getAccessToken } = require('./lib/auth-helper') const LibConsoleCLI = require('@adobe/aio-cli-lib-console') const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app', { provider: 'debug' }) @@ -54,7 +54,7 @@ class BaseCommand extends Command { async getLibConsoleCLI () { if (!this.consoleCLI) { // requires valid login - const { accessToken, env } = await getCliInfo() + const { accessToken, env } = await getAccessToken() // init console CLI sdk consoleCLI this.consoleCLI = await LibConsoleCLI.init({ accessToken, env, apiKey: CONSOLE_API_KEYS[env] }) } diff --git a/src/commands/app/config/get/log-forwarding.js b/src/commands/app/config/get/log-forwarding.js index 4e962df2a..7962e4589 100644 --- a/src/commands/app/config/get/log-forwarding.js +++ b/src/commands/app/config/get/log-forwarding.js @@ -16,10 +16,7 @@ const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper class LogForwardingCommand extends BaseCommand { async run () { let aioConfig = (await this.getFullConfig()).aio - // TODO: remove this check once the deploy service is enabled by default - if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { - aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) - } + aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) const lf = await LogForwarding.init(aioConfig) const localConfig = lf.getLocalConfig() diff --git a/src/commands/app/config/get/log-forwarding/errors.js b/src/commands/app/config/get/log-forwarding/errors.js index 327941fcc..f35ab16df 100644 --- a/src/commands/app/config/get/log-forwarding/errors.js +++ b/src/commands/app/config/get/log-forwarding/errors.js @@ -32,10 +32,7 @@ class ErrorsCommand extends BaseCommand { async getLogForwarding () { let aioConfig = (await this.getFullConfig()).aio - // TODO: remove this check once the deploy service is enabled by default - if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { - aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) - } + aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) const runtimeConfig = aioConfig.runtime rtLib.utils.checkOpenWhiskCredentials({ ow: runtimeConfig }) diff --git a/src/commands/app/config/set/log-forwarding.js b/src/commands/app/config/set/log-forwarding.js index d47e5cfde..b64de2210 100644 --- a/src/commands/app/config/set/log-forwarding.js +++ b/src/commands/app/config/set/log-forwarding.js @@ -17,10 +17,7 @@ const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper class LogForwardingCommand extends BaseCommand { async run () { let aioConfig = (await this.getFullConfig()).aio - // TODO: remove this check once the deploy service is enabled by default - if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { - aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) - } + aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig) const lf = await LogForwarding.init(aioConfig) const destination = await this.promptDestination(lf.getSupportedDestinations()) diff --git a/src/commands/app/deploy.js b/src/commands/app/deploy.js index 2ae040542..cdffff6b9 100644 --- a/src/commands/app/deploy.js +++ b/src/commands/app/deploy.js @@ -18,11 +18,11 @@ const BaseCommand = require('../../BaseCommand') const BuildCommand = require('./build') const webLib = require('@adobe/aio-lib-web') const { Flags } = require('@oclif/core') -const { runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata, getCliInfo, getFilesCountWithExtension } = require('../../lib/app-helper') +const { runInProcess, buildExtensionPointPayloadWoMetadata, buildExcShellViewExtensionMetadata, getFilesCountWithExtension } = require('../../lib/app-helper') const rtLib = require('@adobe/aio-lib-runtime') const LogForwarding = require('../../lib/log-forwarding') const { sendAppAssetsDeployedAuditLog, sendAppDeployAuditLog } = require('../../lib/audit-logger') -const { setRuntimeApiHostAndAuthHandler } = require('../../lib/auth-helper') +const { setRuntimeApiHostAndAuthHandler, getAccessToken } = require('../../lib/auth-helper') const logActions = require('../../lib/log-actions') const PRE_DEPLOY_EVENT_REG = 'pre-deploy-event-reg' @@ -54,7 +54,7 @@ class Deploy extends BuildCommand { try { const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig() - const cliDetails = await getCliInfo(flags.publish) + const cliDetails = await getAccessToken({ useCachedToken: flags.publish }) const appInfo = { name: packageJson.name, version: packageJson.version, @@ -84,10 +84,7 @@ class Deploy extends BuildCommand { if (aioConfig?.project?.workspace && flags['log-forwarding-update'] && flags.actions) { spinner.start('Updating log forwarding configuration') try { - let lfConfig = aioConfig - if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { - lfConfig = setRuntimeApiHostAndAuthHandler(aioConfig) - } + const lfConfig = setRuntimeApiHostAndAuthHandler(aioConfig) const lf = await LogForwarding.init(lfConfig) if (lf.isLocalConfigChanged()) { @@ -129,7 +126,7 @@ class Deploy extends BuildCommand { // - break into smaller pieces deploy, allowing to first deploy all actions then all web assets for (let i = 0; i < keys.length; ++i) { const k = keys[i] - const v = process.env.IS_DEPLOY_SERVICE_ENABLED === 'true' ? setRuntimeApiHostAndAuthHandler(values[i]) : values[i] + const v = setRuntimeApiHostAndAuthHandler(values[i]) await this.deploySingleConfig(k, v, flags, spinner) if (cliDetails?.accessToken && v.app.hasFrontend && flags['web-assets']) { diff --git a/src/commands/app/undeploy.js b/src/commands/app/undeploy.js index fdf92eae6..5d93f8b25 100644 --- a/src/commands/app/undeploy.js +++ b/src/commands/app/undeploy.js @@ -17,10 +17,10 @@ const { Flags } = require('@oclif/core') const BaseCommand = require('../../BaseCommand') const webLib = require('@adobe/aio-lib-web') -const { runInProcess, buildExtensionPointPayloadWoMetadata, getCliInfo } = require('../../lib/app-helper') +const { runInProcess, buildExtensionPointPayloadWoMetadata } = require('../../lib/app-helper') const rtLib = require('@adobe/aio-lib-runtime') const { sendAppAssetsUndeployedAuditLog, sendAppUndeployAuditLog } = require('../../lib/audit-logger') -const { setRuntimeApiHostAndAuthHandler } = require('../../lib/auth-helper') +const { setRuntimeApiHostAndAuthHandler, getAccessToken } = require('../../lib/auth-helper') class Undeploy extends BaseCommand { async run () { @@ -52,7 +52,7 @@ class Undeploy extends BaseCommand { const spinner = ora() try { const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig() - const cliDetails = await getCliInfo(flags.unpublish) + const cliDetails = await getAccessToken({ useCachedToken: flags.unpublish }) const appInfo = { name: packageJson.name, version: packageJson.version, @@ -80,7 +80,7 @@ class Undeploy extends BaseCommand { for (let i = 0; i < keys.length; ++i) { const k = keys[i] // TODO: remove this check once the deploy service is enabled by default - const v = process.env.IS_DEPLOY_SERVICE_ENABLED === 'true' ? setRuntimeApiHostAndAuthHandler(values[i]) : values[i] + const v = setRuntimeApiHostAndAuthHandler(values[i]) await this.undeployOneExt(k, v, flags, spinner) if (cliDetails?.accessToken) { diff --git a/src/lib/app-helper.js b/src/lib/app-helper.js index 4b236e900..0fd457481 100644 --- a/src/lib/app-helper.js +++ b/src/lib/app-helper.js @@ -14,13 +14,10 @@ const fs = require('fs-extra') const path = require('node:path') const which = require('which') const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:lib-app-helper', { provider: 'debug' }) -const { getToken, context } = require('@adobe/aio-lib-ims') -const { CLI } = require('@adobe/aio-lib-ims/src/context') const chalk = require('chalk') const aioConfig = require('@adobe/aio-lib-core-config') const { AIO_CONFIG_WORKSPACE_SERVICES, AIO_CONFIG_ORG_SERVICES } = require('./defaults') const { EOL } = require('os') -const { getCliEnv } = require('@adobe/aio-lib-env') const yaml = require('js-yaml') const RuntimeLib = require('@adobe/aio-lib-runtime') @@ -179,33 +176,6 @@ function wrapError (err) { return new Error(message) } -/** - * getCliInfo - * - * @private - * - * @param {boolean} useForce - if true, user will be forced to login if not already logged in - * @returns {Promise<{accessToken: string, env: string}>} accessToken and env -*/ -async function getCliInfo (useForce = true) { - const env = getCliEnv() - let accessToken - await context.setCli({ 'cli.bare-output': true }, false) // set this globally - if (useForce) { - aioLogger.debug('Retrieving CLI Token using force=true') - accessToken = await getToken(CLI) - } else { - aioLogger.debug('Retrieving CLI Token using force=false') - // in this case, the user might be logged in, but we don't want to force them - // we just check the config for the token ( we still use the cli context so we don't need to know - // the inner workings of ims-lib and where it stores access tokens) - // todo: this is a workaround, we should have a better way to check if the user is logged in (in ims-lib) - const contextConfig = await context.getCli() - accessToken = contextConfig?.access_token?.token - } - return { accessToken, env } -} - /** * Joins url path parts * @@ -545,7 +515,6 @@ module.exports = { runInProcess, runPackageScript, wrapError, - getCliInfo, removeProtocolFromURL, urlJoin, checkFile, diff --git a/src/lib/audit-logger.js b/src/lib/audit-logger.js index dfd014c00..de91867b1 100644 --- a/src/lib/audit-logger.js +++ b/src/lib/audit-logger.js @@ -16,9 +16,10 @@ const OPERATIONS = { AB_APP_ASSETS_UNDEPLOYED: 'ab_app_assets_undeployed' } +const AUDIT_SERVICE_ENDPOINT_ROUTE = '/audit-log-api/event-post' const AUDIT_SERVICE_ENDPOINTS = { - stage: process.env.AUDIT_SERVICE_ENDPOINT_STAGE ?? 'https://deploy-service.stg.app-builder.corp.adp.adobe.io/audit-log-api/event-post', - prod: process.env.AUDIT_SERVICE_ENDPOINT_PROD ?? 'https://deploy-service.app-builder.adp.adobe.io/audit-log-api/event-post' + stage: 'https://deploy-service.stg.app-builder.corp.adp.adobe.io', + prod: 'https://deploy-service.app-builder.adp.adobe.io' } /** @@ -52,31 +53,6 @@ const AUDIT_SERVICE_ENDPOINTS = { * @property {string} operation - Operation type: 'ab_app_deploy', 'ab_app_undeploy', 'ab_app_assets_deployed', or 'ab_app_assets_undeployed' */ -/** - * Checks for environment variable overrides of audit service endpoints and logs warnings if found. - * - * This function checks for the following environment variables: - * - AUDIT_SERVICE_ENDPOINT_STAGE: Override for the stage environment endpoint - * - AUDIT_SERVICE_ENDPOINT_PROD: Override for the production environment endpoint - * - * If any of these variables are set, a warning will be logged to the console indicating - * which variables are being overridden and their values. - * - * @function checkOverrides - * @returns {void} - */ -function checkOverrides () { - const toCheck = ['AUDIT_SERVICE_ENDPOINT_STAGE', 'AUDIT_SERVICE_ENDPOINT_PROD'] - const overrides = toCheck.filter((toCheck) => process.env[toCheck]) - - if (overrides.length > 0) { - console.warn('Audit Service overrides detected:') - overrides.forEach((override) => { - console.warn(` ${override}: ${process.env[override]}`) - }) - } -} - /** * Publish audit log events to audit service * @@ -85,9 +61,14 @@ function checkOverrides () { * @throws {Error} If the audit log request fails */ async function publishAuditLogs ({ accessToken, logEvent, env = 'prod' }) { - checkOverrides() + let url = AUDIT_SERVICE_ENDPOINTS[env] ?? AUDIT_SERVICE_ENDPOINTS.prod + if (process.env.AIO_DEPLOY_SERVICE_URL) { + url = process.env.AIO_DEPLOY_SERVICE_URL + } + + // add the route to the endpoint + url += AUDIT_SERVICE_ENDPOINT_ROUTE - const url = AUDIT_SERVICE_ENDPOINTS[env] ?? AUDIT_SERVICE_ENDPOINTS.prod const payload = { event: logEvent } @@ -208,11 +189,12 @@ async function sendAppAssetsUndeployedAuditLog ({ accessToken, cliCommandFlags, module.exports = { OPERATIONS, + AUDIT_SERVICE_ENDPOINT_ROUTE, AUDIT_SERVICE_ENDPOINTS, + publishAuditLogs, getAuditLogEvent, sendAppDeployAuditLog, sendAppUndeployAuditLog, sendAppAssetsDeployedAuditLog, - sendAppAssetsUndeployedAuditLog, - checkOverrides + sendAppAssetsUndeployedAuditLog } diff --git a/src/lib/auth-helper.js b/src/lib/auth-helper.js index 73c987365..27b55caf4 100644 --- a/src/lib/auth-helper.js +++ b/src/lib/auth-helper.js @@ -12,7 +12,45 @@ governing permissions and limitations under the License. const { getToken, context } = require('@adobe/aio-lib-ims') const { CLI } = require('@adobe/aio-lib-ims/src/context') const { getCliEnv } = require('@adobe/aio-lib-env') -const defaultRuntimeUrl = 'https://adobeioruntime.net' +const defaultDeployServiceUrl = 'https://deploy-service.app-builder.adp.adobe.io' +const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:auth-helper', { provider: 'debug' }) + +/** + * Retrieves an access token for Adobe I/O CLI authentication. + * This function handles both CLI and custom contexts, setting up the appropriate + * authentication context and retrieving the corresponding access token. + * + * @async + * @function getAccessToken + * @param {object} [options] - Options for token retrieval + * @param {boolean} [options.useCachedToken=false] - Whether to use a cached token instead of requesting a new one + * @returns {Promise<{accessToken: string|null, env: string}>} An object containing: + * - accessToken: The retrieved access token for authentication, or null if token retrieval failed + * - env: The current CLI environment (e.g. 'prod', 'stage') + * @throws {Error} If token retrieval fails or context setup fails + */ +async function getAccessToken ({ useCachedToken = false } = {}) { + const env = getCliEnv() + aioLogger.debug(`Retrieving CLI Token using env=${env}`) + + let contextName = CLI // default + const currentContext = await context.getCurrent() // potential override + if (currentContext !== CLI) { + contextName = currentContext + } else { + await context.setCli({ 'cli.bare-output': true }, false) // set this globally + } + + let accessToken = null + if (useCachedToken) { + const contextConfig = await context.get(contextName) + accessToken = contextConfig?.access_token?.token + } else { + accessToken = await getToken(contextName) + } + + return { accessToken, env } +} /** * For use with the openwhisk client js library to send a bearer token instead of basic @@ -20,44 +58,31 @@ const defaultRuntimeUrl = 'https://adobeioruntime.net' */ const bearerAuthHandler = { getAuthHeader: async () => { - await context.setCli({ 'cli.bare-output': true }, false) // set this globally - - const env = getCliEnv() - - console.debug(`Retrieving CLI Token using env=${env}`) - const accessToken = await getToken(CLI) + const { accessToken } = await getAccessToken() return `Bearer ${accessToken}` } } const setRuntimeApiHostAndAuthHandler = (config) => { - // TODO: remove this check once the deploy service is enabled by default - if (process.env.IS_DEPLOY_SERVICE_ENABLED === 'true') { - const aioConfig = (config && 'runtime' in config) ? config : null - if (aioConfig) { - aioConfig.runtime.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl - aioConfig.runtime.auth_handler = bearerAuthHandler - return aioConfig - } - const owConfig = (config && 'ow' in config) ? config : null - if (owConfig) { - owConfig.ow.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl - owConfig.ow.auth_handler = bearerAuthHandler - return owConfig - } - } else { - if (config && config.runtime) { - config.runtime.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl - } - if (config && config.ow) { - config.ow.apihost = process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl - } + const aioConfig = (config && 'runtime' in config) ? config : null + if (aioConfig) { + const apiEndpoint = process.env.AIO_DEPLOY_SERVICE_URL ?? defaultDeployServiceUrl + aioConfig.runtime.apihost = `${apiEndpoint}/runtime` + aioConfig.runtime.auth_handler = bearerAuthHandler + return aioConfig + } + const owConfig = (config && 'ow' in config) ? config : null + if (owConfig) { + const apiEndpoint = process.env.AIO_DEPLOY_SERVICE_URL ?? defaultDeployServiceUrl + owConfig.ow.apihost = `${apiEndpoint}/runtime` + owConfig.ow.auth_handler = bearerAuthHandler + return owConfig } - return config } module.exports = { + getAccessToken, bearerAuthHandler, setRuntimeApiHostAndAuthHandler } diff --git a/test/commands/app/add/service.test.js b/test/commands/app/add/service.test.js index 714ecc3c4..3c40314af 100644 --- a/test/commands/app/add/service.test.js +++ b/test/commands/app/add/service.test.js @@ -62,10 +62,12 @@ jest.mock('../../../../src/lib/import') // mock login - mocks underlying methods behind getCliInfo const mockAccessToken = 'some-access-token' const mockSetCli = jest.fn() +const mockGetCurrent = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { - setCli: () => mockSetCli() + setCli: () => mockSetCli(), + getCurrent: () => mockGetCurrent() }, getToken: () => mockAccessToken } diff --git a/test/commands/app/config/get/log-forwarding.test.js b/test/commands/app/config/get/log-forwarding.test.js index af5532a82..b6ea5a646 100644 --- a/test/commands/app/config/get/log-forwarding.test.js +++ b/test/commands/app/config/get/log-forwarding.test.js @@ -13,7 +13,6 @@ governing permissions and limitations under the License. const { stdout } = require('stdout-stderr') const TheCommand = require('../../../../../src/commands/app/config/get/log-forwarding.js') const LogForwarding = require('../../../../../src/lib/log-forwarding') -const { setRuntimeApiHostAndAuthHandler } = require('../../../../../src/lib/auth-helper') jest.mock('../../../../../src/lib/log-forwarding', () => { const orig = jest.requireActual('../../../../../src/lib/log-forwarding') @@ -23,10 +22,6 @@ jest.mock('../../../../../src/lib/log-forwarding', () => { } }) -jest.mock('../../../../../src/lib/auth-helper', () => ({ - setRuntimeApiHostAndAuthHandler: jest.fn(config => config) -})) - let command, lf beforeEach(async () => { command = new TheCommand([]) @@ -195,21 +190,6 @@ test('failed to get log forwarding settings', async () => { await expect(command.run()).rejects.toThrow('mocked error') }) -test('get log forwarding settings with deploy service enabled', async () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = 'true' - const localConfig = new LogForwarding.LogForwardingConfig() - const serverConfig = new LogForwarding.LogForwardingConfig() - - lf.getLocalConfig.mockReturnValue(localConfig) - lf.getServerConfig.mockResolvedValue(serverConfig) - - await command.run() - expect(setRuntimeApiHostAndAuthHandler).toHaveBeenCalledWith(command.appConfig.aio) - expect(LogForwarding.init).toHaveBeenCalledWith(command.appConfig.aio) - - delete process.env.IS_DEPLOY_SERVICE_ENABLED -}) - test('command aliases are set correctly', () => { expect(TheCommand.aliases).toEqual(['app:config:get:log-forwarding', 'app:config:get:lf']) }) diff --git a/test/commands/app/config/get/log-forwarding/errors.test.js b/test/commands/app/config/get/log-forwarding/errors.test.js index 47ad8d3ec..4d69d44c8 100644 --- a/test/commands/app/config/get/log-forwarding/errors.test.js +++ b/test/commands/app/config/get/log-forwarding/errors.test.js @@ -13,7 +13,6 @@ governing permissions and limitations under the License. const { stdout } = require('stdout-stderr') const TheCommand = require('../../../../../../src/commands/app/config/get/log-forwarding/errors.js') const rtLib = require('@adobe/aio-lib-runtime') -const { setRuntimeApiHostAndAuthHandler } = require('../../../../../../src/lib/auth-helper') jest.mock('@adobe/aio-lib-runtime', () => ({ init: jest.fn(), @@ -22,10 +21,6 @@ jest.mock('@adobe/aio-lib-runtime', () => ({ } })) -jest.mock('../../../../../../src/lib/auth-helper', () => ({ - setRuntimeApiHostAndAuthHandler: jest.fn(config => config) -})) - let command, logForwarding beforeEach(async () => { command = new TheCommand([]) @@ -79,22 +74,6 @@ test('get log forwarding errors without configured forwarder', async () => { expect(stdout.output).toContain('Error 1') }) -test('get log forwarding errors with deploy service enabled', async () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = 'true' - logForwarding.getErrors.mockResolvedValue({ - errors: [] - }) - - await command.run() - expect(setRuntimeApiHostAndAuthHandler).toHaveBeenCalledWith(command.appConfig.aio) - expect(rtLib.init).toHaveBeenCalledWith({ - ...command.appConfig.aio.runtime, - api_key: command.appConfig.aio.runtime.auth - }) - - delete process.env.IS_DEPLOY_SERVICE_ENABLED -}) - test('failed to get log forwarding errors', async () => { logForwarding.getErrors.mockRejectedValue(new Error('mocked error')) await expect(command.run()).rejects.toThrow('mocked error') diff --git a/test/commands/app/config/set/log-forwarding.test.js b/test/commands/app/config/set/log-forwarding.test.js index 14efbafd9..6f43dac9d 100644 --- a/test/commands/app/config/set/log-forwarding.test.js +++ b/test/commands/app/config/set/log-forwarding.test.js @@ -27,6 +27,8 @@ jest.mock('../../../../../src/lib/log-forwarding', () => { let command, lf beforeEach(async () => { + authHelper.setRuntimeApiHostAndAuthHandler.mockClear() + command = new TheCommand([]) command.appConfig = { aio: { @@ -90,11 +92,10 @@ test('set log forwarding destination and save local', async () => { expect(setCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, input)) expect(localSetCall).toHaveBeenCalledTimes(1) expect(localSetCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, fullSanitizedSettings)) - expect(authHelper.setRuntimeApiHostAndAuthHandler).not.toHaveBeenCalled() + expect(authHelper.setRuntimeApiHostAndAuthHandler).toHaveBeenCalledTimes(1) }) -test('should Invoke setRuntimeApiHostAndAuthHandler if IS_DEPLOY_SERVICE_ENABLED = ture and set log forwarding destination', async () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = true +test('should invoke setRuntimeApiHostAndAuthHandler and set log forwarding destination', async () => { const destination = 'destination' const input = { field_one: 'val_one', @@ -133,7 +134,6 @@ test('should Invoke setRuntimeApiHostAndAuthHandler if IS_DEPLOY_SERVICE_ENABLED expect(localSetCall).toHaveBeenCalledTimes(1) expect(localSetCall).toHaveBeenCalledWith(new LogForwarding.LogForwardingConfig(destination, fullSanitizedSettings)) expect(authHelper.setRuntimeApiHostAndAuthHandler).toHaveBeenCalledTimes(1) - process.env.IS_DEPLOY_SERVICE_ENABLED = false }) test('set log forwarding destination and fail save local', async () => { diff --git a/test/commands/app/delete/service.test.js b/test/commands/app/delete/service.test.js index 85ac7ceb3..1c8527180 100644 --- a/test/commands/app/delete/service.test.js +++ b/test/commands/app/delete/service.test.js @@ -55,10 +55,12 @@ function setDefaultMockConfig () { // mock login - mocks underlying methods behind getCliInfo const mockAccessToken = 'some-access-token' const mockSetCli = jest.fn() +const mockGetCurrent = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { - setCli: () => mockSetCli() + setCli: () => mockSetCli(), + getCurrent: () => mockGetCurrent() }, getToken: () => mockAccessToken } diff --git a/test/commands/app/deploy.test.js b/test/commands/app/deploy.test.js index e6ac8887a..4d05c2c44 100644 --- a/test/commands/app/deploy.test.js +++ b/test/commands/app/deploy.test.js @@ -167,7 +167,6 @@ beforeEach(() => { helpers.buildExtensionPointPayloadWoMetadata.mockReset() helpers.buildExcShellViewExtensionMetadata.mockReset() helpers.createWebExportFilter.mockReset() - helpers.getCliInfo.mockReset() mockLogForwarding.isLocalConfigChanged.mockReset() mockLogForwarding.getLocalConfigWithSecrets.mockReset() mockLogForwarding.updateServerConfig.mockReset() @@ -185,7 +184,7 @@ beforeEach(() => { ] }) authHelper.setRuntimeApiHostAndAuthHandler.mockImplementation((aioConfig) => aioConfig) - helpers.getCliInfo.mockImplementation(() => { + authHelper.getAccessToken.mockImplementation(() => { return { accessToken: 'mocktoken', env: 'stage' @@ -1257,88 +1256,6 @@ describe('run', () => { expect(command.error).toHaveBeenCalledTimes(1) }) - test('Should invoke setRuntimeApiHostAndAuthHandler if IS_DEPLOY_SERVICE_ENABLED = true', async () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = true - - const mockToken = 'mocktoken' - const mockEnv = 'stage' - const mockOrg = 'mockorg' - const mockProject = 'mockproject' - const mockWorkspaceId = 'mockworkspaceid' - const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ - accessToken: mockToken, - env: mockEnv - }) - const fullConfig = { - aio: { - project: { - id: mockProject, - org: { - id: mockOrg - }, - workspace: { - id: mockWorkspaceId, - name: mockWorkspaceName - } - } - }, - packagejson: { - name: 'test-app', - version: '1.0.0' - } - } - command.getFullConfig = jest.fn().mockReturnValue(fullConfig) - command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig)) - - await command.run() - expect(command.error).toHaveBeenCalledTimes(0) - expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1) - expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(1) - expect(auditLogger.sendAppAssetsDeployedAuditLog).toHaveBeenCalledTimes(1) - expect(authHelper.setRuntimeApiHostAndAuthHandler).toHaveBeenCalledTimes(2) // once in logforwarding, once when deploying - expect(auditLogger.sendAppAssetsDeployedAuditLog).toHaveBeenCalledWith({ - accessToken: mockToken, - appInfo: { - name: 'test-app', - version: '1.0.0', - runtimeNamespace: undefined, - project: { - id: mockProject, - org: { - id: mockOrg - }, - workspace: { - id: mockWorkspaceId, - name: mockWorkspaceName - } - } - }, - cliCommandFlags: { - actions: true, - build: true, - 'content-hash': true, - 'force-build': true, - 'force-deploy': false, - 'force-events': false, - 'force-publish': false, - 'log-forwarding-update': true, - open: false, - publish: false, - 'web-assets': true, - 'web-optimize': false - }, - env: mockEnv, - opItems: [ - '3 Javascript file(s)', - '2 CSS file(s)', - '5 image(s)', - '1 HTML page(s)' - ] - }) - process.env.IS_DEPLOY_SERVICE_ENABLED = false - }) - test('Send audit logs for successful app deploy', async () => { const mockToken = 'mocktoken' const mockEnv = 'stage' @@ -1346,7 +1263,7 @@ describe('run', () => { const mockProject = 'mockproject' const mockWorkspaceId = 'mockworkspaceid' const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) @@ -1426,7 +1343,7 @@ describe('run', () => { const mockWorkspaceId = 'mockworkspaceid' const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) @@ -1469,7 +1386,7 @@ describe('run', () => { command.argv = ['--web-assets'] - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) @@ -1548,7 +1465,7 @@ describe('run', () => { const mockProject = 'mockproject' const mockWorkspaceId = 'mockworkspaceid' const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) @@ -1601,7 +1518,7 @@ describe('run', () => { const mockProject = 'mockproject' const mockWorkspaceId = 'mockworkspaceid' const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) @@ -1653,7 +1570,7 @@ describe('run', () => { const mockProject = 'mockproject' const mockWorkspaceId = 'mockworkspaceid' const mockWorkspaceName = 'mockworkspacename' - helpers.getCliInfo.mockResolvedValueOnce({ + authHelper.getAccessToken.mockResolvedValueOnce({ accessToken: mockToken, env: mockEnv }) diff --git a/test/commands/app/undeploy.test.js b/test/commands/app/undeploy.test.js index 33b2a6f1f..7de9dc573 100644 --- a/test/commands/app/undeploy.test.js +++ b/test/commands/app/undeploy.test.js @@ -87,7 +87,7 @@ beforeEach(() => { auditLogger.getAuditLogEvent.mockImplementation((flags, project, event) => { return { orgId: 'mockorg', projectId: 'mockproject', workspaceId: 'mockworkspaceid', workspaceName: 'mockworkspacename' } }) - helpers.getCliInfo.mockImplementation(() => { + authHelper.getAccessToken.mockImplementation(() => { return { accessToken: 'mocktoken', env: 'stage' @@ -513,42 +513,6 @@ describe('run', () => { expect(command.error).toHaveBeenCalledTimes(1) }) - test('Should invoke setRuntimeApiHostAndAuthHandler if IS_DEPLOY_SERVICE_ENABLED = true', async () => { - const mockOrg = 'mockorg' - const mockProject = 'mockproject' - const mockWorkspaceId = 'mockworkspaceid' - const mockWorkspaceName = 'mockworkspacename' - - process.env.IS_DEPLOY_SERVICE_ENABLED = true - - command.getFullConfig = jest.fn().mockReturnValue({ - aio: { - project: { - id: mockProject, - org: { - id: mockOrg - }, - workspace: { - id: mockWorkspaceId, - name: mockWorkspaceName - } - } - }, - packagejson: { - name: 'test-app', - version: '1.0.0' - } - }) - command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig)) - - await command.run() - expect(command.error).toHaveBeenCalledTimes(0) - expect(mockRuntimeLib.undeployActions).toHaveBeenCalledTimes(1) - expect(mockWebLib.undeployWeb).toHaveBeenCalledTimes(1) - expect(authHelper.setRuntimeApiHostAndAuthHandler).toHaveBeenCalledTimes(1) - process.env.IS_DEPLOY_SERVICE_ENABLED = false - }) - test('Send audit logs for successful app undeploy', async () => { const mockToken = 'mocktoken' const mockEnv = 'stage' @@ -636,7 +600,7 @@ describe('run', () => { } }) command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig)) - helpers.getCliInfo.mockImplementationOnce(() => null) + authHelper.getAccessToken.mockImplementationOnce(() => null) await command.run() expect(command.error).toHaveBeenCalledTimes(0) diff --git a/test/commands/app/use.test.js b/test/commands/app/use.test.js index eaee6ce0b..7a3a4a0a3 100644 --- a/test/commands/app/use.test.js +++ b/test/commands/app/use.test.js @@ -85,11 +85,13 @@ function setConfigMock () { const mockAccessToken = 'some-access-token' const mockGetCli = jest.fn() const mockSetCli = jest.fn() +const mockGetCurrent = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { getCli: () => mockGetCli(), - setCli: () => mockSetCli() + setCli: () => mockSetCli(), + getCurrent: () => mockGetCurrent() }, getToken: () => mockAccessToken } diff --git a/test/commands/lib/app-helper.test.js b/test/commands/lib/app-helper.test.js index f7fd53ec6..ca69cf745 100644 --- a/test/commands/lib/app-helper.test.js +++ b/test/commands/lib/app-helper.test.js @@ -676,32 +676,6 @@ describe('writeConfig', () => { }) }) -describe('getCliInfo', () => { - test('prod', async () => { - libEnv.getCliEnv.mockReturnValue('prod') - libIms.getToken.mockResolvedValue('token') - const res = await appHelper.getCliInfo() - expect(res).toEqual( - { accessToken: 'token', env: 'prod' } - ) - }) - test('stage', async () => { - libEnv.getCliEnv.mockReturnValue('stage') - libIms.getToken.mockResolvedValue('stoken') - const res = await appHelper.getCliInfo() - expect(res).toEqual( - { accessToken: 'stoken', env: 'stage' } - ) - }) - test('useForceFalse', async () => { - libEnv.getCliEnv.mockReturnValue('prod') - libIms.getToken.mockResolvedValue('asdasd') - const res = await appHelper.getCliInfo(false) - expect(res).toEqual({ accessToken: undefined, env: 'prod' }) - expect(libIms.getToken).toHaveBeenCalledTimes(0) - }) -}) - describe('createWebExportFilter', () => { const webFilter = appHelper.createWebExportFilter(true) const nonWebFilter = appHelper.createWebExportFilter(false) diff --git a/test/commands/lib/audit-logger.test.js b/test/commands/lib/audit-logger.test.js index c0b2c4298..79a63533f 100644 --- a/test/commands/lib/audit-logger.test.js +++ b/test/commands/lib/audit-logger.test.js @@ -11,13 +11,14 @@ governing permissions and limitations under the License. const { OPERATIONS, + AUDIT_SERVICE_ENDPOINT_ROUTE, AUDIT_SERVICE_ENDPOINTS, getAuditLogEvent, sendAppDeployAuditLog, sendAppUndeployAuditLog, sendAppAssetsDeployedAuditLog, sendAppAssetsUndeployedAuditLog, - checkOverrides + publishAuditLogs } = require('../../../src/lib/audit-logger') beforeEach(() => { @@ -42,49 +43,6 @@ describe('audit-logger', () => { } const mockCliFlags = { flag1: 'value1' } - describe('checkOverrides', () => { - const originalEnv = process.env - - beforeEach(() => { - jest.resetModules() // Clears any cached modules - process.env = { ...originalEnv } // Copies the original environment variables - jest.spyOn(console, 'warn').mockImplementation() - }) - - afterEach(() => { - process.env = originalEnv // Restores the original environment variables - console.warn.mockRestore() - }) - - it('should not log warnings when no environment variables are set', () => { - checkOverrides() - expect(console.warn).not.toHaveBeenCalled() - }) - - it('should log warning when only stage endpoint is overridden', () => { - process.env.AUDIT_SERVICE_ENDPOINT_STAGE = 'https://custom-stage-endpoint.com' - checkOverrides() - expect(console.warn).toHaveBeenCalledWith('Audit Service overrides detected:') - expect(console.warn).toHaveBeenCalledWith(' AUDIT_SERVICE_ENDPOINT_STAGE: https://custom-stage-endpoint.com') - }) - - it('should log warning when only prod endpoint is overridden', () => { - process.env.AUDIT_SERVICE_ENDPOINT_PROD = 'https://custom-prod-endpoint.com' - checkOverrides() - expect(console.warn).toHaveBeenCalledWith('Audit Service overrides detected:') - expect(console.warn).toHaveBeenCalledWith(' AUDIT_SERVICE_ENDPOINT_PROD: https://custom-prod-endpoint.com') - }) - - it('should log warnings when both endpoints are overridden', () => { - process.env.AUDIT_SERVICE_ENDPOINT_STAGE = 'https://custom-stage-endpoint.com' - process.env.AUDIT_SERVICE_ENDPOINT_PROD = 'https://custom-prod-endpoint.com' - checkOverrides() - expect(console.warn).toHaveBeenCalledWith('Audit Service overrides detected:') - expect(console.warn).toHaveBeenCalledWith(' AUDIT_SERVICE_ENDPOINT_STAGE: https://custom-stage-endpoint.com') - expect(console.warn).toHaveBeenCalledWith(' AUDIT_SERVICE_ENDPOINT_PROD: https://custom-prod-endpoint.com') - }) - }) - describe('getAuditLogEvent', () => { it('should create a valid audit log event for app deploy', () => { const event = getAuditLogEvent({ @@ -203,7 +161,7 @@ describe('audit-logger', () => { }) expect(fetch).toHaveBeenCalledWith( - AUDIT_SERVICE_ENDPOINTS.prod, + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, expect.objectContaining({ method: 'POST', headers: { @@ -226,7 +184,7 @@ describe('audit-logger', () => { }) expect(fetch).toHaveBeenCalledWith( - AUDIT_SERVICE_ENDPOINTS.prod, + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, expect.objectContaining({ method: 'POST', headers: { @@ -252,7 +210,7 @@ describe('audit-logger', () => { }) expect(fetch).toHaveBeenCalledWith( - AUDIT_SERVICE_ENDPOINTS.prod, + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, expect.objectContaining({ method: 'POST', headers: { @@ -276,7 +234,7 @@ describe('audit-logger', () => { }) expect(fetch).toHaveBeenCalledWith( - AUDIT_SERVICE_ENDPOINTS.prod, + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, expect.objectContaining({ method: 'POST', headers: { @@ -310,7 +268,7 @@ describe('audit-logger', () => { }) expect(fetch).toHaveBeenCalledWith( - AUDIT_SERVICE_ENDPOINTS.prod, + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, expect.objectContaining({ method: 'POST', headers: { @@ -321,4 +279,90 @@ describe('audit-logger', () => { ) }) }) + + describe('publishAuditLogs', () => { + const mockLogEvent = { + orgId: 'fake-org-id', + projectId: 'fake-project-id', + operation: 'test-operation' + } + + it('should publish audit logs successfully to prod environment', async () => { + setFetchMock(true, 200, {}) + + await publishAuditLogs({ + accessToken: mockAccessToken, + logEvent: mockLogEvent, + env: 'prod' + }) + + expect(fetch).toHaveBeenCalledWith( + AUDIT_SERVICE_ENDPOINTS.prod + AUDIT_SERVICE_ENDPOINT_ROUTE, + expect.objectContaining({ + method: 'POST', + headers: { + Authorization: `Bearer ${mockAccessToken}`, + 'Content-type': 'application/json' + }, + body: JSON.stringify({ event: mockLogEvent }) + }) + ) + }) + + it('should publish audit logs successfully to stage environment', async () => { + setFetchMock(true, 200, {}) + + await publishAuditLogs({ + accessToken: mockAccessToken, + logEvent: mockLogEvent, + env: 'stage' + }) + + expect(fetch).toHaveBeenCalledWith( + AUDIT_SERVICE_ENDPOINTS.stage + AUDIT_SERVICE_ENDPOINT_ROUTE, + expect.objectContaining({ + method: 'POST', + headers: { + Authorization: `Bearer ${mockAccessToken}`, + 'Content-type': 'application/json' + }, + body: JSON.stringify({ event: mockLogEvent }) + }) + ) + }) + + it('should use custom URL when AIO_DEPLOY_SERVICE_URL is set', async () => { + const customUrl = 'https://custom-service.example.com' + process.env.AIO_DEPLOY_SERVICE_URL = customUrl + setFetchMock(true, 200, {}) + + await publishAuditLogs({ + accessToken: mockAccessToken, + logEvent: mockLogEvent + }) + + expect(fetch).toHaveBeenCalledWith( + customUrl + AUDIT_SERVICE_ENDPOINT_ROUTE, + expect.objectContaining({ + method: 'POST', + headers: { + Authorization: `Bearer ${mockAccessToken}`, + 'Content-type': 'application/json' + }, + body: JSON.stringify({ event: mockLogEvent }) + }) + ) + + delete process.env.AIO_DEPLOY_SERVICE_URL + }) + + it('should throw error when audit service returns non-200 status', async () => { + setFetchMock(true, 500, 'Internal Server Error') + + await expect(publishAuditLogs({ + accessToken: mockAccessToken, + logEvent: mockLogEvent + })).rejects.toThrow('Failed to send audit log - 500 Internal Server Error') + }) + }) }) diff --git a/test/commands/lib/auth-helper.test.js b/test/commands/lib/auth-helper.test.js index 0fc41011e..42cf56ba9 100644 --- a/test/commands/lib/auth-helper.test.js +++ b/test/commands/lib/auth-helper.test.js @@ -1,4 +1,4 @@ -const { bearerAuthHandler, setRuntimeApiHostAndAuthHandler } = require('../../../src/lib/auth-helper') +const { getAccessToken, bearerAuthHandler, setRuntimeApiHostAndAuthHandler } = require('../../../src/lib/auth-helper') const { getToken, context } = require('@adobe/aio-lib-ims') const { CLI } = require('@adobe/aio-lib-ims/src/context') const { getCliEnv } = require('@adobe/aio-lib-env') @@ -6,37 +6,87 @@ const { getCliEnv } = require('@adobe/aio-lib-env') jest.mock('@adobe/aio-lib-ims') jest.mock('@adobe/aio-lib-env') -describe('bearerAuthHandler', () => { +describe('getAccessToken', () => { beforeEach(() => { jest.clearAllMocks() }) - test('getAuthHeader should return a Bearer token', async () => { + test('should get token using CLI context by default', async () => { const mockToken = 'mocked-token' + const mockEnv = 'prod' getToken.mockResolvedValue(mockToken) - getCliEnv.mockReturnValue('test-env') + getCliEnv.mockReturnValue(mockEnv) + context.getCurrent.mockResolvedValue(CLI) - const result = await bearerAuthHandler.getAuthHeader() + const result = await getAccessToken() expect(context.setCli).toHaveBeenCalledWith({ 'cli.bare-output': true }, false) expect(getCliEnv).toHaveBeenCalled() expect(getToken).toHaveBeenCalledWith(CLI) + expect(result).toEqual({ accessToken: mockToken, env: mockEnv }) + }) + + test('should use custom context if set', async () => { + const mockToken = 'mocked-token' + const mockEnv = 'prod' + const customContext = 'custom-context' + getToken.mockResolvedValue(mockToken) + getCliEnv.mockReturnValue(mockEnv) + context.getCurrent.mockResolvedValue(customContext) + + const result = await getAccessToken() + + expect(context.setCli).not.toHaveBeenCalled() + expect(getToken).toHaveBeenCalledWith(customContext) + expect(result).toEqual({ accessToken: mockToken, env: mockEnv }) + }) + + test('should use cached token when requested', async () => { + const mockToken = 'cached-token' + const mockEnv = 'prod' + const mockContext = { access_token: { token: mockToken } } + getCliEnv.mockReturnValue(mockEnv) + context.getCurrent.mockResolvedValue(CLI) + context.get.mockResolvedValue(mockContext) + + const result = await getAccessToken({ useCachedToken: true }) + + expect(getToken).not.toHaveBeenCalled() + expect(context.get).toHaveBeenCalledWith(CLI) + expect(result).toEqual({ accessToken: mockToken, env: mockEnv }) + }) +}) + +describe('bearerAuthHandler', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + test('getAuthHeader should return a Bearer token', async () => { + const mockToken = 'mocked-token' + getToken.mockResolvedValue(mockToken) + getCliEnv.mockReturnValue('prod') + context.getCurrent.mockResolvedValue(CLI) + + const result = await bearerAuthHandler.getAuthHeader() + expect(result).toBe(`Bearer ${mockToken}`) }) }) describe('setRuntimeApiHostAndAuthHandler', () => { - const defaultRuntimeUrl = 'https://adobeioruntime.net' + const defaultDeployServiceUrl = 'https://deploy-service.app-builder.adp.adobe.io' + beforeEach(() => { jest.clearAllMocks() - process.env.IS_DEPLOY_SERVICE_ENABLED = 'true' + delete process.env.AIO_DEPLOY_SERVICE_URL }) test('should set runtime.apihost and runtime.auth_handler when config has runtime', () => { const config = { runtime: {} } const result = setRuntimeApiHostAndAuthHandler(config) - expect(result.runtime.apihost).toBe(process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl) + expect(result.runtime.apihost).toBe(`${defaultDeployServiceUrl}/runtime`) expect(result.runtime.auth_handler).toBe(bearerAuthHandler) }) @@ -44,38 +94,27 @@ describe('setRuntimeApiHostAndAuthHandler', () => { const config = { ow: {} } const result = setRuntimeApiHostAndAuthHandler(config) - expect(result.ow.apihost).toBe(process.env.AIO_RUNTIME_APIHOST ?? defaultRuntimeUrl) + expect(result.ow.apihost).toBe(`${defaultDeployServiceUrl}/runtime`) expect(result.ow.auth_handler).toBe(bearerAuthHandler) }) - test('should return config unchanged when config has neither runtime nor ow', () => { - const config = { other: {} } + test('should use custom deploy service URL from environment', () => { + const customUrl = 'https://custom-deploy-service.example.com' + process.env.AIO_DEPLOY_SERVICE_URL = customUrl + const config = { runtime: {} } const result = setRuntimeApiHostAndAuthHandler(config) - expect(result).toBe(config) + expect(result.runtime.apihost).toBe(`${customUrl}/runtime`) }) - test('should return null when config is null', () => { - const result = setRuntimeApiHostAndAuthHandler(null) - - expect(result).toBeNull() + test('should return undefined when config is null or undefined', () => { + expect(setRuntimeApiHostAndAuthHandler(null)).not.toBeDefined() + expect(setRuntimeApiHostAndAuthHandler()).not.toBeDefined() }) - test('should set default runtime.apihost only config has runtime', () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = 'false' - const config = { runtime: {} } - const result = setRuntimeApiHostAndAuthHandler(config) - - expect(result.runtime.apihost).toBe(defaultRuntimeUrl) - expect(result.runtime.auth_handler).toBeUndefined() - }) - - test('should set default ow.apihost only config has openwhisk', () => { - process.env.IS_DEPLOY_SERVICE_ENABLED = 'false' - const config = { ow: {} } + test('should return undefined when config has neither runtime nor ow', () => { + const config = { other: {} } const result = setRuntimeApiHostAndAuthHandler(config) - - expect(result.ow.apihost).toBe(defaultRuntimeUrl) - expect(result.ow.auth_handler).toBeUndefined() + expect(result).not.toBeDefined() }) })