-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added owasp api limits for array, string and integer
Fixes #16
- Loading branch information
1 parent
fbfd15e
commit 8b95700
Showing
7 changed files
with
975 additions
and
39 deletions.
There are no files selected for viewing
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,78 @@ | ||
import { DiagnosticSeverity } from "@stoplight/types"; | ||
import testRule from "./__helpers__/helper"; | ||
|
||
testRule("owasp:api4:2019-array-limit", [ | ||
{ | ||
name: "valid case: oas2", | ||
document: { | ||
swagger: "2.0", | ||
info: { version: "1.0" }, | ||
definitions: { | ||
Foo: { | ||
type: "array", | ||
maxItems: 99, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "valid case: oas3", | ||
document: { | ||
openapi: "3.0.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "array", | ||
maxItems: 99, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas2 missing maxItems", | ||
document: { | ||
swagger: "2.0", | ||
info: { version: "1.0" }, | ||
definitions: { | ||
Foo: { | ||
type: "array", | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type array must specify maxItems.", | ||
path: ["definitions", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas3 missing maxItems", | ||
document: { | ||
openapi: "3.0.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "array", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type array must specify maxItems.", | ||
path: ["components", "schemas", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
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,77 @@ | ||
import { DiagnosticSeverity } from "@stoplight/types"; | ||
import testRule from "./__helpers__/helper"; | ||
|
||
testRule("owasp:api4:2019-integer-format", [ | ||
{ | ||
name: "valid case: format - int32", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
format: "int32", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "valid case: format - int64", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
format: "int64", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "valid case: format - whatever", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
format: "whatever", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "invalid case: no format", | ||
document: { | ||
openapi: "3.1.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type integer must specify format (int32 or int64).", | ||
path: ["components", "schemas", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
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,124 @@ | ||
import { DiagnosticSeverity } from "@stoplight/types"; | ||
import testRule from "./__helpers__/helper"; | ||
|
||
testRule("owasp:api4:2019-integer-limit-legacy", [ | ||
{ | ||
name: "valid case: oas2", | ||
document: { | ||
swagger: "2.0", | ||
info: { version: "1.0" }, | ||
definitions: { | ||
Foo: { | ||
type: "integer", | ||
minimum: 1, | ||
maximum: 99, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "valid case: oas3.0", | ||
document: { | ||
openapi: "3.0.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
minimum: 1, | ||
maximum: 99, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas2 missing maximum", | ||
document: { | ||
swagger: "2.0", | ||
info: { version: "1.0" }, | ||
definitions: { | ||
Foo: { | ||
type: "integer", | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type integer must specify minimum and maximum.", | ||
path: ["definitions", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas3.0 missing maximum", | ||
document: { | ||
openapi: "3.0.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type integer must specify minimum and maximum.", | ||
path: ["components", "schemas", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas2 has maximum but missing minimum", | ||
document: { | ||
swagger: "2.0", | ||
info: { version: "1.0" }, | ||
definitions: { | ||
Foo: { | ||
type: "integer", | ||
maximum: 99, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type integer must specify minimum and maximum.", | ||
path: ["definitions", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: "invalid case: oas3.0 has maximum but missing minimum", | ||
document: { | ||
openapi: "3.0.0", | ||
info: { version: "1.0" }, | ||
components: { | ||
schemas: { | ||
Foo: { | ||
type: "integer", | ||
maximum: 99, | ||
}, | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: "Schema of type integer must specify minimum and maximum.", | ||
path: ["components", "schemas", "Foo"], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
Oops, something went wrong.