Skip to content

Commit

Permalink
Remove proxyquire references to not iast modules from iast test (#2378)
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien committed Sep 15, 2022
1 parent 183cd83 commit 96d0c90
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 369 deletions.
Expand Up @@ -2,7 +2,7 @@

const Plugin = require('../../../../src/plugins/plugin')
const { storage } = require('../../../../../datadog-core')
const { getFirstNonDDPathAndLine } = require('./../path-line')
const { getFirstNonDDPathAndLine } = require('../path-line')
const { createVulnerability, addVulnerability } = require('../vulnerability-reporter')
const { getIastContext } = require('../iast-context')
const overheadController = require('../overhead-controller')
Expand Down
10 changes: 4 additions & 6 deletions packages/dd-trace/src/appsec/iast/index.js
Expand Up @@ -4,8 +4,7 @@ const web = require('../../plugins/util/web')
const { storage } = require('../../../../datadog-core')
const overheadController = require('./overhead-controller')
const dc = require('diagnostics_channel')
const { saveIastContext, getIastContext, cleanIastContext } = require('./iast-context')

const iastContextFunctions = require('./iast-context')
// TODO Change to `apm:http:server:request:[start|close]` when the subscription
// order of the callbacks can be enforce
const requestStart = dc.channel('dd-trace:incomingHttpRequestStart')
Expand Down Expand Up @@ -33,7 +32,7 @@ function onIncomingHttpRequestStart (data) {
const rootSpan = topContext.span
const isRequestAcquired = overheadController.acquireRequest(rootSpan)
if (isRequestAcquired) {
const iastContext = saveIastContext(store, topContext, { rootSpan, req: data.req })
const iastContext = iastContextFunctions.saveIastContext(store, topContext, { rootSpan, req: data.req })
overheadController.initializeRequestContext(iastContext)
}
}
Expand All @@ -44,13 +43,12 @@ function onIncomingHttpRequestStart (data) {
function onIncomingHttpRequestEnd (data) {
if (data && data.req) {
const store = storage.getStore()
const iastContext = getIastContext(storage.getStore())
const iastContext = iastContextFunctions.getIastContext(storage.getStore())
if (iastContext && iastContext.rootSpan) {
overheadController.releaseRequest()
sendVulnerabilities(iastContext, iastContext.rootSpan)
}
// TODO web.getContext(data.req) is required when the request is aborted
if (cleanIastContext(store, web.getContext(data.req), iastContext)) {
if (iastContextFunctions.cleanIastContext(store, web.getContext(data.req), iastContext)) {
overheadController.releaseRequest()
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/dd-trace/src/appsec/iast/path-line.js
Expand Up @@ -51,6 +51,9 @@ function getFirstNonDDPathAndLineFromCallsites (callsites) {
function isExcluded (callsite) {
if (callsite.isNative()) return true
const filename = callsite.getFileName()
if (!filename) {
return true
}
for (let i = 0; i < EXCLUDED_PATHS.length; i++) {
if (filename.indexOf(EXCLUDED_PATHS[i]) > -1) {
return true
Expand Down
Expand Up @@ -30,7 +30,7 @@ describe('vulnerability-analyzer', () => {
}
VulnerabilityAnalyzer = proxyquire('../../../../src/appsec/iast/analyzers/vulnerability-analyzer', {
'../vulnerability-reporter': vulnerabilityReporter,
'./../path-line': pathLine,
'../path-line': pathLine,
'../overhead-controller': overheadController,
'../iast-context': iastContextHandler
})
Expand Down

0 comments on commit 96d0c90

Please sign in to comment.