@contrast/assess 1.46.0 → 1.46.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -11
- package/lib/crypto-analysis/install/crypto.test.js +0 -146
- package/lib/crypto-analysis/install/math.test.js +0 -65
- package/lib/dataflow/index.test.js +0 -36
- package/lib/dataflow/propagation/index.test.js +0 -103
- package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
- package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
- package/lib/dataflow/propagation/install/buffer.test.js +0 -112
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
- package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
- package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
- package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
- package/lib/dataflow/propagation/install/escape.test.js +0 -73
- package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
- package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
- package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
- package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
- package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
- package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
- package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
- package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
- package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
- package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
- package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
- package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
- package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
- package/lib/dataflow/propagation/install/path/format.test.js +0 -250
- package/lib/dataflow/propagation/install/path/index.test.js +0 -45
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
- package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
- package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
- package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
- package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
- package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
- package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
- package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
- package/lib/dataflow/propagation/install/send.test.js +0 -63
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
- package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
- package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
- package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
- package/lib/dataflow/propagation/install/string/index.test.js +0 -103
- package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
- package/lib/dataflow/propagation/install/string/match.test.js +0 -374
- package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
- package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
- package/lib/dataflow/propagation/install/string/split.test.js +0 -513
- package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
- package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
- package/lib/dataflow/propagation/install/unescape.test.js +0 -78
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
- package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
- package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
- package/lib/dataflow/propagation/install/url/url.test.js +0 -466
- package/lib/dataflow/propagation/install/util-format.test.js +0 -336
- package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
- package/lib/dataflow/sinks/index.test.js +0 -78
- package/lib/dataflow/sinks/install/child-process.test.js +0 -338
- package/lib/dataflow/sinks/install/eval.test.js +0 -95
- package/lib/dataflow/sinks/install/express/index.test.js +0 -33
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
- package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/fs.test.js +0 -138
- package/lib/dataflow/sinks/install/function.test.js +0 -103
- package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/http/index.test.js +0 -33
- package/lib/dataflow/sinks/install/http/request.test.js +0 -184
- package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
- package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
- package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
- package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
- package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
- package/lib/dataflow/sinks/install/mssql.test.js +0 -134
- package/lib/dataflow/sinks/install/mysql.test.js +0 -224
- package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
- package/lib/dataflow/sinks/install/postgres.test.js +0 -152
- package/lib/dataflow/sinks/install/restify.test.js +0 -140
- package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
- package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
- package/lib/dataflow/sinks/install/vm.test.js +0 -326
- package/lib/dataflow/sources/handler.test.js +0 -501
- package/lib/dataflow/sources/index.test.js +0 -60
- package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
- package/lib/dataflow/sources/install/busboy.test.js +0 -152
- package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
- package/lib/dataflow/sources/install/express/params.test.js +0 -110
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
- package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
- package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
- package/lib/dataflow/sources/install/formidable1.test.js +0 -119
- package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
- package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
- package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
- package/lib/dataflow/sources/install/http.test.js +0 -149
- package/lib/dataflow/sources/install/koa/index.test.js +0 -40
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
- package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
- package/lib/dataflow/sources/install/multer1.test.js +0 -143
- package/lib/dataflow/sources/install/qs6.test.js +0 -131
- package/lib/dataflow/sources/install/querystring.test.js +0 -82
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
- package/lib/dataflow/sources/install/restify/index.test.js +0 -38
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
- package/lib/dataflow/sources/install/restify/router.test.js +0 -81
- package/lib/dataflow/tag-utils-complete.test.js +0 -27
- package/lib/dataflow/tag-utils.test.js +0 -192
- package/lib/dataflow/tracker.test.js +0 -216
- package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
- package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
- package/lib/event-factory.test.js +0 -326
- package/lib/get-policy.test.js +0 -194
- package/lib/get-source-context.test.js +0 -161
- package/lib/index.test.js +0 -45
- package/lib/make-source-context.test.js +0 -50
- package/lib/response-scanning/handlers/index.test.js +0 -419
- package/lib/response-scanning/handlers/utils.test.js +0 -380
- package/lib/response-scanning/index.test.js +0 -41
- package/lib/response-scanning/install/http.test.js +0 -175
- package/lib/rule-scopes.test.js +0 -27
- package/lib/sampler/common.test.js +0 -101
- package/lib/sampler/index.test.js +0 -313
- package/lib/session-configuration/handlers.test.js +0 -84
- package/lib/session-configuration/index.test.js +0 -36
- package/lib/session-configuration/install/express-session.test.js +0 -218
- package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
- package/lib/session-configuration/install/hapi.test.js +0 -269
- package/lib/session-configuration/install/koa.test.js +0 -92
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
const { InputType } = require('@contrast/common');
|
|
7
|
-
const qsInstr = require('./qs6');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources qs v6.x', function () {
|
|
10
|
-
let core, simulateRequestScope, qsMock, patchedQs, query, sources;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
|
|
15
|
-
sources = core.assess.dataflow.sources;
|
|
16
|
-
sinon.spy(sources, 'handle');
|
|
17
|
-
|
|
18
|
-
query = 'querystring';
|
|
19
|
-
qsMock = {
|
|
20
|
-
parse: (query) => ({ query } || {})
|
|
21
|
-
};
|
|
22
|
-
sinon.spy(core.patcher, 'patch');
|
|
23
|
-
|
|
24
|
-
qsInstr(core).install();
|
|
25
|
-
patchedQs = core.depHooks.resolve.yield(qsMock)[0];
|
|
26
|
-
core.patcher.patch.resetHistory();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('calls patcher on the `.parse` method', function () {
|
|
30
|
-
core.depHooks.resolve.yield(qsMock);
|
|
31
|
-
|
|
32
|
-
expect(core.patcher.patch).to.have.been.calledOnce;
|
|
33
|
-
expect(core.patcher.patch).to.have.been.calledWithMatch(qsMock, 'parse', {
|
|
34
|
-
name: 'qs.parse',
|
|
35
|
-
patchType: 'assess-dataflow-source',
|
|
36
|
-
post: sinon.match.func
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('calls `.handle` when parsing is successful, in right context and with reqData.queries present', function () {
|
|
41
|
-
let sourceContext;
|
|
42
|
-
|
|
43
|
-
simulateRequestScope(() => {
|
|
44
|
-
sourceContext = core.scopes.sources.getStore()?.assess;
|
|
45
|
-
|
|
46
|
-
Object.assign(sourceContext.reqData, {
|
|
47
|
-
queries: 'querystring'
|
|
48
|
-
});
|
|
49
|
-
patchedQs.parse(query);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(sources.handle).to.have.been.calledOnce;
|
|
53
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
54
|
-
context: 'req.query',
|
|
55
|
-
name: 'qs.parse',
|
|
56
|
-
stacktraceOpts: {
|
|
57
|
-
constructorOpt: sinon.match.func,
|
|
58
|
-
},
|
|
59
|
-
inputType: InputType.QUERYSTRING,
|
|
60
|
-
data: { query: 'querystring' },
|
|
61
|
-
sourceContext
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('does not call `.handle` when parsing is successful, in right context but with reqData.queries not present', function () {
|
|
66
|
-
simulateRequestScope(() => {
|
|
67
|
-
patchedQs.parse(query);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(sources.handle).not.to.have.been.called;
|
|
71
|
-
expect(core.logger.debug).not.to.have.been.called;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('does not call `.handle` when not in context', function () {
|
|
75
|
-
simulateRequestScope(() => {
|
|
76
|
-
patchedQs.parse(query);
|
|
77
|
-
}, {});
|
|
78
|
-
|
|
79
|
-
expect(sources.handle).not.to.have.been.called;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('does not call `.handle` when the values are already tracked', function () {
|
|
83
|
-
simulateRequestScope(() => {
|
|
84
|
-
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
85
|
-
sourceContext.parsedQuery = true;
|
|
86
|
-
|
|
87
|
-
patchedQs.parse(query);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
expect(sources.handle).not.to.have.been.called;
|
|
91
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
92
|
-
{ inputType: InputType.QUERYSTRING, funcKey: 'assess-dataflow-source:qs.parse' },
|
|
93
|
-
'values already tracked',
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('does not call `.handle` when `qs` does not return a result', function () {
|
|
98
|
-
simulateRequestScope(() => {
|
|
99
|
-
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
100
|
-
|
|
101
|
-
Object.assign(sourceContext.reqData, {
|
|
102
|
-
queries: 'querystring'
|
|
103
|
-
});
|
|
104
|
-
patchedQs.parse(null);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
expect(sources.handle).not.to.have.been.called;
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('handles a case with an error in the `.handle` method', function () {
|
|
111
|
-
const err = new Error('test');
|
|
112
|
-
|
|
113
|
-
core.assess.dataflow.sources.handle = () => {
|
|
114
|
-
throw err;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
simulateRequestScope(() => {
|
|
118
|
-
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
119
|
-
|
|
120
|
-
Object.assign(sourceContext.reqData, {
|
|
121
|
-
queries: 'querystring'
|
|
122
|
-
});
|
|
123
|
-
patchedQs.parse(query);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
127
|
-
{ err, inputType: InputType.QUERYSTRING, funcKey: 'assess-dataflow-source:qs.parse' },
|
|
128
|
-
'unable to handle source',
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
const { InputType } = require('@contrast/common');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow sources querystring', function () {
|
|
9
|
-
let core, simulateRequestScope, querystring;
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
13
|
-
|
|
14
|
-
sinon.stub(core.assess.dataflow.sources, 'handle');
|
|
15
|
-
|
|
16
|
-
const querystringMock = {
|
|
17
|
-
parse: (query) => ({ query })
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
require('./querystring')(core).install();
|
|
21
|
-
querystring = core.depHooks.resolve.yield(querystringMock)[0];
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('calls `.handle` when parsing is successful, in right context and with reqData.queries present', function () {
|
|
25
|
-
simulateRequestScope(() => {
|
|
26
|
-
querystring.parse('query');
|
|
27
|
-
|
|
28
|
-
expect(core.assess.dataflow.sources.handle).to.have.been.calledWith({
|
|
29
|
-
context: 'req.query',
|
|
30
|
-
name: 'querystring.parse',
|
|
31
|
-
stacktraceOpts: {
|
|
32
|
-
constructorOpt: sinon.match.func,
|
|
33
|
-
prependFrames: sinon.match.array,
|
|
34
|
-
},
|
|
35
|
-
inputType: InputType.QUERYSTRING,
|
|
36
|
-
data: { query: 'query' },
|
|
37
|
-
sourceContext: core.scopes.sources.getStore().assess
|
|
38
|
-
});
|
|
39
|
-
}, { assess: { reqData: { queries: 'query' } } });
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('does not call `.handle` when parsing is successful, in right context but without matching reqData.queries', function () {
|
|
43
|
-
simulateRequestScope(() => {
|
|
44
|
-
querystring.parse('query1');
|
|
45
|
-
|
|
46
|
-
expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
|
|
47
|
-
}, { assess: { reqData: { queries: 'query2' } } });
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('does not call `.handle` when not in context', function () {
|
|
51
|
-
simulateRequestScope(() => {
|
|
52
|
-
querystring.parse('query');
|
|
53
|
-
|
|
54
|
-
expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
|
|
55
|
-
}, {});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('does not call `.handle` when the values are already tracked', function () {
|
|
59
|
-
simulateRequestScope(() => {
|
|
60
|
-
querystring.parse('query');
|
|
61
|
-
|
|
62
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
63
|
-
{ funcKey: 'assess-dataflow-source:querystring.parse' },
|
|
64
|
-
'values already tracked'
|
|
65
|
-
);
|
|
66
|
-
}, { assess: { parsedQuery: true } });
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('handles a case with an error in the `.handle` method', function () {
|
|
70
|
-
const err = new Error('test');
|
|
71
|
-
core.assess.dataflow.sources.handle.throws(err);
|
|
72
|
-
|
|
73
|
-
simulateRequestScope(() => {
|
|
74
|
-
querystring.parse('query');
|
|
75
|
-
|
|
76
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
77
|
-
{ err, funcKey: 'assess-dataflow-source:querystring.parse' },
|
|
78
|
-
'unable to handle source'
|
|
79
|
-
);
|
|
80
|
-
}, { assess: { reqData: { queries: 'query' } } });
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { InputType } = require('@contrast/common');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
const init = require('./fieldedTextBodyParser');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources restify fieldedTextBodyParser', function () {
|
|
10
|
-
let core, simulateRequestScope, handle, middleware, req, res, next;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
handle = sinon.stub(core.assess.dataflow.sources, 'handle');
|
|
15
|
-
|
|
16
|
-
let fieldedTextBodyParserStub = sinon.stub().returns(sinon.stub().callsArg(2));
|
|
17
|
-
|
|
18
|
-
req = {};
|
|
19
|
-
res = {};
|
|
20
|
-
next = sinon.stub();
|
|
21
|
-
|
|
22
|
-
core.depHooks.resolve
|
|
23
|
-
.withArgs({ name: 'restify', file: 'lib/plugins/fieldedTextBodyParser.js', version: '>=8 <12' })
|
|
24
|
-
.callsFake((_, cb) => {
|
|
25
|
-
fieldedTextBodyParserStub = cb(fieldedTextBodyParserStub);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
init(core).install();
|
|
29
|
-
middleware = fieldedTextBodyParserStub();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('does not call `handle` when there is no assess policy in request context', function () {
|
|
33
|
-
simulateRequestScope(() => {
|
|
34
|
-
middleware(req, res, next);
|
|
35
|
-
|
|
36
|
-
expect(handle).not.to.have.been.called;
|
|
37
|
-
}, { assess: { policy: null } });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('does not handle source when body is already tracked', function () {
|
|
41
|
-
simulateRequestScope(() => {
|
|
42
|
-
core.scopes.sources.getStore().assess.parsedBody = true;
|
|
43
|
-
|
|
44
|
-
middleware(req, res, next);
|
|
45
|
-
|
|
46
|
-
expect(handle).not.to.have.been.called;
|
|
47
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
48
|
-
{ funcKey: 'assess-dataflow-source:restify.plugins.fieldedTextBodyParser.parseFieldedText' },
|
|
49
|
-
'values already tracked'
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('calls `handle` appropriately', function () {
|
|
55
|
-
req.body = [{ foo: 'bar' }];
|
|
56
|
-
|
|
57
|
-
simulateRequestScope(() => {
|
|
58
|
-
middleware(req, res, next);
|
|
59
|
-
|
|
60
|
-
expect(handle).to.have.been.calledWith({
|
|
61
|
-
context: 'req.body',
|
|
62
|
-
data: req.body,
|
|
63
|
-
inputType: InputType.BODY,
|
|
64
|
-
name: 'restify.plugins.fieldedTextBodyParser.parseFieldedText',
|
|
65
|
-
stacktraceOpts: {
|
|
66
|
-
constructorOpt: sinon.match.func,
|
|
67
|
-
},
|
|
68
|
-
sourceContext: sinon.match.object,
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('logs errors in the `handle` method', function () {
|
|
74
|
-
const err = new Error('yikes!');
|
|
75
|
-
handle.throws(err);
|
|
76
|
-
|
|
77
|
-
simulateRequestScope(() => {
|
|
78
|
-
middleware(req, res, next);
|
|
79
|
-
|
|
80
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
81
|
-
{ err, funcKey: 'assess-dataflow-source:restify.plugins.fieldedTextBodyParser.parseFieldedText' },
|
|
82
|
-
'unable to handle Restify source',
|
|
83
|
-
);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const proxyquire = require('proxyquire');
|
|
5
|
-
const mocks = require('@contrast/test/mocks');
|
|
6
|
-
|
|
7
|
-
const moduleMock = (moduleName, mock) => (deps) => {
|
|
8
|
-
deps.assess.dataflow.sources.restifyInstrumentation[moduleName] = mock[moduleName];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow sources restify', function () {
|
|
12
|
-
let core, restifyInstrumentation, init, modules;
|
|
13
|
-
|
|
14
|
-
beforeEach(function () {
|
|
15
|
-
core = mocks.core();
|
|
16
|
-
core.assess = mocks.assess();
|
|
17
|
-
restifyInstrumentation = core.assess.dataflow.sources.restifyInstrumentation;
|
|
18
|
-
init = proxyquire('.', {
|
|
19
|
-
'./fieldedTextBodyParser': moduleMock('fieldedTextBodyParser', restifyInstrumentation),
|
|
20
|
-
'./jsonBodyParser': moduleMock('jsonBodyParser', restifyInstrumentation),
|
|
21
|
-
'./router': moduleMock('router', restifyInstrumentation),
|
|
22
|
-
});
|
|
23
|
-
modules = [
|
|
24
|
-
'fieldedTextBodyParser',
|
|
25
|
-
'jsonBodyParser',
|
|
26
|
-
'router',
|
|
27
|
-
];
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('installs the components', function () {
|
|
31
|
-
init(core).install();
|
|
32
|
-
|
|
33
|
-
modules.forEach((module) => {
|
|
34
|
-
expect(restifyInstrumentation[module].install).to.have.been.calledOnce;
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { InputType } = require('@contrast/common');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
const init = require('./jsonBodyParser');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources restify jsonBodyParser', function () {
|
|
10
|
-
let core, simulateRequestScope, handle, jsonBodyParserStub, req, res, next;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
handle = sinon.stub(core.assess.dataflow.sources, 'handle');
|
|
15
|
-
|
|
16
|
-
jsonBodyParserStub = sinon.stub().returns([
|
|
17
|
-
sinon.stub(),
|
|
18
|
-
sinon.stub().callsArg(2),
|
|
19
|
-
]);
|
|
20
|
-
|
|
21
|
-
req = {};
|
|
22
|
-
res = {};
|
|
23
|
-
next = sinon.stub();
|
|
24
|
-
|
|
25
|
-
core.depHooks.resolve
|
|
26
|
-
.withArgs({ name: 'restify', file: 'lib/plugins/jsonBodyParser.js', version: '>=8 <12' })
|
|
27
|
-
.callsFake((_, cb) => {
|
|
28
|
-
jsonBodyParserStub = cb(jsonBodyParserStub);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
init(core).install();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('does not handle source when there is no assess policy in request context', function () {
|
|
35
|
-
const [, middleware] = jsonBodyParserStub();
|
|
36
|
-
|
|
37
|
-
simulateRequestScope(() => {
|
|
38
|
-
middleware(req, res, next);
|
|
39
|
-
expect(handle).not.to.have.been.called;
|
|
40
|
-
}, { assess: { policy: null } });
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('does not call `handle` when body is already tracked', function () {
|
|
44
|
-
const [, middleware] = jsonBodyParserStub();
|
|
45
|
-
|
|
46
|
-
simulateRequestScope(() => {
|
|
47
|
-
core.scopes.sources.getStore().assess.parsedBody = true;
|
|
48
|
-
middleware(req, res, next);
|
|
49
|
-
|
|
50
|
-
expect(handle).not.to.have.been.called;
|
|
51
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
52
|
-
{ funcKey: 'assess-dataflow-source:restify.plugins.jsonBodyParser.parseJson' },
|
|
53
|
-
'values already tracked'
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('calls `handle` appropriately', function () {
|
|
59
|
-
const [, middleware] = jsonBodyParserStub();
|
|
60
|
-
req.body = { foo: 'bar' };
|
|
61
|
-
|
|
62
|
-
simulateRequestScope(() => {
|
|
63
|
-
middleware(req, res, next);
|
|
64
|
-
|
|
65
|
-
expect(handle).to.have.been.calledOnceWith({
|
|
66
|
-
context: 'req.body',
|
|
67
|
-
data: req.body,
|
|
68
|
-
inputType: InputType.JSON_VALUE,
|
|
69
|
-
name: 'restify.plugins.jsonBodyParser.parseJson',
|
|
70
|
-
stacktraceOpts: {
|
|
71
|
-
constructorOpt: sinon.match.func,
|
|
72
|
-
},
|
|
73
|
-
sourceContext: sinon.match.object,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('calls `handle` twice if `mapParams` is set', function () {
|
|
79
|
-
const [, middleware] = jsonBodyParserStub({ mapParams: true });
|
|
80
|
-
req.body = { foo: 'bar' };
|
|
81
|
-
req.params = req.body;
|
|
82
|
-
|
|
83
|
-
simulateRequestScope(() => {
|
|
84
|
-
middleware(req, res, next);
|
|
85
|
-
|
|
86
|
-
expect(handle).to.have.callCount(2);
|
|
87
|
-
expect(handle).to.have.been.calledWith({
|
|
88
|
-
context: 'req.body',
|
|
89
|
-
data: req.body,
|
|
90
|
-
inputType: InputType.JSON_VALUE,
|
|
91
|
-
name: 'restify.plugins.jsonBodyParser.parseJson',
|
|
92
|
-
stacktraceOpts: {
|
|
93
|
-
constructorOpt: sinon.match.func,
|
|
94
|
-
},
|
|
95
|
-
sourceContext: sinon.match.object,
|
|
96
|
-
});
|
|
97
|
-
expect(handle).to.have.been.calledWith({
|
|
98
|
-
context: 'req.params',
|
|
99
|
-
data: req.params,
|
|
100
|
-
inputType: InputType.JSON_VALUE,
|
|
101
|
-
name: 'restify.plugins.jsonBodyParser.parseJson',
|
|
102
|
-
stacktraceOpts: {
|
|
103
|
-
constructorOpt: sinon.match.func,
|
|
104
|
-
},
|
|
105
|
-
sourceContext: sinon.match.object,
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
it('logs errors in the `handle` method', function () {
|
|
112
|
-
const [, middleware] = jsonBodyParserStub();
|
|
113
|
-
const err = new Error('yikes!');
|
|
114
|
-
handle.throws(err);
|
|
115
|
-
|
|
116
|
-
simulateRequestScope(() => {
|
|
117
|
-
middleware(req, res, next);
|
|
118
|
-
|
|
119
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
120
|
-
{ err, funcKey: 'assess-dataflow-source:restify.plugins.jsonBodyParser.parseJson' },
|
|
121
|
-
'unable to handle Restify source',
|
|
122
|
-
);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('logs errors in the `handle` method 2 ', function () {
|
|
127
|
-
const [, middleware] = jsonBodyParserStub({ mapParams: true });
|
|
128
|
-
const err = new Error('yikes!');
|
|
129
|
-
handle.onCall(1).throws(err);
|
|
130
|
-
|
|
131
|
-
simulateRequestScope(() => {
|
|
132
|
-
middleware(req, res, next);
|
|
133
|
-
|
|
134
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
135
|
-
{ err, funcKey: 'assess-dataflow-source:restify.plugins.jsonBodyParser.parseJson' },
|
|
136
|
-
'unable to handle Restify source',
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { InputType } = require('@contrast/common');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
const init = require('./router');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources restify router', function () {
|
|
10
|
-
let core, simulateRequestScope, handle, Router, req;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
handle = sinon.stub(core.assess.dataflow.sources, 'handle');
|
|
15
|
-
|
|
16
|
-
Router = { prototype: { lookup: sinon.stub() } };
|
|
17
|
-
req = {};
|
|
18
|
-
|
|
19
|
-
core.depHooks.resolve
|
|
20
|
-
.withArgs({ name: 'restify', file: 'lib/router.js', version: '>=8 <12' })
|
|
21
|
-
.yields(Router);
|
|
22
|
-
|
|
23
|
-
init(core).install();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('does not call `handle` when there is no assess policy in request context', function () {
|
|
27
|
-
simulateRequestScope(() => {
|
|
28
|
-
Router.prototype.lookup(req);
|
|
29
|
-
|
|
30
|
-
expect(handle).not.called;
|
|
31
|
-
expect(core.logger.trace.callCount).greaterThan(0);
|
|
32
|
-
expect(core.logger.trace.lastCall.args[0]).includes('Assess intentionally disabled');
|
|
33
|
-
}, { assess: { policy: null } });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('does not call `handle` when body is already tracked', function () {
|
|
37
|
-
simulateRequestScope(() => {
|
|
38
|
-
Router.prototype.lookup(req);
|
|
39
|
-
|
|
40
|
-
expect(handle).not.to.have.been.called;
|
|
41
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
42
|
-
{ funcKey: 'assess-dataflow-source:restify.Router.prototype.lookup' },
|
|
43
|
-
'values already tracked'
|
|
44
|
-
);
|
|
45
|
-
}, { assess: { parsedParams: true } });
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('calls `handle` appropriately', function () {
|
|
49
|
-
req.params = { foo: 'bar' };
|
|
50
|
-
|
|
51
|
-
simulateRequestScope(() => {
|
|
52
|
-
Router.prototype.lookup(req);
|
|
53
|
-
|
|
54
|
-
expect(handle).to.have.been.calledWith({
|
|
55
|
-
context: 'req.params',
|
|
56
|
-
data: req.params,
|
|
57
|
-
inputType: InputType.URL_PARAMETER,
|
|
58
|
-
name: 'restify.Router.prototype.lookup',
|
|
59
|
-
stacktraceOpts: {
|
|
60
|
-
constructorOpt: sinon.match.func,
|
|
61
|
-
prependFrames: [sinon.match.func],
|
|
62
|
-
},
|
|
63
|
-
sourceContext: sinon.match.object,
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('logs errors in the `handle` method', function () {
|
|
69
|
-
const err = new Error('yikes!');
|
|
70
|
-
handle.throws(err);
|
|
71
|
-
|
|
72
|
-
simulateRequestScope(() => {
|
|
73
|
-
Router.prototype.lookup(req);
|
|
74
|
-
|
|
75
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
76
|
-
{ err, funcKey: 'assess-dataflow-source:restify.Router.prototype.lookup' },
|
|
77
|
-
'unable to handle Restify source',
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const { expect } = require('chai');
|
|
6
|
-
const utils = require('./tag-utils');
|
|
7
|
-
|
|
8
|
-
const parsed = require('@contrast/test/data/tag-util-args-and-results');
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow tag-utils - verify all existing usage', function() {
|
|
11
|
-
for (const test in parsed) {
|
|
12
|
-
const fnName = test.slice(0, -4);
|
|
13
|
-
const { lines, tests } = parsed[test];
|
|
14
|
-
describe(fnName, function() {
|
|
15
|
-
if (!utils[fnName]) {
|
|
16
|
-
throw new Error(`No test for ${fnName}`);
|
|
17
|
-
}
|
|
18
|
-
for (let i = 0; i < tests.length; i++) {
|
|
19
|
-
it(lines[i], function() {
|
|
20
|
-
const { args, ret } = tests[i];
|
|
21
|
-
const r = utils[fnName](...args);
|
|
22
|
-
expect(r).to.deep.equal(ret);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
});
|