Skip to content

Commit 856fc06

Browse files
committed
test: add test suite for DOK.21
Signed-off-by: Mats Johansson <extern.mats.johansson@digg.se>
1 parent 0232657 commit 856fc06

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

tests/unit/dok.test.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,105 @@ testRule('Dok19', [
510510
],
511511
},
512512
]);
513-
513+
testRule('Dok21', [
514+
{
515+
name: 'ogiltigt testfall - security saknas helt',
516+
document: {
517+
openapi: '3.1.0',
518+
info: { version: '1.0' },
519+
servers: [{ url: 'https://example.com/my-api/v1' }],
520+
paths: {
521+
'/pets': {
522+
get: {
523+
description: 'Retrieve all pets',
524+
},
525+
},
526+
},
527+
},
528+
errors: [
529+
{
530+
message: 'Krav på autentisering SKALL anges i specifikationen.',
531+
severity: DiagnosticSeverity.Error,
532+
},
533+
],
534+
},
535+
{
536+
name: 'giltigt testfall - security finns på rootnivå och består utav en tom array',
537+
document: {
538+
openapi: '3.1.0',
539+
info: { version: '1.0' },
540+
servers: [{ url: 'https://example.com/my-api/v1' }],
541+
security: [],
542+
paths: {
543+
'/pets': {
544+
get: {
545+
description: 'Retrieve all pets',
546+
},
547+
},
548+
},
549+
},
550+
errors: [],
551+
},
552+
{
553+
name: 'giltigt testfall - security finns på rootnivå och innehåller ett objekt',
554+
document: {
555+
openapi: '3.1.0',
556+
info: { version: '1.0' },
557+
servers: [{ url: 'https://example.com/my-api/v1' }],
558+
security: [
559+
{
560+
OAuth2: [],
561+
},
562+
],
563+
paths: {
564+
'/pets': {
565+
get: {
566+
description: 'Retrieve all pets',
567+
},
568+
},
569+
},
570+
},
571+
errors: [],
572+
},
573+
{
574+
name: 'giltigt testfall - security finns på operationsnivå och består utav en tom array',
575+
document: {
576+
openapi: '3.1.0',
577+
info: { version: '1.0' },
578+
servers: [{ url: 'https://example.com/my-api/v1' }],
579+
paths: {
580+
'/pets': {
581+
get: {
582+
description: 'Retrieve all pets',
583+
security: [],
584+
},
585+
},
586+
},
587+
},
588+
errors: [],
589+
},
590+
{
591+
name: 'giltigt testfall - security finns på operationsnivå och innehåller ett objekt',
592+
document: {
593+
openapi: '3.1.0',
594+
info: { version: '1.0' },
595+
servers: [{ url: 'https://example.com/my-api/v1' }],
596+
paths: {
597+
'/pets': {
598+
get: {
599+
description: 'Retrieve all pets',
600+
security: [
601+
{
602+
OAuth2: [],
603+
},
604+
],
605+
},
606+
},
607+
},
608+
},
609+
errors: [],
610+
},
611+
]);
514612
testRule('Dok01', [
515613
{
516614
name: 'giltigt testfall',

tests/util/rulesetTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const ruleTypes = [
7272
DokRules.Dok15ReqBody,
7373
DotRules.Dot04,
7474
DokRules.Dok19,
75+
DokRules.Dok21,
7576
DokRules.Dok01,
7677
DokRules.Dok11,
7778
DokRules.Dok17,

0 commit comments

Comments
 (0)