@@ -3,12 +3,21 @@ import testRule from './__helpers__/tester';
3
3
4
4
testRule ( 'oas2-operation-security-defined' , [
5
5
{
6
- name : 'a correct object (just in body) ' ,
6
+ name : 'valid case ' ,
7
7
document : {
8
8
swagger : '2.0' ,
9
9
securityDefinitions : {
10
- apikey : { } ,
10
+ apikey : {
11
+ type : 'apiKey' ,
12
+ name : 'api_key' ,
13
+ in : 'header' ,
14
+ } ,
11
15
} ,
16
+ security : [
17
+ {
18
+ apikey : [ ] ,
19
+ } ,
20
+ ] ,
12
21
paths : {
13
22
'/path' : {
14
23
get : {
@@ -25,37 +34,44 @@ testRule('oas2-operation-security-defined', [
25
34
} ,
26
35
27
36
{
28
- name : 'a correct object (API-level security) ' ,
37
+ name : 'valid and invalid object ' ,
29
38
document : {
30
39
swagger : '2.0' ,
31
40
securityDefinitions : {
32
- apikey : { } ,
41
+ apikey : {
42
+ type : 'apiKey' ,
43
+ name : 'api_key' ,
44
+ in : 'header' ,
45
+ } ,
46
+ oauth2 : {
47
+ type : 'oauth2' ,
48
+ flows : 'accessCode' ,
49
+ authorizationUrl : 'https://example.com/api/oauth/dialog' ,
50
+ tokenUrl : 'https://example.com/api/oauth/token' ,
51
+ scopes : {
52
+ 'write:pets' : 'modify pets in your account' ,
53
+ 'read:pets' : 'read your pets' ,
54
+ } ,
55
+ } ,
33
56
} ,
34
57
security : [
35
58
{
36
59
apikey : [ ] ,
60
+ basic : [ ] ,
61
+ oauth2 : [ 'write:pets' ] ,
37
62
} ,
38
- ] ,
39
- paths : {
40
- '/path' : {
41
- get : { } ,
63
+ { } ,
64
+ {
65
+ oauth2 : [ 'write:users' , 'read:users' ] ,
42
66
} ,
43
- } ,
44
- } ,
45
- errors : [ ] ,
46
- } ,
47
-
48
- {
49
- name : 'invalid object' ,
50
- document : {
51
- swagger : '2.0' ,
52
- securityDefinitions : { } ,
67
+ ] ,
53
68
paths : {
54
- '/path ' : {
69
+ '/users ' : {
55
70
get : {
56
71
security : [
57
72
{
58
- apikey : [ ] ,
73
+ bearer : [ ] ,
74
+ oauth2 : [ ] ,
59
75
} ,
60
76
] ,
61
77
} ,
@@ -64,45 +80,32 @@ testRule('oas2-operation-security-defined', [
64
80
} ,
65
81
errors : [
66
82
{
67
- message : 'Operation "security" values must match a scheme defined in the "securityDefinitions" object.' ,
68
- path : [ 'paths' , '/path' , 'get' , ' security', '0' , 'apikey ' ] ,
83
+ message : 'API "security" values must match a scheme defined in the "securityDefinitions" object.' ,
84
+ path : [ 'security' , '0' , 'basic ' ] ,
69
85
severity : DiagnosticSeverity . Warning ,
70
86
} ,
71
- ] ,
72
- } ,
73
-
74
- {
75
- name : 'invalid object (API-level security)' ,
76
- document : {
77
- swagger : '2.0' ,
78
- securityDefinitions : { } ,
79
- security : [
80
- {
81
- apikey : [ ] ,
82
- } ,
83
- ] ,
84
- paths : {
85
- '/path' : {
86
- get : { } ,
87
- } ,
87
+ {
88
+ message : '"write:users" must be listed among scopes.' ,
89
+ path : [ 'security' , '2' , 'oauth2' , '0' ] ,
90
+ severity : DiagnosticSeverity . Warning ,
88
91
} ,
89
- } ,
90
- errors : [
91
92
{
92
- message : 'API "security" values must match a scheme defined in the "securityDefinitions" object.' ,
93
- path : [ 'security' , '0' , 'apikey' ] ,
93
+ message : '"read:users" must be listed among scopes.' ,
94
+ path : [ 'security' , '2' , 'oauth2' , '1' ] ,
95
+ severity : DiagnosticSeverity . Warning ,
96
+ } ,
97
+ {
98
+ message : 'Operation "security" values must match a scheme defined in the "securityDefinitions" object.' ,
99
+ path : [ 'paths' , '/users' , 'get' , 'security' , '0' , 'bearer' ] ,
94
100
severity : DiagnosticSeverity . Warning ,
95
101
} ,
96
102
] ,
97
103
} ,
98
104
99
105
{
100
- name : 'valid and invalid object ' ,
106
+ name : 'missing securityDefinitions ' ,
101
107
document : {
102
108
swagger : '2.0' ,
103
- securityDefinitions : {
104
- apikey : { } ,
105
- } ,
106
109
paths : {
107
110
'/path' : {
108
111
get : {
@@ -111,12 +114,18 @@ testRule('oas2-operation-security-defined', [
111
114
apikey : [ ] ,
112
115
basic : [ ] ,
113
116
} ,
117
+ { } ,
114
118
] ,
115
119
} ,
116
120
} ,
117
121
} ,
118
122
} ,
119
123
errors : [
124
+ {
125
+ message : 'Operation "security" values must match a scheme defined in the "securityDefinitions" object.' ,
126
+ path : [ 'paths' , '/path' , 'get' , 'security' , '0' , 'apikey' ] ,
127
+ severity : DiagnosticSeverity . Warning ,
128
+ } ,
120
129
{
121
130
message : 'Operation "security" values must match a scheme defined in the "securityDefinitions" object.' ,
122
131
path : [ 'paths' , '/path' , 'get' , 'security' , '0' , 'basic' ] ,
@@ -126,28 +135,58 @@ testRule('oas2-operation-security-defined', [
126
135
} ,
127
136
128
137
{
129
- name : 'valid and invalid object (API-level security) ' ,
138
+ name : 'invalid scopes in Security Scheme object ' ,
130
139
document : {
131
140
swagger : '2.0' ,
132
141
securityDefinitions : {
133
- apikey : { } ,
134
- } ,
135
- security : [
136
- {
137
- apikey : [ ] ,
138
- basic : [ ] ,
142
+ authorizationCode : {
143
+ type : 'oauth2' ,
144
+ flows : 'accessCode' ,
145
+ authorizationUrl : 'https://example.com/api/oauth/dialog' ,
146
+ tokenUrl : 'https://example.com/api/oauth/token' ,
147
+ scopes : null ,
139
148
} ,
140
- ] ,
149
+ noFlows : {
150
+ type : 'oauth2' ,
151
+ } ,
152
+ client : {
153
+ type : 'oauth2' ,
154
+ flows : {
155
+ clientCredentials : null ,
156
+ } ,
157
+ } ,
158
+ } ,
141
159
paths : {
142
160
'/path' : {
143
- get : { } ,
161
+ get : {
162
+ security : [
163
+ {
164
+ noFlows : [ 'read:users' ] ,
165
+ authorizationCode : [ 'write:users' ] ,
166
+ } ,
167
+ {
168
+ noFlows : [ ] ,
169
+ client : [ 'read:users' ] ,
170
+ } ,
171
+ ] ,
172
+ } ,
144
173
} ,
145
174
} ,
146
175
} ,
147
176
errors : [
148
177
{
149
- message : 'API "security" values must match a scheme defined in the "securityDefinitions" object.' ,
150
- path : [ 'security' , '0' , 'basic' ] ,
178
+ message : '"read:users" must be listed among scopes.' ,
179
+ path : [ 'paths' , '/path' , 'get' , 'security' , '0' , 'noFlows' , '0' ] ,
180
+ severity : DiagnosticSeverity . Warning ,
181
+ } ,
182
+ {
183
+ message : '"write:users" must be listed among scopes.' ,
184
+ path : [ 'paths' , '/path' , 'get' , 'security' , '0' , 'authorizationCode' , '0' ] ,
185
+ severity : DiagnosticSeverity . Warning ,
186
+ } ,
187
+ {
188
+ message : '"read:users" must be listed among scopes.' ,
189
+ path : [ 'paths' , '/path' , 'get' , 'security' , '1' , 'client' , '0' ] ,
151
190
severity : DiagnosticSeverity . Warning ,
152
191
} ,
153
192
] ,
0 commit comments