Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 85aba9f

Browse files
authored
Merge branch 'master' into fix-data-callback
2 parents a64b2c9 + d2c565d commit 85aba9f

File tree

6 files changed

+374
-2779
lines changed

6 files changed

+374
-2779
lines changed

.circleci/config.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ workflows:
2626
static_analysis:
2727
jobs:
2828
- test
29-
- size:
30-
requires:
31-
- test
3229
- coverage:
3330
requires:
3431
- test
@@ -100,13 +97,6 @@ jobs:
10097
- checkout
10198
- attach_workspace: { at: . }
10299
- run: yarn run report-coverage
103-
size:
104-
docker:
105-
- image: circleci/node:10-browsers
106-
steps:
107-
- checkout
108-
- attach_workspace: { at: . }
109-
- run: yarn run size
110100
snyk:
111101
docker:
112102
- image: circleci/node:10-browsers

History.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
v3.5.0 / 2021-1-5
2+
==========================
3+
* Update axios to fix the Server-Side Request Forgery vulnerability (#259)
4+
5+
6+
v3.4.1-beta.3 / 2020-10-26
7+
==========================
8+
* Update axios to fix the infinite retry bug (#255)
9+
* Use a local instance of axios to prevent client options leaking to other contexts (#255)
10+
11+
v3.4.1-beta.2 / 2020-06-10
12+
==========================
13+
* Update lodash (#222) (#221) from segmentio/dependabot/npm_and_yarn/lodash-4.17.11 8e9a91d
14+
* Fix typo (#220)
15+
* Update axios (#218)
16+
17+
118
v3.4.1-beta.1 / 2019-06-20
219
==========================
320

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Analytics {
4545
enumerable: true,
4646
value: typeof options.enable === 'boolean' ? options.enable : true
4747
})
48-
49-
axiosRetry(axios, {
48+
this.axiosClient = axios.create()
49+
axiosRetry(this.axiosClient, {
5050
retries: options.retryCount || 3,
5151
retryCondition: this._isErrorRetryable,
5252
retryDelay: axiosRetry.exponentialDelay
@@ -279,7 +279,7 @@ class Analytics {
279279
req.timeout = typeof this.timeout === 'string' ? ms(this.timeout) : this.timeout
280280
}
281281

282-
axios(req)
282+
this.axiosClient(req)
283283
.then(() => done())
284284
.catch(err => {
285285
if (err.response) {

package.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "analytics-node",
3-
"version": "3.4.0-beta.1",
3+
"version": "3.5.0",
44
"description": "The hassle-free way to integrate analytics into any Node.js application",
55
"license": "MIT",
66
"repository": "segmentio/analytics-node",
@@ -12,17 +12,10 @@
1212
"engines": {
1313
"node": ">=4"
1414
},
15-
"size-limit": [
16-
{
17-
"limit": "25 KB",
18-
"path": "index.js"
19-
}
20-
],
2115
"scripts": {
2216
"circle-lint": ".buildscript/circle.sh",
2317
"dependencies": "yarn",
24-
"size": "size-limit",
25-
"test": "standard && nyc ava && .buildscript/e2e.sh",
18+
"test": "standard && nyc ava --timeout=20s&& .buildscript/e2e.sh",
2619
"report-coverage": "nyc report --reporter=lcov > coverage.lcov && codecov",
2720
"np": "np --no-publish",
2821
"release": "yarn run np"
@@ -41,7 +34,7 @@
4134
],
4235
"dependencies": {
4336
"@segment/loosely-validate-event": "^2.0.0",
44-
"axios": "^0.19.0",
37+
"axios": "^0.21.1",
4538
"axios-retry": "^3.0.2",
4639
"lodash.isstring": "^4.0.1",
4740
"md5": "^2.2.1",
@@ -61,8 +54,13 @@
6154
"nyc": "^14.1.1",
6255
"pify": "^4.0.1",
6356
"sinon": "^7.3.2",
64-
"size-limit": "^1.3.5",
6557
"snyk": "^1.171.1",
6658
"standard": "^12.0.1"
59+
},
60+
"resolutions": {
61+
"kind-of": "^6.0.3",
62+
"lodash": "^4.17.19",
63+
"set-value": "^2.0.1",
64+
"yargs-parser": "^13.1.2"
6765
}
6866
}

test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const context = {
1919

2020
const metadata = { nodeVersion: process.versions.node }
2121
const port = 4063
22+
const separateAxiosClientPort = 4064
23+
const retryCount = 5
2224

2325
const createClient = options => {
2426
options = Object.assign({
@@ -33,6 +35,7 @@ const createClient = options => {
3335
}
3436

3537
test.before.cb(t => {
38+
let count = 0
3639
express()
3740
.use(bodyParser.json())
3841
.post('/v1/batch', (req, res) => {
@@ -62,6 +65,19 @@ test.before.cb(t => {
6265
return setTimeout(() => res.end(), 5000)
6366
}
6467

68+
if (batch[0] === 'axios-retry') {
69+
if (count++ === retryCount) return res.json({})
70+
return res.status(503).json({
71+
error: { message: 'Service Unavailable' }
72+
})
73+
}
74+
75+
if (batch[0] === 'axios-retry-forever') {
76+
return res.status(503).json({
77+
error: { message: 'Service Unavailable' }
78+
})
79+
}
80+
6581
res.json({})
6682
})
6783
.listen(port, t.end)
@@ -561,3 +577,63 @@ test('allows messages > 32kb', t => {
561577
client.track(event, noop)
562578
})
563579
})
580+
581+
test('ensure that failed requests are retried', async t => {
582+
const client = createClient({ retryCount: retryCount })
583+
const callback = spy()
584+
585+
client.queue = [
586+
{
587+
message: 'axios-retry',
588+
callback
589+
}
590+
]
591+
592+
await t.notThrows(client.flush())
593+
})
594+
595+
test('ensure that failed requests are not retried forever', async t => {
596+
const client = createClient()
597+
const callback = spy()
598+
599+
client.queue = [
600+
{
601+
message: 'axios-retry-forever',
602+
callback
603+
}
604+
]
605+
606+
await t.throws(client.flush())
607+
})
608+
609+
test('ensure other axios clients are not impacted by axios-retry', async t => {
610+
let client = createClient() // eslint-disable-line
611+
const axios = require('axios')
612+
613+
let callCounter = 0
614+
615+
// Client will return a successful response for any requests beyond the first
616+
let server = express()
617+
.use(bodyParser.json())
618+
.get('/v1/anotherEndpoint', (req, res) => {
619+
if (callCounter > 0) {
620+
res.status(200).send('Ok')
621+
} else {
622+
callCounter++
623+
res.status(503).send('Service down')
624+
}
625+
})
626+
.listen(separateAxiosClientPort)
627+
628+
await axios.get(`http://localhost:${separateAxiosClientPort}/v1/anotherEndpoint`)
629+
.then(response => {
630+
t.fail()
631+
})
632+
.catch(error => {
633+
if (error) {
634+
t.pass()
635+
}
636+
})
637+
638+
server.close()
639+
})

0 commit comments

Comments
 (0)