Skip to content

Commit

Permalink
test: updated the cross agent tests, made updates to tests based on f…
Browse files Browse the repository at this point in the history
…ixture changes (#1917)
  • Loading branch information
bizob2828 committed Dec 15, 2023
1 parent f49fd43 commit 2d666b6
Show file tree
Hide file tree
Showing 40 changed files with 2,211 additions and 2,320 deletions.
13 changes: 9 additions & 4 deletions lib/util/sql/obfuscate.js
Expand Up @@ -12,11 +12,11 @@ const doubleQuote = /"(?:[^"]|"")*?(?:\\".*|"(?!"))/
const dollarQuote = /(\$(?!\d)[^$]*?\$).*?(?:\1|$)/
const oracleQuote = /q'\[.*?(?:\]'|$)|q'\{.*?(?:\}'|$)|q'\<.*?(?:\>'|$)|q'\(.*?(?:\)'|$)/
const comment = /(?:#|--).*?(?=\r|\n|$)/
const multilineComment = /\/\*(?:[^/]|\/[^*])*?(?:\*\/|\/\*.*)/
const multilineComment = /\/\*(?:[^\/]|\/[^*])*?(?:\*\/|\/\*.*)/
const uuid = /\{?(?:[0-9a-f]\-*){32}\}?/
const hex = /0x[0-9a-f]+/
const boolean = /true|false|null/
const number = /\b-?(?:[0-9]+\.)?[0-9]+([eE][+-]?[0-9]+)?/
const boolean = /\b(?:true|false|null)\b/
const number = /-?\b(?:[0-9]+\.)?[0-9]+(e[+-]?[0-9]+)?/

const dialects = (obfuscate.dialects = Object.create(null))

Expand All @@ -29,7 +29,7 @@ dialects.postgres = [
replacer(
join([dollarQuote, singleQuote, comment, multilineComment, uuid, boolean, number], 'gi')
),
unmatchedPairs(/'|\/\*|\*\/|(?:\$(?!\?))/)
unmatchedPairs(/'|\/\*|\*\/|\$(?!\?)/)
]

dialects.cassandra = [
Expand All @@ -42,6 +42,11 @@ dialects.oracle = [
unmatchedPairs(/'|\/\*|\*\//)
]

dialects.sqlite = [
replacer(join([singleQuote, comment, multilineComment, hex, boolean, number], 'gi')),
unmatchedPairs(/'|\/\*|\*\//)
]

dialects.default = dialects.mysql

function obfuscate(raw, dialect) {
Expand Down
Expand Up @@ -91,7 +91,7 @@ const testExpected = function (t, object, fixture) {
}

const testVendor = function (t, object, vendors) {
t.same(object.tracestate.tracing_vendors, vendors, 'do vendors match?')
t.same(object.tracestate.vendors, vendors, 'do vendors match?')
}

// tests a few of the helper functions we wrote for this test case
Expand Down Expand Up @@ -236,7 +236,7 @@ const runTestCaseOutboundPayloads = function (t, testCase, context) {
case 'notequal':
testNotEqual(t, context[key], fields)
break
case 'tracingVendors':
case 'vendors':
testVendor(t, context[key], fields)
break
default:
Expand All @@ -246,35 +246,6 @@ const runTestCaseOutboundPayloads = function (t, testCase, context) {
}
}

function runTestCaseOutboundNewrelicPayloads(t, testCase, newrelicPayloads) {
if (!testCase.outbound_newrelic_payloads) {
return
}

for (const [index, testToRun] of testCase.outbound_newrelic_payloads.entries()) {
for (const [assertType, fields] of Object.entries(testToRun)) {
const newrelicPayload = newrelicPayloads[index]

switch (assertType) {
case 'exact':
testExact(t, newrelicPayload, fields)
break
case 'expected':
testExpected(t, newrelicPayload, fields)
break
case 'unexpected':
testUnexpected(t, newrelicPayload, fields)
break
case 'notequal':
testNotEqual(t, newrelicPayload, fields)
break
default:
throw new Error('Unexpected assert type for newrelic payloads: ' + assertType)
}
}
}
}

const runTestCase = function (testCase, parentTest) {
// validates the test case data has what we're looking for. Good for
// catching any changes to the test format over time, as well as becoming
Expand All @@ -294,8 +265,7 @@ const runTestCase = function (testCase, parentTest) {
'trusted_account_key',
'web_transaction',
'comment',
'transaction_events_enabled',
'outbound_newrelic_payloads'
'transaction_events_enabled'
])

if (testCase.outbound_payloads) {
Expand All @@ -305,7 +275,7 @@ const runTestCase = function (testCase, parentTest) {
'exact',
'expected',
'notequal',
'tracingVendors',
'vendors',
'unexpected'
])
}
Expand Down Expand Up @@ -394,12 +364,8 @@ const runTestCase = function (testCase, parentTest) {

// Generate outbound payloads
const outboundTraceContextPayloads = testCase.outbound_payloads || []
const outboundNewrelicPayloads = testCase.outbound_newrelic_payloads || []

const insertCount = Math.max(
outboundTraceContextPayloads.length,
outboundNewrelicPayloads.length
)
const insertCount = Math.max(outboundTraceContextPayloads.length)

const outboundHeaders = []
for (let i = 0; i < insertCount; i++) {
Expand Down Expand Up @@ -430,7 +396,7 @@ const runTestCase = function (testCase, parentTest) {
// Found entry for the correct trust key / tenantId
// So manually setting for now
intrinsics.tenantId = tenantId
intrinsics.tracingVendors = vendors
intrinsics.vendors = vendors

// get payload for how we represent it internally to how tests want it
const outboundPayload = {
Expand Down Expand Up @@ -467,14 +433,12 @@ const runTestCase = function (testCase, parentTest) {
outboundPayload.traceparent
)

return outboundPayload
})

const insertedNewrelicTraces = outboundHeaders.map((headers) => {
if (headers.newrelic) {
const rawPayload = Buffer.from(headers.newrelic, 'base64').toString('utf-8')
return JSON.parse(rawPayload)
outboundPayload.newrelic = JSON.parse(rawPayload)
}

return outboundPayload
})

// end transaction
Expand Down Expand Up @@ -506,12 +470,11 @@ const runTestCase = function (testCase, parentTest) {
// Priority is asserted to have 1-less precision than the incoming, which is not an agent
// requirement and not something we do. Adjusting so we can have the test in the repository.
if (testCase.test_name === 'newrelic_origin_trace_id_correctly_transformed_for_w3c') {
const payloadTest = testCase.outbound_newrelic_payloads[0]
payloadTest.exact['d.pr'] = 1.1234321
const payloadTest = testCase.outbound_payloads[0]
payloadTest.exact['newrelic.d.pr'] = 1.1234321
}

runTestCaseOutboundPayloads(t, testCase, insertedTraceContextTraces)
runTestCaseOutboundNewrelicPayloads(t, testCase, insertedNewrelicTraces)
runTestCaseTargetEvents(t, testCase, agent)
runTestCaseMetrics(t, testCase, agent)
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/newrelic-response-handling.tap.js
Expand Up @@ -9,7 +9,7 @@ const tap = require('tap')
const nock = require('nock')
const sinon = require('sinon')
const helper = require('../lib/agent_helper')
const testCases = require('../lib/cross_agent_tests/response_code_handling.json')
const testCases = require('../lib/response_code_handling.json')

const TEST_DOMAIN = 'test-collector.newrelic.com'
const TEST_COLLECTOR_URL = `https://${TEST_DOMAIN}`
Expand Down
2 changes: 1 addition & 1 deletion test/integration/security-policies-cross-agent.tap.js
Expand Up @@ -9,7 +9,7 @@ const tap = require('tap')
const nock = require('nock')

const helper = require('../lib/agent_helper')
const testCases = require('../lib/cross_agent_tests/lasp/language_agents_security_policies.json')
const testCases = require('../lib/cross_agent_tests/language_agents_security_policies.json')

const LASP_MAP = require('../../lib/config/lasp').LASP_MAP

Expand Down
7 changes: 0 additions & 7 deletions test/integration/utilization/docker-info.tap.js
Expand Up @@ -66,13 +66,6 @@ function makeTest(testCase, testFile, v2) {
t.notOk(info, 'should not have found container id')
}

if (testCase.expectedMetrics) {
// TODO: No tests currently expect metrics, when one does we'll have to
// update this test depending on the format of that.
t.bailout('Docker expected metrics found but can not be handled.')
} else {
t.equal(agent.metrics._metrics.toJSON().length, 0, 'should have no metrics')
}
resolve()
})
})
Expand Down
1 change: 1 addition & 0 deletions test/lib/cross_agent_tests/.gitignore
@@ -0,0 +1 @@
.idea
7 changes: 4 additions & 3 deletions test/lib/cross_agent_tests/README.md
Expand Up @@ -7,7 +7,7 @@ Please be careful when adding new tests from real world failures.

### Access

Push access to this repository is granted via membership in the cross-agent-team GHE group. Contact Belinda Runkle if you are on the agent team but don't have push access.
Push access to this repository is granted via membership in the agents GHE group.

### Tests

Expand All @@ -17,7 +17,7 @@ Push access to this repository is granted via membership in the cross-agent-team
| [rum_footer_insertion_location](rum_footer_insertion_location) | Describe where the RUM footer (aka "client config") should be inserted. These tests do not apply to agents which insert the footer directly after the loader. |
| [rules.json](rules.json) | Describe how url/metric/txn-name rules should be applied. |
| [rum_client_config.json](rum_client_config.json) | These tests dictate the format and contents of the browser monitoring client configuration. For more information see: [SPEC](https://newrelic.atlassian.net/wiki/display/eng/BAM+Agent+Auto-Instrumentation) |
| [sql_parsing.json](sql_parsing.json) | These tests show how an SQL string should be parsed for the operation and table name. |
| [sql_parsing.json](sql_parsing.json) | These tests show how an SQL string should be parsed for the operation and table name. *Java Note*: The Java Agent is [out-of-sync with these tests](https://source.datanerd.us/java-agent/java_agent/blob/master/newrelic-agent/src/main/java/com/newrelic/agent/database/DefaultDatabaseStatementParser.java), [has its own tests](https://source.datanerd.us/java-agent/java_agent/blob/master/newrelic-agent/src/test/java/com/newrelic/agent/database/DatabaseStatementResponseParserTest.java), and cannot implement these without a breaking change. |
| [url_clean.json](url_clean.json) | These tests show how URLs should be cleaned before putting them into a trace segment's parameter hash (under the key 'uri'). |
| [url_domain_extraction.json](url_domain_extraction.json) | These tests show how the domain of a URL should be extracted (for the purpose of creating external metrics). |
| [postgres_explain_obfuscation](postgres_explain_obfuscation) | These tests show how plain-text explain plan output from PostgreSQL should be obfuscated when SQL obfuscation is enabled. |
Expand All @@ -30,6 +30,7 @@ Push access to this repository is granted via membership in the cross-agent-team
| [transaction_segment_terms.json](transaction_segment_terms.json) | These tests cover agent implementations of the `transaction_segment_terms` transaction renaming rules introduced in collector protocol 14. See [the spec](https://newrelic.atlassian.net/wiki/display/eng/Language+agent+transaction+segment+terms+rules) for details. |
| [synthetics](synthetics) | These tests cover agent support for Synthetics. For details, see [Agent Support for Synthetics: Forced Transaction Traces and Analytic Events](https://source.datanerd.us/agents/agent-specs/blob/master/Synthetics-PORTED.md). |
| [docker_container_id](docker_container_id) | These tests cover parsing of Docker container IDs from `/proc/*/cgroup` on Linux hosts. |
| [docker_container_id_v2](docker_container_id_v2) | These tests cover parsing of Docker container IDs from `/proc/*/mountinfop` on Linux hosts. |
| [utilization](utilization) | These tests cover the collection and validation of metadata for billing purposes as per the [Utilization spec](https://source.datanerd.us/agents/agent-specs/blob/master/Utilization.md). |
| [utilization_vendor_specific](utilization_vendor_specific) | These tests cover the collection and validation of metadata for AWS, Pivotal Cloud Foundry, Google Cloud Platform, and Azure as per the [Utilization spec](https://source.datanerd.us/agents/agent-specs/blob/master/Utilization.md). |
| [data_transport](data_transport/data_transport.json) | These test correct JSON payload generation and handling collector responses. See [readme](https://source.datanerd.us/agents/cross_agent_tests/blob/master/data_transport/data_transport.md) for details. |
| [distributed_tracing](distributed_tracing) | distributed tracing, a.k.a. CAT CATs |

0 comments on commit 2d666b6

Please sign in to comment.