Skip to content
Open
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
39 changes: 31 additions & 8 deletions tools/testing-server/constants.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
const path = require('path')
const yargs = require('yargs/yargs')
const { hideBin } = require('yargs/helpers')
const fs = require('fs')
const args = yargs(hideBin(process.argv)).argv

const defaultAgentConfig = {
licenseKey: 'asdf',
applicationID: 42,
accountID: 123,
agentID: 456,
trustKey: 789
let agentConfig
if (args.B) {
try {
agentConfig = JSON.parse(args.B)
} catch (err) {
try {
agentConfig = JSON.parse(fs.readFileSync(args.B, 'utf-8'))
} catch (err) {
console.error('Failed to parse BAM config:', err)
}
}
}

/** fallback if no override was provided or override outright failed to parse correctly */
if (!agentConfig) {
agentConfig = {
Copy link
Contributor

@cwli24 cwli24 Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really to send harvest, only the application ID & licenseKey are needed. To make this .B easier to use, you shouldn't need the rest of the properties but simply provide those 2.

licenseKey: 'asdf',
applicationID: 42,
accountID: 123,
agentID: 456,
trustKey: 789
}
}
module.exports.defaultAgentConfig = defaultAgentConfig

module.exports.agentConfig = agentConfig

console.log('Starting service using agent config -- ', agentConfig)

const mockEntityGuid = () => {
return btoa(`${defaultAgentConfig.accountID}|BROWSER|APPLICATION|${Math.floor(Math.random() * 1000000)}`).replace(/=/g, '')
return btoa(`${agentConfig.accountID}|BROWSER|APPLICATION|${Math.floor(Math.random() * 1000000)}`).replace(/=/g, '')
}

module.exports.paths = {
Expand Down
10 changes: 5 additions & 5 deletions tools/testing-server/plugins/agent-injector/config-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { Transform } = require('stream')
const debugShim = require('./debug-shim')
const sslShim = require('./ssl-shim')
const {
defaultAgentConfig,
agentConfig,
loaderConfigKeys,
loaderOnlyConfigKeys
} = require('../../constants')
Expand Down Expand Up @@ -33,9 +33,9 @@ function getConfigContent (request, reply, testServer) {

const config = {
agent: `${testServer.assetServer.host}:${testServer.assetServer.port}/build/nr.js`,
beacon: `${testServer.bamServer.host}:${testServer.bamServer.port}`,
errorBeacon: `${testServer.bamServer.host}:${testServer.bamServer.port}`,
...defaultAgentConfig,
beacon: `${testServer.bamServer.host}:${testServer.bamServer.port}`, // these will be overridden by agentConfig if supplied
errorBeacon: `${testServer.bamServer.host}:${testServer.bamServer.port}`, // these will be overridden by agentConfig if supplied
...agentConfig,
...queryConfig
}

Expand Down Expand Up @@ -67,7 +67,7 @@ function getConfigContent (request, reply, testServer) {
? `NREUM.loader_config=${loaderConfigJSON};`
: ''

return `${sslShim}window.NREUM||(NREUM={});NREUM.info=${infoJSON};${loaderConfigAssignment}${
return `${sslShim()}window.NREUM||(NREUM={});NREUM.info=${infoJSON};${loaderConfigAssignment}${
testServer.config.debugShim ? debugShim : ''
}`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Transform } = require('stream')
const { defaultInitBlock } = require('../../constants')
const { deepmerge } = require('deepmerge-ts')
const { deserialize } = require('../../../shared/serializer.js')
const sslShim = require('./ssl-shim.js')

/**
* Constructs the agent init script block based on the init query.
Expand Down Expand Up @@ -35,7 +36,7 @@ function getInitContent (request, reply, testServer) {

initJSON = initJSON.replace(/"new RegExp\((.*?)\)"/g, 'new RegExp($1)')

return `window.NREUM||(NREUM={});NREUM.init=${initJSON};NREUM.init.ssl=false;`
return sslShim(initJSON)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function (request, reply, testServer) {
function replaceLoaderPlaceholder (chunkString, loaderScript) {
return chunkString.replace(
'{loader}',
`<script type="text/javascript" ${nonce}>${sslShim}</script>${loaderScript}`
`<script type="text/javascript" ${nonce}>${sslShim()}</script>${loaderScript}`
)
}
while (chunkString.indexOf('{loader}') > -1) {
Expand Down
6 changes: 5 additions & 1 deletion tools/testing-server/plugins/agent-injector/ssl-shim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const yargs = require('yargs')
const { hideBin } = require('yargs/helpers')
const args = yargs(hideBin(process.argv)).argv

/**
* This script is injected into test HTML pages to disable SSL in the agent.
*/
module.exports = 'window.NREUM||(NREUM={});NREUM.init||(NREUM.init={});NREUM.init.ssl=false;'
module.exports = (initString = '{}') => `window.NREUM||(NREUM={});NREUM.init||(NREUM.init=${initString});NREUM.init.ssl=${!!args.B};`
4 changes: 4 additions & 0 deletions tools/wdio/args.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const args = yargs(hideBin(process.argv))
.default('webview', false)
.describe('webview', 'Run webview tests')

.string('B')
.alias('B', 'report-to-bam')
.describe('B', 'Supply a JSON string or file path with expected BAM configs to send agent traffic to BAM instead of local service')

.middleware(argv => {
if (argv.webview && (!argv.browsers || argv.browsers === 'chrome@latest')) {
argv.browsers = argv.b = 'ios@latest,android@latest'
Expand Down
Loading