Skip to content

Commit ce9866f

Browse files
Trickfilm400keithamus
andauthoredJun 9, 2023
Dependency updates to fix security vulnerabilities (#306)
* build(deps): Updated superagent,cookiejar,qs to the latest version Update superagent to latest version for fixing security vulnerabilities * build(deps): Locking superagent types to 4.1.13 due to failing build * extend cookie expiry dates * use a more reliable site for network tests * use webooks.site for echo tests * ditch console log * increase timeout on tests that hit webook.site --------- Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
1 parent dbba17c commit ce9866f

File tree

4 files changed

+381
-238
lines changed

4 files changed

+381
-238
lines changed
 

‎package-lock.json

+311-197
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
},
5252
"dependencies": {
5353
"@types/chai": "4",
54-
"@types/superagent": "^4.1.10",
54+
"@types/superagent": "4.1.13",
5555
"charset": "^1.0.1",
56-
"cookiejar": "^2.1.2",
56+
"cookiejar": "^2.1.4",
5757
"is-ip": "^2.0.0",
5858
"methods": "^1.1.2",
59-
"qs": "^6.5.1",
60-
"superagent": "^6.1.0"
59+
"qs": "^6.11.2",
60+
"superagent": "^8.0.9"
6161
},
6262
"devDependencies": {
6363
"@semantic-release/changelog": "^5.0.1",

‎test/http.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ describe('assertions', function () {
300300
headers: {
301301
'set-cookie': [
302302
'name=value',
303-
'name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT'
303+
'name2=value2; Expires=Wed, 09 Jun 2038 10:18:14 GMT'
304304
]
305305
}
306306
};
@@ -333,7 +333,7 @@ describe('assertions', function () {
333333
headers: {
334334
'set-cookie': [
335335
'name=value;',
336-
'name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT',
336+
'name2=value2; Expires=Wed, 09 Jun 2038 10:18:14 GMT',
337337
'name3=value3; Domain=.somedomain.com',
338338
]
339339
}
@@ -369,7 +369,7 @@ describe('assertions', function () {
369369
var agent = chai.request.agent();
370370
var cookies = [
371371
'name=value',
372-
'name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT',
372+
'name2=value2; Expires=Wed, 09 Jun 2038 10:18:14 GMT',
373373
'name3=value3; Domain=.somedomain.com',
374374
];
375375
if (agent.jar) // Using superagent.Agent (node)

‎test/request.js

+63-34
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('request', function () {
1717
});
1818

1919
it('can request a web page', function (done) {
20-
request('https://httpbin.org')
21-
.get('/html')
20+
request('https://chaijs.com')
21+
.get('/guide/')
2222
.end(function (err, res) {
2323
res.should.have.status(200);
2424
res.should.be.html;
@@ -35,8 +35,8 @@ describe('request', function () {
3535
});
3636

3737
it('can request JSON data', function (done) {
38-
request('https://httpbin.org')
39-
.get('/get')
38+
request('https://chaijs.com')
39+
.get('/package-lock.json')
4040
.end(function (err, res) {
4141
res.should.have.status(200);
4242
res.should.be.json;
@@ -49,47 +49,76 @@ describe('request', function () {
4949
});
5050

5151
it('can read response headers', function (done) {
52-
request('https://httpbin.org')
53-
.get('/response-headers')
54-
.query({'content-type': 'application/json'})
55-
.query({'pragma': 'test1'})
56-
.query({'location': 'test2'})
57-
.query({'x-api-key': 'test3'})
52+
this.timeout(5000)
53+
request('https://webhook.site')
54+
.post('/token')
5855
.end(function (err, res) {
59-
res.should.have.status(200);
60-
61-
// Content-Type and Pragma are supported on Node and browser
62-
res.should.be.json;
63-
res.should.have.header('Content-Type', /json$/);
64-
res.should.have.header('Pragma', 'test1');
56+
const uuid = res.body.uuid;
57+
request('https://webhook.site')
58+
.get('/' + uuid)
59+
.query({'content-type': 'application/json'})
60+
.query({'pragma': 'test1'})
61+
.query({'location': 'test2'})
62+
.query({'x-api-key': 'test3'})
63+
.end(function (err, res) {
64+
res.should.have.status(200);
65+
request('https://webhook.site')
66+
.get('/token/' + uuid + '/requests?sorting=newest&per_page=1')
67+
.end(function (err, res) {
68+
// Content-Type and Pragma are supported on Node and browser
69+
res.should.be.json;
70+
res.should.have.nested.property('.body.data.0.query.content-type', 'application/json')
71+
res.should.have.nested.property('.body.data.0.query.pragma', 'test1')
6572

66-
// When running in a browser, only "simple" headers are readable
67-
// https://www.w3.org/TR/cors/#simple-response-header
68-
isNode && res.should.have.header('Location', 'test2');
69-
isNode && res.should.have.header('X-API-Key', 'test3');
70-
isBrowser && res.should.not.have.header('Location');
71-
isBrowser && res.should.not.have.header('X-API-Key');
73+
// When running in a browser, only "simple" headers are readable
74+
// https://www.w3.org/TR/cors/#simple-response-header
75+
isNode && res.should.have.nested.property('.body.data.0.query.location', 'test2')
76+
isNode && res.should.have.nested.property('.body.data.0.query.x-api-key', 'test3')
77+
isBrowser && res.should.not.have.nested.property('.body.data.0.query.location');
78+
isBrowser && res.should.not.have.nested.property('.body.data.0.query.x-api-key');
7279

73-
done(err);
80+
done(err);
81+
});
82+
});
7483
});
7584
});
7685

7786
it('succeeds when response has an error status', function (done) {
78-
request('https://httpbin.org')
79-
.get('/status/400')
87+
request('https://chaijs.com')
88+
.get('/404')
8089
.end(function (err, res) {
81-
res.should.have.status(400);
90+
res.should.have.status(404);
8291
done(err);
8392
});
8493
});
8594

8695
it('can be augmented with promises', function (done) {
87-
request('https://httpbin.org')
88-
.get('/get')
89-
.set('X-API-Key', 'test3')
96+
this.timeout(5000)
97+
let uuid = ''
98+
request('https://webhook.site')
99+
.post('/token')
100+
.then(function (res) {
101+
uuid = res.body.uuid;
102+
return res.body.uuid;
103+
})
104+
.then(function (uuid) {
105+
return request('https://webhook.site')
106+
.get('/' + uuid)
107+
.query({'content-type': 'application/json'})
108+
.query({'x-api-key': 'test3'})
109+
})
90110
.then(function (res) {
91111
res.should.have.status(200);
92-
res.body.headers['X-Api-Key'].should.equal('test3');
112+
return request('https://webhook.site')
113+
.get('/token/' + uuid + '/requests?sorting=newest&per_page=1')
114+
})
115+
.then(function (res) {
116+
res.should.have.status(200);
117+
res.should.be.json;
118+
res.should.have.nested.property('.body.data.0.query.content-type', 'application/json')
119+
res.should.have.nested.property('.body.data.0.query.x-api-key', 'test3')
120+
})
121+
.then(function () {
93122
throw new Error('Testing catch');
94123
})
95124
.then(function () {
@@ -103,11 +132,11 @@ describe('request', function () {
103132
.then(done, done);
104133
});
105134

106-
it('can resolve a promise given status code of 400', function () {
107-
return request('https://httpbin.org')
108-
.get('/status/400')
135+
it('can resolve a promise given status code of 404', function () {
136+
return request('https://chaijs.com')
137+
.get('/404')
109138
.then(function (res) {
110-
res.should.have.status(400);
139+
res.should.have.status(404);
111140
});
112141
});
113142
});

0 commit comments

Comments
 (0)
Please sign in to comment.