Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 00d9daf

Browse files
committed
fix(oas3): warn for unsupported 3.1 security scheme mutalTLS
1 parent 9ae7df3 commit 00d9daf

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/openapi3-parser/lib/parser/oas/parseSecuritySchemeObject.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ function parseSecuritySchemeObject(context, object) {
115115
createWarning(namespace, `'${name}' 'type' must be either 'apiKey', 'http', 'oauth2' or 'openIdConnect'`),
116116
getValue
117117
);
118-
const validateType = R.unless(isValidTypeValue, createInvalidTypeWarning);
118+
119+
const isMutalTLSOnOpenAPI31 = R.both(
120+
hasValue('mutalTLS'),
121+
() => context.isOpenAPIVersionMoreThanOrEqual(3, 1)
122+
);
123+
const validateType = R.unless(
124+
R.either(isValidTypeValue, isMutalTLSOnOpenAPI31),
125+
createInvalidTypeWarning
126+
);
119127

120128
const createUnsupportedTypeWarning = member => createWarning(namespace,
121129
`'${name}' 'type' '${member.value.toValue()}' is unsupported`, member.value);

packages/openapi3-parser/test/unit/parser/oas/parseSecuritySchemeObject-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ describe('Security Scheme Object', () => {
5353
expect(parseResult.length).to.equal(1);
5454
expect(parseResult).to.contain.warning("'Security Scheme Object' 'type' 'openIdConnect' is unsupported");
5555
});
56+
57+
it('provides an unsupported warning for mutalTLS type in OpenAPI >= 3.1', () => {
58+
context.openapiVersion = { major: 3, minor: 1 };
59+
const securityScheme = new namespace.elements.Object({
60+
type: 'mutalTLS',
61+
});
62+
63+
const parseResult = parse(context, securityScheme);
64+
65+
expect(parseResult.length).to.equal(1);
66+
expect(parseResult).to.contain.warning("'Security Scheme Object' 'type' 'mutalTLS' is unsupported");
67+
});
68+
69+
it('provides an invalid warning for mutalTLS type in OpenAPI 3.0', () => {
70+
const securityScheme = new namespace.elements.Object({
71+
type: 'mutalTLS',
72+
});
73+
74+
const parseResult = parse(context, securityScheme);
75+
76+
expect(parseResult.length).to.equal(1);
77+
expect(parseResult).to.contain.warning("'Security Scheme Object' 'type' must be either 'apiKey', 'http', 'oauth2' or 'openIdConnect'");
78+
});
5679
});
5780

5881
describe('#name', () => {

0 commit comments

Comments
 (0)