Skip to content

Commit 8287065

Browse files
k1LoWdaveshanley
authored andcommitted
Add tests
1 parent 997ed2e commit 8287065

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

parameters/validate_security_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,53 @@ components:
291291
assert.Equal(t, 1, len(errors))
292292
}
293293

294+
func TestParamValidator_ValidateSecurity_MissingSecuritySchemes(t *testing.T) {
295+
296+
spec := `openapi: 3.1.0
297+
paths:
298+
/products:
299+
post:
300+
security:
301+
- ApiKeyAuth:
302+
- write:products
303+
components: {}
304+
`
305+
306+
doc, _ := libopenapi.NewDocument([]byte(spec))
307+
308+
m, _ := doc.BuildV3Model()
309+
310+
v := NewParameterValidator(&m.Model)
311+
312+
request, _ := http.NewRequest(http.MethodPost, "https://things.com/products", nil)
313+
valid, errors := v.ValidateSecurity(request)
314+
assert.False(t, valid)
315+
assert.Equal(t, 1, len(errors))
316+
}
317+
318+
func TestParamValidator_ValidateSecurity_NoComponents(t *testing.T) {
319+
320+
spec := `openapi: 3.1.0
321+
paths:
322+
/products:
323+
post:
324+
security:
325+
- ApiKeyAuth:
326+
- write:products
327+
`
328+
329+
doc, _ := libopenapi.NewDocument([]byte(spec))
330+
331+
m, _ := doc.BuildV3Model()
332+
333+
v := NewParameterValidator(&m.Model)
334+
335+
request, _ := http.NewRequest(http.MethodPost, "https://things.com/products", nil)
336+
valid, errors := v.ValidateSecurity(request)
337+
assert.False(t, valid)
338+
assert.Equal(t, 1, len(errors))
339+
}
340+
294341
func TestParamValidator_ValidateSecurity_PresetPath(t *testing.T) {
295342

296343
spec := `openapi: 3.1.0

0 commit comments

Comments
 (0)