@@ -178,122 +178,16 @@ export function* compareReqHeader(
178178
179179 // security headers
180180 // ----------------
181+ const securityHeaders = [ ] ;
181182 if ( isValidRequest ( interaction ) ) {
182- let isSecured = false ;
183- const maybeResults : Result [ ] = [ ] ;
184183 for ( const scheme of operation . security || [ ] ) {
185- if ( Object . keys ( scheme ) . length === 0 ) {
186- isSecured = true ;
187- break ;
188- }
189184 for ( const schemeName of Object . keys ( scheme ) ) {
190185 const scheme = securitySchemes [ schemeName ] ;
191- switch ( scheme ?. type ) {
192- case "apiKey" :
193- switch ( scheme . in ) {
194- case "header" :
195- if ( requestHeaders . has ( scheme . name ) ) {
196- isSecured = true ;
197- } else {
198- maybeResults . push ( {
199- code : "request.authorization.missing" ,
200- message :
201- "Request Authorization header is missing but is required by the spec file" ,
202- mockDetails : {
203- ...baseMockDetails ( interaction ) ,
204- location : `[root].interactions[${ index } ].request.headers` ,
205- value : get ( interaction , "request.headers" ) ,
206- } ,
207- specDetails : {
208- location : `[root].paths.${ path } .${ method } ` ,
209- pathMethod : method ,
210- pathName : path ,
211- value : operation ,
212- } ,
213- type : "error" ,
214- } ) ;
215- }
216- requestHeaders . delete ( scheme . name ) ;
217- break ;
218- case "cookie" :
219- case "query" :
220- }
221- break ;
222- case "basic" : {
223- const basicAuth = requestHeaders . get ( "authorization" ) || "" ;
224- if ( basicAuth . startsWith ( "Basic " ) ) {
225- isSecured = true ;
226- } else {
227- maybeResults . push ( {
228- code : "request.authorization.missing" ,
229- message :
230- "Request Authorization header is missing but is required by the spec file" ,
231- mockDetails : {
232- ...baseMockDetails ( interaction ) ,
233- location : `[root].interactions[${ index } ].request.headers` ,
234- value : get ( interaction , "request.headers" ) ,
235- } ,
236- specDetails : {
237- location : `[root].paths.${ path } .${ method } ` ,
238- pathMethod : method ,
239- pathName : path ,
240- value : operation ,
241- } ,
242- type : "error" ,
243- } ) ;
244- }
245- break ;
246- }
247- case "http" : {
248- const auth = requestHeaders . get ( "authorization" ) || "" ;
249- let isValid = false ;
250- switch ( scheme . scheme ) {
251- case "basic" :
252- isValid = auth . toLowerCase ( ) . startsWith ( "basic " ) ;
253- break ;
254- case "bearer" :
255- isValid = auth . toLowerCase ( ) . startsWith ( "bearer " ) ;
256- break ;
257- }
258-
259- if ( config . get ( "no-authorization-schema" ) ) {
260- isValid = requestHeaders . get ( "authorization" ) !== null ;
261- }
262-
263- if ( isValid ) {
264- isSecured = true ;
265- } else {
266- maybeResults . push ( {
267- code : "request.authorization.missing" ,
268- message :
269- "Request Authorization header is missing but is required by the spec file" ,
270- mockDetails : {
271- ...baseMockDetails ( interaction ) ,
272- location : `[root].interactions[${ index } ].request.headers` ,
273- value : get ( interaction , "request.headers" ) ,
274- } ,
275- specDetails : {
276- location : `[root].paths.${ path } .${ method } ` ,
277- pathMethod : method ,
278- pathName : path ,
279- value : operation ,
280- } ,
281- type : "error" ,
282- } ) ;
283- }
284- break ;
285- }
286- case "mutualTLS" :
287- case "oauth2" :
288- case "openIdConnect" :
289- // ignore
186+ if ( scheme && scheme . type === "apiKey" && scheme . in === "header" ) {
187+ securityHeaders . push ( scheme . name . toLowerCase ( ) ) ;
290188 }
291189 }
292190 }
293-
294- if ( ! isSecured ) {
295- yield * maybeResults ;
296- }
297191 }
298192
299193 // specified headers
@@ -396,22 +290,24 @@ export function* compareReqHeader(
396290 // -----------------
397291 if ( isValidRequest ( interaction ) ) {
398292 for ( const [ headerName , headerValue ] of requestHeaders . entries ( ) ) {
399- yield {
400- code : "request.header.unknown" ,
401- message : `Request header is not defined in the spec file: ${ headerName } ` ,
402- mockDetails : {
403- ...baseMockDetails ( interaction ) ,
404- location : `[root].interactions[${ index } ].request.headers.${ headerName } ` ,
405- value : headerValue ,
406- } ,
407- specDetails : {
408- location : `[root].paths.${ path } .${ method } ` ,
409- pathMethod : method ,
410- pathName : path ,
411- value : operation ,
412- } ,
413- type : "warning" ,
414- } ;
293+ if ( ! securityHeaders . includes ( headerName ) ) {
294+ yield {
295+ code : "request.header.unknown" ,
296+ message : `Request header is not defined in the spec file: ${ headerName } ` ,
297+ mockDetails : {
298+ ...baseMockDetails ( interaction ) ,
299+ location : `[root].interactions[${ index } ].request.headers.${ headerName } ` ,
300+ value : headerValue ,
301+ } ,
302+ specDetails : {
303+ location : `[root].paths.${ path } .${ method } ` ,
304+ pathMethod : method ,
305+ pathName : path ,
306+ value : operation ,
307+ } ,
308+ type : "warning" ,
309+ } ;
310+ }
415311 }
416312 }
417313}
0 commit comments