Skip to content

Commit 3522ff7

Browse files
authored
switch all sandbox usage to new helper (#6777)
1 parent 091130d commit 3522ff7

File tree

108 files changed

+893
-1415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+893
-1415
lines changed

integration-tests/aiguard/index.spec.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
const { describe, it, before, after } = require('mocha')
44
const path = require('path')
5-
const { createSandbox, FakeAgent, spawnProc } = require('../helpers')
5+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
66
const startApiMock = require('./api-mock')
77
const { expect } = require('chai')
88
const { executeRequest } = require('./util')
99

1010
describe('AIGuard SDK integration tests', () => {
11-
let sandbox, cwd, appFile, agent, proc, api, url
11+
let cwd, appFile, agent, proc, api, url
12+
13+
useSandbox(['express'])
1214

1315
before(async function () {
14-
this.timeout(process.platform === 'win32' ? 90000 : 30000)
15-
sandbox = await createSandbox(['express'])
16-
cwd = sandbox.folder
16+
cwd = sandboxCwd()
1717
appFile = path.join(cwd, 'aiguard/server.js')
1818
api = await startApiMock()
1919
})
2020

2121
after(async () => {
22-
await sandbox.remove()
2322
await api.close()
2423
})
2524

integration-tests/appsec/data-collection.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ const path = require('path')
55
const Axios = require('axios')
66

77
const {
8-
createSandbox,
8+
sandboxCwd,
9+
useSandbox,
910
FakeAgent,
1011
spawnProc
1112
} = require('../helpers')
1213

1314
describe('ASM Data collection', () => {
14-
let axios, sandbox, cwd, appFile, agent, proc
15+
let axios, cwd, appFile, agent, proc
16+
17+
useSandbox(['express'])
1518

1619
before(async () => {
17-
sandbox = await createSandbox(['express'])
18-
cwd = sandbox.folder
20+
cwd = sandboxCwd()
1921
appFile = path.join(cwd, 'appsec/data-collection/index.js')
2022
})
2123

22-
after(async () => {
23-
await sandbox.remove()
24-
})
25-
2624
function startServer (extendedDataCollection) {
2725
beforeEach(async () => {
2826
agent = await new FakeAgent().start()

integration-tests/appsec/endpoints-collection.spec.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
'use strict'
22

33
const { expect } = require('chai')
4-
const { describe, before, after, it } = require('mocha')
4+
const { describe, before, it } = require('mocha')
55

66
const path = require('node:path')
77

8-
const { createSandbox, FakeAgent, spawnProc } = require('../helpers')
8+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
99

1010
describe('Endpoints collection', () => {
11-
let sandbox, cwd
11+
let cwd
1212

13-
before(async function () {
14-
this.timeout(process.platform === 'win32' ? 90000 : 30000)
13+
useSandbox(['express', 'fastify'])
1514

16-
sandbox = await createSandbox(['express', 'fastify'])
17-
18-
cwd = sandbox.folder
19-
})
20-
21-
after(async function () {
22-
this.timeout(60000)
23-
await sandbox.remove()
15+
before(function () {
16+
cwd = sandboxCwd()
2417
})
2518

2619
function getExpectedEndpoints (framework) {

integration-tests/appsec/graphql.spec.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ const axios = require('axios')
66

77
const {
88
FakeAgent,
9-
createSandbox,
9+
sandboxCwd,
10+
useSandbox,
1011
spawnProc
1112
} = require('../helpers')
1213

1314
describe('graphql', () => {
14-
let sandbox, cwd, agent, webFile, proc
15+
let cwd, agent, webFile, proc
1516

16-
before(async function () {
17-
sandbox = await createSandbox(['@apollo/server', 'graphql'])
18-
cwd = sandbox.folder
17+
useSandbox(['@apollo/server', 'graphql'])
18+
19+
before(function () {
20+
cwd = sandboxCwd()
1921
webFile = path.join(cwd, 'graphql/index.js')
2022
})
2123

@@ -34,10 +36,6 @@ describe('graphql', () => {
3436
await agent.stop()
3537
})
3638

37-
after(async () => {
38-
await sandbox.remove()
39-
})
40-
4139
it('should not report any attack', async () => {
4240
const agentPromise = agent.assertMessageReceived(({ headers, payload }) => {
4341
assert.propertyVal(headers, 'host', `127.0.0.1:${agent.port}`)

integration-tests/appsec/iast-esbuild.spec.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ const path = require('path')
88
const { promisify } = require('util')
99
const msgpack = require('@msgpack/msgpack')
1010

11-
const { createSandbox, FakeAgent, spawnProc } = require('../helpers')
11+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
1212

1313
const exec = promisify(childProcess.exec)
1414

1515
describe('esbuild support for IAST', () => {
1616
describe('cjs', () => {
17-
let proc, agent, sandbox, axios
17+
let proc, agent, axios
1818
let applicationDir, bundledApplicationDir
1919

20+
useSandbox()
21+
2022
before(async () => {
21-
sandbox = await createSandbox([])
22-
const cwd = sandbox.folder
23+
const cwd = sandboxCwd()
2324
applicationDir = path.join(cwd, 'appsec/iast-esbuild')
2425

2526
// Craft node_modules directory to ship native modules
@@ -49,10 +50,6 @@ describe('esbuild support for IAST', () => {
4950
fs.cpSync(path.join(craftedNodeModulesDir, 'node_modules'), bundledApplicationDir, { recursive: true })
5051
})
5152

52-
after(async () => {
53-
await sandbox.remove()
54-
})
55-
5653
function startServer (appFile, iastEnabled) {
5754
beforeEach(async () => {
5855
agent = await new FakeAgent().start()

integration-tests/appsec/iast.esm-security-controls.spec.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
'use strict'
22

3-
const { createSandbox, spawnProc, FakeAgent } = require('../helpers')
3+
const { sandboxCwd, useSandbox, spawnProc, FakeAgent } = require('../helpers')
44
const path = require('path')
55
const Axios = require('axios')
66
const { assert } = require('chai')
77

88
describe('ESM Security controls', () => {
9-
let axios, sandbox, cwd, appFile, agent, proc
9+
let axios, cwd, appFile, agent, proc
1010

1111
['4', '5'].forEach(version => {
1212
describe(`With express v${version}`, () => {
13-
before(async function () {
14-
this.timeout(process.platform === 'win32' ? 90000 : 30000)
15-
sandbox = await createSandbox([`express@${version}`])
16-
cwd = sandbox.folder
17-
appFile = path.join(cwd, 'appsec', 'esm-security-controls', 'index.mjs')
18-
})
13+
useSandbox([`express@${version}`])
1914

20-
after(async function () {
21-
await sandbox.remove()
15+
before(function () {
16+
cwd = sandboxCwd()
17+
appFile = path.join(cwd, 'appsec', 'esm-security-controls', 'index.mjs')
2218
})
2319

2420
const nodeOptions = '--import dd-trace/initialize.mjs'

integration-tests/appsec/iast.esm.spec.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
'use strict'
22

3-
const { createSandbox, spawnProc, FakeAgent } = require('../helpers')
3+
const { sandboxCwd, useSandbox, spawnProc, FakeAgent } = require('../helpers')
44
const path = require('path')
55
const Axios = require('axios')
66
const { assert } = require('chai')
77

88
describe('ESM', () => {
9-
let axios, sandbox, cwd, appFile, agent, proc
9+
let axios, cwd, appFile, agent, proc
1010

11-
before(async function () {
12-
this.timeout(process.platform === 'win32' ? 90000 : 30000)
13-
sandbox = await createSandbox(['express'])
14-
cwd = sandbox.folder
15-
appFile = path.join(cwd, 'appsec', 'esm-app', 'index.mjs')
16-
})
11+
useSandbox(['express'])
1712

18-
after(async function () {
19-
await sandbox.remove()
13+
before(function () {
14+
cwd = sandboxCwd()
15+
appFile = path.join(cwd, 'appsec', 'esm-app', 'index.mjs')
2016
})
2117

2218
const nodeOptionsList = [

integration-tests/appsec/index.spec.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ const path = require('path')
44
const Axios = require('axios')
55
const { assert } = require('chai')
66
const msgpack = require('@msgpack/msgpack')
7-
const { createSandbox, FakeAgent, spawnProc } = require('../helpers')
7+
const { sandboxCwd, useSandbox, FakeAgent, spawnProc } = require('../helpers')
88

99
describe('RASP', () => {
10-
let axios, sandbox, cwd, appFile, agent, proc, stdioHandler
10+
let axios, cwd, appFile, agent, proc, stdioHandler
1111

1212
function stdOutputHandler (data) {
1313
stdioHandler && stdioHandler(data)
1414
}
1515

16-
before(async () => {
17-
sandbox = await createSandbox(['express', 'axios'])
18-
cwd = sandbox.folder
19-
appFile = path.join(cwd, 'appsec/rasp/index.js')
20-
})
16+
useSandbox(['express', 'axios'])
2117

22-
after(async () => {
23-
await sandbox.remove()
18+
before(() => {
19+
cwd = sandboxCwd()
20+
appFile = path.join(cwd, 'appsec/rasp/index.js')
2421
})
2522

2623
function startServer (abortOnUncaughtException, collectRequestBody = false) {

integration-tests/appsec/multer.spec.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@
22

33
const axios = require('axios')
44
const { assert } = require('chai')
5-
const { describe, it, beforeEach, afterEach, before, after } = require('mocha')
5+
const { describe, it, beforeEach, afterEach, before } = require('mocha')
66

77
const path = require('node:path')
88

99
const {
10-
createSandbox,
10+
sandboxCwd,
11+
useSandbox,
1112
FakeAgent,
1213
spawnProc
1314
} = require('../helpers')
1415

1516
describe('multer', () => {
16-
let sandbox, cwd, startupTestFile, agent, proc, env
17+
let cwd, startupTestFile, agent, proc, env
1718

1819
['1.4.4-lts.1', '1.4.5-lts.1'].forEach((version) => {
1920
describe(`v${version}`, () => {
20-
before(async () => {
21-
sandbox = await createSandbox(['express', `multer@${version}`])
22-
cwd = sandbox.folder
23-
startupTestFile = path.join(cwd, 'appsec', 'multer', 'index.js')
24-
})
21+
useSandbox(['express', `multer@${version}`])
2522

26-
after(async () => {
27-
await sandbox.remove()
23+
before(() => {
24+
cwd = sandboxCwd()
25+
startupTestFile = path.join(cwd, 'appsec', 'multer', 'index.js')
2826
})
2927

3028
beforeEach(async () => {

integration-tests/appsec/response-headers.spec.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ const path = require('path')
55
const Axios = require('axios')
66

77
const {
8-
createSandbox,
8+
sandboxCwd,
9+
useSandbox,
910
FakeAgent,
1011
spawnProc
1112
} = require('../helpers')
1213

1314
describe('Headers collection - Fastify', () => {
14-
let axios, sandbox, cwd, appFile, agent, proc
15+
let axios, cwd, appFile, agent, proc
1516

16-
before(async () => {
17-
sandbox = await createSandbox(['fastify'])
18-
cwd = sandbox.folder
19-
appFile = path.join(cwd, 'appsec/data-collection/fastify.js')
20-
})
17+
useSandbox(['fastify'])
2118

22-
after(async () => {
23-
await sandbox.remove()
19+
before(() => {
20+
cwd = sandboxCwd()
21+
appFile = path.join(cwd, 'appsec/data-collection/fastify.js')
2422
})
2523

2624
beforeEach(async () => {

0 commit comments

Comments
 (0)