Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rate limit responses check for content too
- Loading branch information
1 parent
edb735b
commit 95b862d
Showing
2 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
__tests__/owasp-api4-2019-rate-limit-responses-429.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { DiagnosticSeverity } from "@stoplight/types"; | ||
import testRule from "./__helpers__/helper"; | ||
|
||
testRule("owasp:api4:2019-rate-limit-responses-429", [ | ||
{ | ||
name: "valid: defines a 429 response with content", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
paths: { | ||
"/": { | ||
get: { | ||
responses: { | ||
"429": { | ||
description: "ok", | ||
content: { | ||
"application/problem+json": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "invalid: 429 is not defined at all", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
paths: { | ||
"/": { | ||
get: { | ||
responses: { | ||
"200": { | ||
description: "ok", | ||
content: { | ||
"application/json": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: | ||
"Operation is missing rate limiting response in responses[429].", | ||
path: ["paths", "/", "get", "responses"], | ||
severity: DiagnosticSeverity.Warning, | ||
}, | ||
{ | ||
message: | ||
"Operation is missing rate limiting response in responses[429].content.", | ||
path: ["paths", "/", "get", "responses"], | ||
severity: DiagnosticSeverity.Warning, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "invalid: 429 exists but content is missing", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
paths: { | ||
"/": { | ||
get: { | ||
responses: { | ||
"429": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: | ||
"Operation is missing rate limiting response in [429].content.", | ||
path: ["paths", "/", "get", "responses", "429"], | ||
severity: DiagnosticSeverity.Warning, | ||
}, | ||
], | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters