From 6f30129bfe616d550f4e1c181290a71f58f3d84d Mon Sep 17 00:00:00 2001 From: Pavel Bodiachevskii Date: Wed, 22 May 2024 04:11:34 +0400 Subject: [PATCH] test(definitions): sasl security scheme https://github.com/asyncapi/spec-json-schemas/issues/539 --- test/definitions/3.0.0/security/index.js | 1 + .../security/saslSecurityScheme/gssapi.json | 4 ++ .../security/saslSecurityScheme/plain.json | 4 ++ .../saslSecurityScheme/saslSecurityScheme.js | 53 +++++++++++++++++++ .../saslSecurityScheme/scramSha256.json | 4 ++ .../saslSecurityScheme/scramSha512.json | 4 ++ 6 files changed, 70 insertions(+) create mode 100644 test/definitions/3.0.0/security/saslSecurityScheme/gssapi.json create mode 100644 test/definitions/3.0.0/security/saslSecurityScheme/plain.json create mode 100644 test/definitions/3.0.0/security/saslSecurityScheme/saslSecurityScheme.js create mode 100644 test/definitions/3.0.0/security/saslSecurityScheme/scramSha256.json create mode 100644 test/definitions/3.0.0/security/saslSecurityScheme/scramSha512.json diff --git a/test/definitions/3.0.0/security/index.js b/test/definitions/3.0.0/security/index.js index 120e3989..454b9a63 100644 --- a/test/definitions/3.0.0/security/index.js +++ b/test/definitions/3.0.0/security/index.js @@ -3,6 +3,7 @@ describe('Security Schemes', () => { require('./asymmetricEncryption/asymmetricEncryption.js'); require('./gssapi/gssapi.js'); require('./openIdconnect/openIdconnect.js'); + require('./saslSecurityScheme/saslSecurityScheme.js') require('./plain/plain.js'); require('./scramSha256/scramSha256.js'); require('./scramSha512/scramSha512.js'); diff --git a/test/definitions/3.0.0/security/saslSecurityScheme/gssapi.json b/test/definitions/3.0.0/security/saslSecurityScheme/gssapi.json new file mode 100644 index 00000000..f2784402 --- /dev/null +++ b/test/definitions/3.0.0/security/saslSecurityScheme/gssapi.json @@ -0,0 +1,4 @@ +{ + "type": "gssapi", + "description": "gssapi" +} diff --git a/test/definitions/3.0.0/security/saslSecurityScheme/plain.json b/test/definitions/3.0.0/security/saslSecurityScheme/plain.json new file mode 100644 index 00000000..5a3f8a63 --- /dev/null +++ b/test/definitions/3.0.0/security/saslSecurityScheme/plain.json @@ -0,0 +1,4 @@ +{ + "type": "plain", + "description": "plain" +} diff --git a/test/definitions/3.0.0/security/saslSecurityScheme/saslSecurityScheme.js b/test/definitions/3.0.0/security/saslSecurityScheme/saslSecurityScheme.js new file mode 100644 index 00000000..57fdb3dc --- /dev/null +++ b/test/definitions/3.0.0/security/saslSecurityScheme/saslSecurityScheme.js @@ -0,0 +1,53 @@ +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/SaslSecurityScheme.json'); +const validator = ajv + .addMetaSchema(require('../../../../../definitions/3.0.0/schema.json')) + .addSchema(require('../../../../../definitions/3.0.0/SaslScramSecurityScheme.json')) + .addSchema(require('../../../../../definitions/3.0.0/SaslPlainSecurityScheme.json')) + .addSchema(require('../../../../../definitions/3.0.0/SaslGssapiSecurityScheme.json')) + .addSchema(require('../../../../../definitions/3.0.0/specificationExtension.json')) + .compile(jsonSchema); + +describe('SASL Security Scheme', () => { + it('Plain', () => { + const model = JSON.parse(fs.readFileSync(`${__dirname}/plain.json`, 'utf-8')); + const validationResult = validator(model); + + assert(validationResult === true, 'Plain is valid'); + }); + + it('SCRAM-SHA-256', () => { + const model = JSON.parse(fs.readFileSync(`${__dirname}/scramSha256.json`, 'utf-8')); + const validationResult = validator(model); + + assert(validationResult === true, 'HTTP API Key is valid'); + }); + + it('SCRAM-SHA-512', () => { + const model = JSON.parse(fs.readFileSync(`${__dirname}/scramSha512.json`, 'utf-8')); + const validationResult = validator(model); + + assert(validationResult === true, 'HTTP API Key is valid'); + }); + + it('GSS-API', () => { + const model = JSON.parse(fs.readFileSync(`${__dirname}/gssapi.json`, 'utf-8')); + const validationResult = validator(model); + + assert(validationResult === true, 'HTTP API Key is valid'); + }); +}); diff --git a/test/definitions/3.0.0/security/saslSecurityScheme/scramSha256.json b/test/definitions/3.0.0/security/saslSecurityScheme/scramSha256.json new file mode 100644 index 00000000..120e37e8 --- /dev/null +++ b/test/definitions/3.0.0/security/saslSecurityScheme/scramSha256.json @@ -0,0 +1,4 @@ +{ + "type": "scramSha256", + "description": "scramSha256" +} diff --git a/test/definitions/3.0.0/security/saslSecurityScheme/scramSha512.json b/test/definitions/3.0.0/security/saslSecurityScheme/scramSha512.json new file mode 100644 index 00000000..82ab450c --- /dev/null +++ b/test/definitions/3.0.0/security/saslSecurityScheme/scramSha512.json @@ -0,0 +1,4 @@ +{ + "type": "scramSha512", + "description": "scramSha512" +}