-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
176 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
'use strict' | ||
|
||
const { assert } = require('chai') | ||
|
||
const { getRootSpan } = require('../../../src/appsec/sdk/utils') | ||
const Tracer = require('../../../src/proxy') | ||
const Config = require('../../../src/config') | ||
|
||
describe('Appsec SDK utils', () => { | ||
let tracer | ||
|
||
before(() => { | ||
tracer = new Tracer(new Config({ | ||
enabled: true | ||
})) | ||
tracer.init() | ||
}) | ||
|
||
describe('getRootSpan', () => { | ||
it('should return root span if there are no childs', () => { | ||
tracer.trace('parent', { }, parent => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(parent, root) | ||
}) | ||
}) | ||
|
||
it('should return root span of single child', () => { | ||
const childOf = tracer.startSpan('parent') | ||
|
||
tracer.trace('child1', { childOf }, child1 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(childOf, root) | ||
}) | ||
}) | ||
|
||
it('should return root span of multiple child', () => { | ||
const childOf = tracer.startSpan('parent') | ||
|
||
tracer.trace('child1.1', { childOf }, child11 => { | ||
tracer.trace('child1.1.2', { childOf: child11 }, child112 => {}) | ||
}) | ||
tracer.trace('child1.2', { childOf }, child12 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(childOf, root) | ||
}) | ||
}) | ||
|
||
it('should return root span of single child discarding inferred spans', () => { | ||
const childOf = tracer.startSpan('parent') | ||
childOf.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1', { childOf }, child1 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(child1, root) | ||
}) | ||
}) | ||
|
||
it('should return root span of an inferred span', () => { | ||
const childOf = tracer.startSpan('parent') | ||
|
||
tracer.trace('child1', { childOf }, child1 => { | ||
child1.setTag('_inferred_span', {}) | ||
|
||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(childOf, root) | ||
}) | ||
}) | ||
|
||
it('should return root span of an inferred span with inferred parent', () => { | ||
const childOf = tracer.startSpan('parent') | ||
childOf.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1', { childOf }, child1 => { | ||
child1.setTag('_inferred_span', {}) | ||
|
||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(child1, root) | ||
}) | ||
}) | ||
|
||
it('should return root span discarding inferred spans (mutiple childs)', () => { | ||
const childOf = tracer.startSpan('parent') | ||
childOf.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.1', { childOf }, child11 => {}) | ||
tracer.trace('child1.2', { childOf }, child12 => { | ||
tracer.trace('child1.2.1', { childOf: child12 }, child121 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(child12, root) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should return root span discarding inferred spans if it is direct parent (mutiple childs)', () => { | ||
const childOf = tracer.startSpan('parent') | ||
|
||
tracer.trace('child1.1', { childOf }, child11 => {}) | ||
tracer.trace('child1.2', { childOf }, child12 => { | ||
child12.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.2.1', { childOf: child12 }, child121 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(childOf, root) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should return root span discarding multiple inferred spans', () => { | ||
const childOf = tracer.startSpan('parent') | ||
|
||
tracer.trace('child1.1', { childOf }, child11 => {}) | ||
tracer.trace('child1.2', { childOf }, child12 => { | ||
child12.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.2.1', { childOf: child12 }, child121 => { | ||
child121.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.2.1.1', { childOf: child121 }, child1211 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(childOf, root) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
it('should return itself as root span if all are inferred spans', () => { | ||
const childOf = tracer.startSpan('parent') | ||
childOf.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.1', { childOf }, child11 => {}) | ||
tracer.trace('child1.2', { childOf }, child12 => { | ||
child12.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.2.1', { childOf: child12 }, child121 => { | ||
child121.setTag('_inferred_span', {}) | ||
|
||
tracer.trace('child1.2.1.1', { childOf: child121 }, child1211 => { | ||
const root = getRootSpan(tracer) | ||
|
||
assert.equal(child1211, root) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |