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

Commit 677d8f2

Browse files
committed
feat(oas3): added integration test for security
1 parent 4479e3e commit 677d8f2

File tree

6 files changed

+184
-6
lines changed

6 files changed

+184
-6
lines changed

packages/fury-adapter-oas3-parser/lib/parser/oas/parseComponentsObject.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function parseComponentsObject(context, element) {
158158
if (value) {
159159
if (value instanceof namespace.elements.AuthScheme) {
160160
// eslint-disable-next-line no-param-reassign
161-
value.meta.id = key.clone();
161+
value.id = key.clone();
162162
array.push(value);
163163

164164
return;
@@ -167,7 +167,7 @@ function parseComponentsObject(context, element) {
167167
// append oauth2 flow names
168168
value.forEach((flow) => {
169169
// eslint-disable-next-line no-param-reassign
170-
flow.meta.id = `${key.toValue()} ${flow.grantTypeValue}`;
170+
flow.id = `${key.toValue()} ${flow.grantTypeValue}`;
171171
array.push(flow);
172172
});
173173
}

packages/fury-adapter-oas3-parser/lib/parser/oas/parseOpenAPIObject.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,23 @@ function parseOASObject(context, object) {
125125
parseObject(context, name, parseMember, requiredKeys, ['components']),
126126
(object) => {
127127
const api = object.get('info');
128+
const components = object.get('components');
129+
130+
if (components) {
131+
const schemes = R.or(components.get('securitySchemes'), new namespace.elements.Array());
132+
133+
if (schemes.length > 0) {
134+
api.push(new namespace.elements.Category(
135+
schemes.content, { classes: ['authSchemes'] }
136+
));
137+
}
138+
}
128139

129140
const resources = object.get('paths');
130141
if (resources) {
131142
api.content = api.content.concat(resources.content);
132143
}
133144

134-
const components = object.get('components');
135145
if (components) {
136146
const schemas = R.or(components.get('schemas'), new namespace.elements.Array())
137147
.content
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"element": "parseResult",
3+
"content": [
4+
{
5+
"element": "category",
6+
"meta": {
7+
"classes": {
8+
"element": "array",
9+
"content": [
10+
{
11+
"element": "string",
12+
"content": "api"
13+
}
14+
]
15+
},
16+
"title": {
17+
"element": "string",
18+
"content": "Auth Scheme"
19+
}
20+
},
21+
"attributes": {
22+
"version": {
23+
"element": "string",
24+
"content": "1.0.0"
25+
}
26+
},
27+
"content": [
28+
{
29+
"element": "category",
30+
"meta": {
31+
"classes": {
32+
"element": "array",
33+
"content": [
34+
{
35+
"element": "string",
36+
"content": "authSchemes"
37+
}
38+
]
39+
}
40+
},
41+
"content": [
42+
{
43+
"element": "Basic Authentication Scheme",
44+
"meta": {
45+
"id": {
46+
"element": "string",
47+
"content": "basic"
48+
}
49+
}
50+
}
51+
]
52+
},
53+
{
54+
"element": "resource",
55+
"attributes": {
56+
"href": {
57+
"element": "string",
58+
"content": "/user"
59+
}
60+
},
61+
"content": [
62+
{
63+
"element": "transition",
64+
"meta": {
65+
"title": {
66+
"element": "string",
67+
"content": "View the current User"
68+
}
69+
},
70+
"content": [
71+
{
72+
"element": "httpTransaction",
73+
"attributes": {
74+
"authSchemes": {
75+
"element": "array",
76+
"content": [
77+
{
78+
"element": "basic"
79+
}
80+
]
81+
}
82+
},
83+
"content": [
84+
{
85+
"element": "httpRequest",
86+
"attributes": {
87+
"method": {
88+
"element": "string",
89+
"content": "GET"
90+
}
91+
}
92+
},
93+
{
94+
"element": "httpResponse",
95+
"attributes": {
96+
"headers": {
97+
"element": "httpHeaders",
98+
"content": [
99+
{
100+
"element": "member",
101+
"content": {
102+
"key": {
103+
"element": "string",
104+
"content": "Content-Type"
105+
},
106+
"value": {
107+
"element": "string",
108+
"content": "application/json"
109+
}
110+
}
111+
}
112+
]
113+
},
114+
"statusCode": {
115+
"element": "string",
116+
"content": "200"
117+
}
118+
},
119+
"content": [
120+
{
121+
"element": "dataStructure",
122+
"content": {
123+
"element": "string"
124+
}
125+
},
126+
{
127+
"element": "copy",
128+
"content": "A user"
129+
}
130+
]
131+
}
132+
]
133+
}
134+
]
135+
}
136+
]
137+
}
138+
]
139+
}
140+
]
141+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Auth Scheme
5+
paths:
6+
/user:
7+
get:
8+
summary: View the current User
9+
security:
10+
- basic: []
11+
responses:
12+
'200':
13+
description: A user
14+
content:
15+
application/json:
16+
schema:
17+
type: string
18+
components:
19+
securitySchemes:
20+
basic:
21+
type: http
22+
scheme: basic

packages/fury-adapter-oas3-parser/test/integration/parse-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ describe('#parse', () => {
1111
const file = path.join(__dirname, 'fixtures', 'petstore');
1212
return testParseFixture(file, true);
1313
});
14+
15+
it('can parse auth schemes', () => {
16+
const file = path.join(__dirname, 'fixtures', 'auth-scheme');
17+
return testParseFixture(file);
18+
});
1419
});

packages/fury-adapter-oas3-parser/test/unit/parser/oas/parseComponentsObject-test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('Components Object', () => {
340340
const securitySchemes = parsedComponents.get('securitySchemes');
341341
expect(securitySchemes).to.be.instanceof(namespace.elements.Array);
342342
expect(securitySchemes.get(0)).to.be.instanceof(namespace.elements.AuthScheme);
343-
expect(securitySchemes.get(0).meta.id.toValue()).to.equal('token');
343+
expect(securitySchemes.get(0).id.toValue()).to.equal('token');
344344
});
345345

346346
it('parses oauth2 securityScheme with multiple flows', () => {
@@ -371,9 +371,9 @@ describe('Components Object', () => {
371371
const securitySchemes = parsedComponents.get('securitySchemes');
372372
expect(securitySchemes).to.be.instanceof(namespace.elements.Array);
373373
expect(securitySchemes.get(0)).to.be.instanceof(namespace.elements.AuthScheme);
374-
expect(securitySchemes.get(0).meta.id.toValue()).to.equal('oauth resource owner password credentials');
374+
expect(securitySchemes.get(0).id.toValue()).to.equal('oauth resource owner password credentials');
375375
expect(securitySchemes.get(1)).to.be.instanceof(namespace.elements.AuthScheme);
376-
expect(securitySchemes.get(1).meta.id.toValue()).to.equal('oauth implicit');
376+
expect(securitySchemes.get(1).id.toValue()).to.equal('oauth implicit');
377377
});
378378

379379
it('handles invalid security scheme', () => {

0 commit comments

Comments
 (0)