Skip to content

Commit

Permalink
test(definitions): refactor security tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Jun 15, 2024
1 parent 1e10bff commit 74b97ee
Show file tree
Hide file tree
Showing 82 changed files with 317 additions and 815 deletions.
72 changes: 72 additions & 0 deletions test/definitions/3.0.0/security/apiKey.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper.mjs';

const jsonSchema = require('@definitions/3.0.0/apiKey.json');

describe('API Key', () => {
it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": "apiKey",
"description": "apiKey",
"in": "user"
},
));

it(TestHelper.cannotBeEmptyTestName, () => TestHelper.objectIsNotValid(
jsonSchema,
{},
[
'must have required property \'type\'',
'must have required property \'in\''
]
));

it(TestHelper.isNotValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"description": "apiKey"
},
[
'must have required property \'type\'',
'must have required property \'in\''
]
));

it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": "apiKey",
"in": "user"
},
));

it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": "apiKey",
"description": "apiKey",
"in": "user",
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
}
},
));

it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended(
jsonSchema,
{
"type": "apiKey",
"description": "apiKey",
"in": "user",
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
},
"ext-number": 1
}
));
});
1 change: 0 additions & 1 deletion test/definitions/3.0.0/security/apiKey/empty.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/definitions/3.0.0/security/apiKey/example.json

This file was deleted.

10 changes: 0 additions & 10 deletions test/definitions/3.0.0/security/apiKey/extended.json

This file was deleted.

45 changes: 0 additions & 45 deletions test/definitions/3.0.0/security/apiKey/index.mjs

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions test/definitions/3.0.0/security/apiKey/wrongly extended.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

43 changes: 0 additions & 43 deletions test/definitions/3.0.0/security/asymmetricEncryption/index.mjs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

117 changes: 117 additions & 0 deletions test/definitions/3.0.0/security/default-implementation.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {describe, it} from 'vitest';
import TestHelper from '@test/test-helper.mjs';

describe.each([
{
name: 'X509',
type: 'X509',
description: 'X509 example',
schema: 'X509',
},
{
name: 'userPassword',
type: 'userPassword',
description: 'userPassword example',
schema: 'userPassword',
},
{
name: 'symmetricEncryption',
type: 'symmetricEncryption',
description: 'symmetricEncryption example',
schema: 'symmetricEncryption',
},
{
name: 'asymmetricEncryption',
type: 'asymmetricEncryption',
description: 'asymmetricEncryption example',
schema: 'asymmetricEncryption',
},
{
name: 'SASL: plain',
type: 'plain',
description: 'SASL plain example',
schema: 'SaslPlainSecurityScheme',
},
{
name: 'SASL: GSS-API',
type: 'gssapi',
description: 'SASL GSS-API example',
schema: 'SaslGssapiSecurityScheme',
},
{
name: 'SASL: SCRAM-SHA-256',
type: 'scramSha256',
description: 'SASL SCRAM-SHA-256 example',
schema: 'SaslScramSecurityScheme',
},
{
name: 'SASL: SCRAM-SHA-512',
type: 'scramSha512',
description: 'SASL SCRAM-SHA-512 example',
schema: 'SaslScramSecurityScheme',
},
])('$name', async (params) => {

const jsonSchema = await import(`@definitions/3.0.0/${params.schema}.json`);

it(TestHelper.exampleIsValidTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": params.type,
"description": params.description,
},
));

it(TestHelper.cannotBeEmptyTestName, () => TestHelper.objectIsNotValid(
jsonSchema,
{},
[
'must have required property \'type\''
]
));

it(TestHelper.isNotValidWithoutRequiredPropertiesTestName, () => TestHelper.objectIsNotValid(
jsonSchema,
{
"description": params.description,
},
[
'must have required property \'type\''
]
));

it(TestHelper.isValidWithOnlyRequiredPropertiesTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": params.type,
},
));

it(TestHelper.isValidWhenIsExtendedTestName, () => TestHelper.objectIsValid(
jsonSchema,
{
"type": params.type,
"description": params.description,
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
}
},
));

it(TestHelper.isNotValidWhenIsWronglyExtendedTestName, () => TestHelper.wronglyExtended(
jsonSchema,
{
"type": params.type,
"description": params.description,
"x-number": 0,
"x-string": "",
"x-object": {
"property": {}
},
"ext-number": 1
},
));

})
1 change: 0 additions & 1 deletion test/definitions/3.0.0/security/gssapi/empty.json

This file was deleted.

4 changes: 0 additions & 4 deletions test/definitions/3.0.0/security/gssapi/example.json

This file was deleted.

9 changes: 0 additions & 9 deletions test/definitions/3.0.0/security/gssapi/extended.json

This file was deleted.

Loading

0 comments on commit 74b97ee

Please sign in to comment.