Skip to content

Commit

Permalink
test(definitions): http security scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed May 22, 2024
1 parent 01a4ce7 commit 97f2e91
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
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 test/definitions/3.0.0/security/httpSecurityScheme/basic.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "http",
"description": "http",
"scheme": "basic"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "http",
"description": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
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');
});
});
1 change: 1 addition & 0 deletions test/definitions/3.0.0/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Security Schemes', () => {
require('./symmetricEncryption/symmetricEncryption.js');
require('./userPassword/userPassword.js');
require('./x509/x509.js');
require('./httpSecurityScheme/httpSecurityScheme.js')
require('./httpApiKey/httpApiKey.js');
require('./httpBearer/httpBearer.js');
require('./httpBasic/httpBasic.js');
Expand Down

0 comments on commit 97f2e91

Please sign in to comment.