-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rulesets): add rules to validate channels.servers and server.sec…
…urity
- Loading branch information
1 parent
daae46c
commit aead22f
Showing
6 changed files
with
544 additions
and
0 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
118 changes: 118 additions & 0 deletions
118
packages/rulesets/src/asyncapi/__tests__/asyncapi-channel-servers.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,118 @@ | ||
import { DiagnosticSeverity } from '@stoplight/types'; | ||
import testRule from './__helpers__/tester'; | ||
|
||
testRule('asyncapi-channel-servers', [ | ||
{ | ||
name: 'valid case', | ||
document: { | ||
asyncapi: '2.2.0', | ||
servers: { | ||
development: {}, | ||
production: {}, | ||
}, | ||
channels: { | ||
channel: { | ||
servers: ['development'], | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'valid case - without defined servers', | ||
document: { | ||
asyncapi: '2.2.0', | ||
servers: { | ||
development: {}, | ||
production: {}, | ||
}, | ||
channels: { | ||
channel: {}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'valid case - with empty array', | ||
document: { | ||
asyncapi: '2.2.0', | ||
servers: { | ||
development: {}, | ||
production: {}, | ||
}, | ||
channels: { | ||
channel: { | ||
servers: [], | ||
}, | ||
}, | ||
}, | ||
errors: [], | ||
}, | ||
|
||
{ | ||
name: 'invalid case', | ||
document: { | ||
asyncapi: '2.2.0', | ||
servers: { | ||
development: {}, | ||
production: {}, | ||
}, | ||
channels: { | ||
channel: { | ||
servers: ['another-server'], | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Channel contains server that are not defined on the "servers" object.', | ||
path: ['channels', 'channel', 'servers', '0'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'invalid case - one server is defined, another one not', | ||
document: { | ||
asyncapi: '2.2.0', | ||
servers: { | ||
development: {}, | ||
production: {}, | ||
}, | ||
channels: { | ||
channel: { | ||
servers: ['production', 'another-server'], | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Channel contains server that are not defined on the "servers" object.', | ||
path: ['channels', 'channel', 'servers', '1'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
|
||
{ | ||
name: 'invalid case - without defined servers', | ||
document: { | ||
asyncapi: '2.2.0', | ||
channels: { | ||
channel: { | ||
servers: ['production'], | ||
}, | ||
}, | ||
}, | ||
errors: [ | ||
{ | ||
message: 'Channel contains server that are not defined on the "servers" object.', | ||
path: ['channels', 'channel', 'servers', '0'], | ||
severity: DiagnosticSeverity.Error, | ||
}, | ||
], | ||
}, | ||
]); |
Oops, something went wrong.