serverest 2.24.4 → 2.25.0
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/CHANGELOG.md +41 -0
- package/README.md +14 -7
- package/package.json +8 -6
- package/src/app.js +3 -1
- package/src/middlewares/rate-limiter.js +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# [2.25.0](https://github.com/ServeRest/ServeRest/compare/v2.24.4...v2.25.0) (2021-11-22)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Chores
|
|
7
|
+
|
|
8
|
+
* criar multi-stage build para execução do projeto com nodemon ([9b8bca5](https://github.com/ServeRest/ServeRest/commit/9b8bca520a67eeaa0d08b3f1323a4cc515d38dd3))
|
|
9
|
+
* **docker:** avoid using 'prepare' on prod image ([bc4a9c7](https://github.com/ServeRest/ServeRest/commit/bc4a9c710fe7a91f27bd991dcfd31a260cbad6c8))
|
|
10
|
+
* **dockerfile:** incluir labels com informações do projeto ([7cbdd6c](https://github.com/ServeRest/ServeRest/commit/7cbdd6c0c60a7907941d1fd5dd2ea30a6d823f17))
|
|
11
|
+
* generate package-lock with newer version of npm ([e7b28a0](https://github.com/ServeRest/ServeRest/commit/e7b28a028c6d9ac547e58c4f12774a211578655a))
|
|
12
|
+
* guarantee that pipeline will break when test fail ([22a9629](https://github.com/ServeRest/ServeRest/commit/22a962982096b40fb7420beca3241161b7aa7f4c))
|
|
13
|
+
* **infra-test:** containerize infra test to easier run ([ad9529d](https://github.com/ServeRest/ServeRest/commit/ad9529dfeda47eacf487b947eec6b4bec7d28fe1))
|
|
14
|
+
* renomear test de api para teste de integração ([1368f38](https://github.com/ServeRest/ServeRest/commit/1368f38c186212d2307884dc0ee434c5ae8996a1))
|
|
15
|
+
* set specific version of base images ([ca4c152](https://github.com/ServeRest/ServeRest/commit/ca4c152ae3174376912977ade20119047f60b8fc))
|
|
16
|
+
* **sonar:** remover análise de coverage de arquivos que não necessitam ter testes ([9f5ae1f](https://github.com/ServeRest/ServeRest/commit/9f5ae1f3e28d71d860b8a58d68b4c3a030cde83b))
|
|
17
|
+
* **test:** exibir cor na execução de teste de integração para facilitar leitura ([44ef82d](https://github.com/ServeRest/ServeRest/commit/44ef82d6e2ea4a1f130d767f40e0341a8489a256))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Continuous Integration
|
|
21
|
+
|
|
22
|
+
* explicitar o nome da imagem docker ([a2eb8c2](https://github.com/ServeRest/ServeRest/commit/a2eb8c238e55acffc7de3b5149120b2627505090))
|
|
23
|
+
* remover execução de teste que não está containerizado ([123eb10](https://github.com/ServeRest/ServeRest/commit/123eb106101bc56201e188c3a925182fce0dc7e1))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Documentation
|
|
27
|
+
|
|
28
|
+
* **contributing:** detalhar a seção de testes com os pacotes utilizados e informação de coverage ([687395e](https://github.com/ServeRest/ServeRest/commit/687395e6e145384c4ac93af096b95bc01f480f2e))
|
|
29
|
+
* **readme:** adicionar repositório de automação em ruby ([bd828af](https://github.com/ServeRest/ServeRest/commit/bd828af2b993e3ef4558e130ed5252a287d52c9c))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Features
|
|
33
|
+
|
|
34
|
+
* **rate-limit:** interceptar requests de testes de carga para não enviar os dados para o moesif ([7683cd0](https://github.com/ServeRest/ServeRest/commit/7683cd0060b3312c17305496d580729f3a71a687))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
### Tests
|
|
38
|
+
|
|
39
|
+
* fix infra test error ([6345210](https://github.com/ServeRest/ServeRest/commit/634521029dadc92ba3e0b52775b008c7c80bf37f))
|
|
40
|
+
* **infra:** avoid test caching ([befbf6e](https://github.com/ServeRest/ServeRest/commit/befbf6e7d7318964d86f94cb4f12dcdb9b3ff407))
|
|
41
|
+
* **unitario:** garantir comportamento do método getRandomFinancialContributor ([d4debd7](https://github.com/ServeRest/ServeRest/commit/d4debd7691255e307dcef61c986d7486cfc51d30))
|
|
42
|
+
* utilizar multi-stage build ([ed69b62](https://github.com/ServeRest/ServeRest/commit/ed69b6269178ec13382f643a22226fc4dcfe2fe4))
|
|
43
|
+
|
|
3
44
|
## [2.24.4](https://github.com/ServeRest/ServeRest/compare/v2.24.3...v2.24.4) (2021-10-13)
|
|
4
45
|
|
|
5
46
|
|
package/README.md
CHANGED
|
@@ -129,8 +129,6 @@ Você pode encontrar as versões disponíveis na [lista de tags no Docker Hub](h
|
|
|
129
129
|
|
|
130
130
|
## Teste de carga
|
|
131
131
|
|
|
132
|
-
Para utilizar o ServeRest para estudo de teste de carga, sem gerar impacto, é preciso utilizar o header `monitor: false`.
|
|
133
|
-
|
|
134
132
|
Para acompanhar o comportamento do ambiente aonde o ServeRest está hospedado você pode acessar a página https://serverest.dev/status, pois contém informações como:
|
|
135
133
|
|
|
136
134
|
- Uso de CPU.
|
|
@@ -138,6 +136,18 @@ Para acompanhar o comportamento do ambiente aonde o ServeRest está hospedado vo
|
|
|
138
136
|
- Tempo de resposta.
|
|
139
137
|
- RPS (Requisições por segundo).
|
|
140
138
|
|
|
139
|
+
> Fez teste de carga? O que acha de compartilhar com o autor do projeto o relatório final contendo dados de RPS para auxiliar o ServeRest a entender o comportamento de sua infra?
|
|
140
|
+
|
|
141
|
+
## Badge
|
|
142
|
+
|
|
143
|
+
Criou repositório utilizando o ServeRest? Adicione o código abaixo no topo do README.md para ter a badge do projeto.
|
|
144
|
+
|
|
145
|
+
[](https://github.com/ServeRest/ServeRest/)
|
|
146
|
+
|
|
147
|
+
```markdown
|
|
148
|
+
[](https://github.com/ServeRest/ServeRest/)
|
|
149
|
+
```
|
|
150
|
+
|
|
141
151
|
## Exemplos de automação
|
|
142
152
|
|
|
143
153
|
Os repositórios abaixo são exemplos de automação com boas práticas e que consome o ServeRest.
|
|
@@ -146,12 +156,9 @@ Os repositórios abaixo são exemplos de automação com boas práticas e que co
|
|
|
146
156
|
- [JS > Automação com Supertest, Mocha e Chai - Paulo Gonçalves](https://github.com/PauloGoncalvesBH/sample-supertest)
|
|
147
157
|
- [Python > Automação com Pytest - Leonardo Tsuda](https://github.com/ltsuda/pytest-serverest-study)
|
|
148
158
|
- [Robot Framework > Automação com RequestsLibrary - Mayara Fernandes](https://github.com/mayribeirofernandes/testesrobotframework/tree/HEAD/ExemploAPI_ServeRest)
|
|
159
|
+
- [Ruby > Automação com HTTParty e RSpec - Bruno Quintanilha](https://github.com/braquintanilha/serverest-httparty-rspec)
|
|
149
160
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```markdown
|
|
153
|
-
[](https://github.com/ServeRest/ServeRest/)
|
|
154
|
-
```
|
|
161
|
+
Para encontrar mais repositórios acesse https://github.com/search?q=serverest&type=Repositories
|
|
155
162
|
|
|
156
163
|
## Patrocinadores
|
|
157
164
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverest",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0",
|
|
4
4
|
"description": "Servidor REST local de forma rápida e simples para estudo de testes de API",
|
|
5
5
|
"author": "Paulo Gonçalves <paulorochag@hotmail.com> (https://www.linkedin.com/in/paulo-goncalves/)",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -31,11 +31,12 @@
|
|
|
31
31
|
"prepare": "is-ci || husky install",
|
|
32
32
|
"commit": "cz",
|
|
33
33
|
"start": "node ./src/server.js",
|
|
34
|
-
"dev": "
|
|
34
|
+
"dev": "nodemon --legacy-watch -e json,js ./src/server.js --nodoc",
|
|
35
35
|
"test:mutation": "stryker run ./test/stryker.conf.js",
|
|
36
36
|
"test:mutation:diff": "stryker-diff-runner --path ./test/stryker.conf.js --branch trunk",
|
|
37
|
-
"test": "nyc mocha --config test/
|
|
38
|
-
"
|
|
37
|
+
"test:unit": "nyc --report-dir ./coverage-unit mocha --config test/unit/.mocharc.js",
|
|
38
|
+
"test:integration": "nyc --report-dir ./coverage-integration mocha --config test/integration/.mocharc.js",
|
|
39
|
+
"merge-lcov": "npx lcov-result-merger@3.1.0 'coverage-**/lcov.info' 'lcov.info'",
|
|
39
40
|
"lint": "standard",
|
|
40
41
|
"lint:fix": "standard --fix",
|
|
41
42
|
"lint:staged": "lint-staged",
|
|
@@ -51,11 +52,13 @@
|
|
|
51
52
|
"express-query-int": "^3.0.0",
|
|
52
53
|
"express-status-monitor": "^1.3.3",
|
|
53
54
|
"express-validation": "^3.0.8",
|
|
55
|
+
"is-ci": "^3.0.0",
|
|
54
56
|
"jsonwebtoken": "^8.5.1",
|
|
55
57
|
"moesif-nodejs": "^3.1.5",
|
|
56
58
|
"morgan": "^1.10.0",
|
|
57
59
|
"nedb-promises": "^5.0.0",
|
|
58
60
|
"open": "^8.0.6",
|
|
61
|
+
"rate-limiter-flexible": "^2.3.1",
|
|
59
62
|
"swagger-ui-express": "^4.1.4",
|
|
60
63
|
"yargs": "^16.2.0"
|
|
61
64
|
},
|
|
@@ -74,13 +77,12 @@
|
|
|
74
77
|
"@stryker-mutator/core": "^5.3.0",
|
|
75
78
|
"chai": "^4.3.4",
|
|
76
79
|
"commitizen": "^4.2.3",
|
|
77
|
-
"cross-env": "^7.0.3",
|
|
78
80
|
"cz-conventional-changelog": "^3.3.0",
|
|
79
81
|
"faker": "^5.5.3",
|
|
80
82
|
"husky": "^6.0.0",
|
|
81
|
-
"is-ci": "^3.0.0",
|
|
82
83
|
"lint-staged": "^10.5.4",
|
|
83
84
|
"mocha": "^8.3.2",
|
|
85
|
+
"nock": "^13.1.3",
|
|
84
86
|
"nodemon": "^2.0.7",
|
|
85
87
|
"nyc": "^15.1.0",
|
|
86
88
|
"semantic-release-docker": "^2.2.0",
|
package/src/app.js
CHANGED
|
@@ -16,6 +16,7 @@ const errorHandler = require('./middlewares/error-handler')
|
|
|
16
16
|
const logger = require('./utils/logger')
|
|
17
17
|
const { version } = require('../package.json')
|
|
18
18
|
const swaggerDocument = require('../docs/swagger.json')
|
|
19
|
+
const rateLimiter = require('./middlewares/rate-limiter')
|
|
19
20
|
|
|
20
21
|
const ehAmbienteDeTestes = process.env.NODE_ENV === 'serverest-test'
|
|
21
22
|
|
|
@@ -27,6 +28,7 @@ app.use(express.urlencoded({ extended: false }))
|
|
|
27
28
|
app.use(queryParser())
|
|
28
29
|
app.use(timeout())
|
|
29
30
|
app.use(cors())
|
|
31
|
+
app.use(rateLimiter)
|
|
30
32
|
|
|
31
33
|
app.disable('etag')
|
|
32
34
|
|
|
@@ -85,7 +87,7 @@ app.use('/produtos', require('./routes/produtos-route'))
|
|
|
85
87
|
app.use('/carrinhos', require('./routes/carrinhos-route'))
|
|
86
88
|
|
|
87
89
|
app.use(errorHandler)
|
|
88
|
-
app.use(
|
|
90
|
+
app.use((req, res) => {
|
|
89
91
|
res.status(405).send({
|
|
90
92
|
message: `Não é possível realizar ${req.method} em ${req.url}. Acesse ${urlDocumentacao()} para ver as rotas disponíveis e como utilizá-las.`
|
|
91
93
|
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
const { RateLimiterMemory } = require('rate-limiter-flexible')
|
|
4
|
+
|
|
5
|
+
const rateLimiter = new RateLimiterMemory({
|
|
6
|
+
points: 150, // requests
|
|
7
|
+
duration: 1 // segundo por IP
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// Adicionar header 'monitor: false' quando atingir o limite definido para não enviar informações para o moesif.
|
|
11
|
+
module.exports = async (req, res, next) => {
|
|
12
|
+
await rateLimiter.consume(req.ip)
|
|
13
|
+
.then(() => next())
|
|
14
|
+
.catch(() => {
|
|
15
|
+
req.headers.monitor = false
|
|
16
|
+
next()
|
|
17
|
+
})
|
|
18
|
+
}
|