forked from asyncapi/spec-json-schemas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(definitions): http security scheme
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
test/definitions/3.0.0/security/httpSecurityScheme/apiKey.json
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,6 @@ | ||
{ | ||
"type": "httpApiKey", | ||
"description": "httpApiKey", | ||
"name": "api_key", | ||
"in": "header" | ||
} |
5 changes: 5 additions & 0 deletions
5
test/definitions/3.0.0/security/httpSecurityScheme/basic.json
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,5 @@ | ||
{ | ||
"type": "http", | ||
"description": "http", | ||
"scheme": "basic" | ||
} |
6 changes: 6 additions & 0 deletions
6
test/definitions/3.0.0/security/httpSecurityScheme/bearer.json
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,6 @@ | ||
{ | ||
"type": "http", | ||
"description": "http", | ||
"scheme": "bearer", | ||
"bearerFormat": "JWT" | ||
} |
46 changes: 46 additions & 0 deletions
46
test/definitions/3.0.0/security/httpSecurityScheme/httpSecurityScheme.js
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,46 @@ | ||
const Ajv = require('ajv'); | ||
const assert = require('assert'); | ||
const addFormats = require('ajv-formats'); | ||
const fs = require('fs'); | ||
|
||
const ajv = new Ajv({ | ||
jsonPointers: true, | ||
allErrors: true, | ||
schemaId: '$id', | ||
logger: false, | ||
validateFormats: true, | ||
strict: false, | ||
}); | ||
addFormats(ajv); | ||
|
||
const jsonSchema = require('../../../../../definitions/3.0.0/HTTPSecurityScheme.json'); | ||
const validator = ajv | ||
.addMetaSchema(require('../../../../../definitions/3.0.0/schema.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/NonBearerHTTPSecurityScheme.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/BearerHTTPSecurityScheme.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/APIKeyHTTPSecurityScheme.json')) | ||
.addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json')) | ||
.compile(jsonSchema); | ||
|
||
describe('HTTP Security Scheme', () => { | ||
it('HTTP API Key', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/apiKey.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, 'HTTP API Key is valid'); | ||
}); | ||
|
||
it('HTTP Basic', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/basic.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, 'HTTP API Key is valid'); | ||
}); | ||
|
||
it('HTTP Bearer', () => { | ||
const model = JSON.parse(fs.readFileSync(`${__dirname}/bearer.json`, 'utf-8')); | ||
const validationResult = validator(model); | ||
|
||
assert(validationResult === true, 'HTTP API Key is valid'); | ||
}); | ||
}); |
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