Skip to content

Commit 2553906

Browse files
fix: correct given expression + removal of incorrectly entered files for Dok06
Signed-off-by: Fredrik Nordlander <fredrik.nordlander@digg.se>
1 parent 52f7238 commit 2553906

File tree

8 files changed

+28
-139
lines changed

8 files changed

+28
-139
lines changed

GUIDELINES.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Detta dokument specificerar reglerna som verktyget tillämpar.
7575
9. [Område: Säkerhet](#område-säkerhet)
7676
- [ID: SAK.09](#id-sak09)
7777
- [ID: SAK.10](#id-sak10)
78+
- [ID: SAK.15](#id-sak15)
7879
- [ID: SAK.18](#id-sak18)
7980
10. [Område: Förutsättningar](#område-förutsättningar)
8081
- [ID: FOR.02](#id-for02)
@@ -943,7 +944,7 @@ I exemplet ovan, så exemplifieras regeln med en kontroll av de query parametrar
943944

944945
## Område: Säkerhet
945946

946-
**Täckningsgrad: 9%**
947+
**Täckningsgrad: 11%**
947948

948949
### ID: SAK.09
949950

@@ -991,6 +992,29 @@ I exemplet ovan så kommer regeln att ge ett positivt utfall eftersom det finns
991992

992993
---
993994

995+
### ID: SAK.15
996+
997+
**Krav:** API-nycklar SKALL INTE inkluderas i URL eller querysträngen.
998+
999+
**Typ:** SKALL
1000+
1001+
**JSON Path Plus-uttryck:**
1002+
1003+
```
1004+
$.components.securitySchemes[?(@ && @.type=='apiKey')]
1005+
```
1006+
1007+
**Förklaring:**
1008+
Regeln kontrollerar, under förutsättning att ett security scheme är definierat, att om typen är 'apiKey', så får värdet för parametern 'in' inte vara 'query.
1009+
1010+
**Exempel:**
1011+
1012+
![alt text](images/sak15.png)
1013+
1014+
I exemplet ovan ger regeln ett negativt utfall, eftersom det definierade säkerhetsschemat 'ApiKeyQuery' har typen 'apiKey' och parametern 'in' är satt till 'query', vilket strider mot regeln.
1015+
1016+
---
1017+
9941018
### ID: SAK.18
9951019

9961020
**Krav:** OAuth version 2.0 eller senare BÖR användas för auktorisation.

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ path = [
5050
"images/rest-api-profil.png",
5151
"images/sak09.png",
5252
"images/sak10.png",
53+
"images/sak15.png",
5354
"images/sak18.png",
5455
"images/ufn1-2.png",
5556
"images/ufn1.png",

images/sak15.png

13.9 KB
Loading

rulesets/DokRules.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { truthy, falsy, pattern } from '@stoplight/spectral-functions';
88
import { DiagnosticSeverity } from '@stoplight/types';
99
import { Dok03Base } from './rulesetUtil.ts';
1010
import { Dok15Base } from './rulesetUtil.ts';
11-
import { commonEnglishWords, commonSwedishWords } from './constants/CommonWords.ts';
1211
const moduleName: string = 'DokRules.ts';
1312

1413
export class Dok15Get extends Dok15Base {
@@ -134,52 +133,6 @@ export class Dok20 extends BaseRuleset {
134133
}
135134
severity = DiagnosticSeverity.Error;
136135
}
137-
export class Dok06 extends BaseRuleset {
138-
static customProperties: CustomProperties = {
139-
område: 'Dokumentation',
140-
id: 'DOK.06',
141-
};
142-
given = '$.info.description';
143-
message = 'Dokumentationen BÖR finnas på både svenska och engelska.';
144-
then = [
145-
{
146-
function: (targetVal: string, _opts: string, paths: string[]) => {
147-
const lowerCaseTargetVal = targetVal.toLowerCase();
148-
const containsEnglish = commonEnglishWords.some((word) => new RegExp(`\\b${word}\\b`).test(lowerCaseTargetVal));
149-
const containsSwedish = commonSwedishWords.some((word) => new RegExp(`\\b${word}\\b`).test(lowerCaseTargetVal));
150-
151-
if (!containsEnglish || !containsSwedish) {
152-
return [
153-
{
154-
message: this.message,
155-
severity: this.severity,
156-
},
157-
];
158-
} else {
159-
return [];
160-
}
161-
},
162-
},
163-
{
164-
function: (targetVal: string, _opts: string, paths: string[]) => {
165-
this.trackRuleExecutionHandler(
166-
JSON.stringify(targetVal, null, 2),
167-
_opts,
168-
paths,
169-
this.severity,
170-
this.constructor.name,
171-
moduleName,
172-
Dok06.customProperties,
173-
);
174-
},
175-
},
176-
];
177-
constructor() {
178-
super();
179-
super.initializeFormats(['OAS3']);
180-
}
181-
severity = DiagnosticSeverity.Warning;
182-
}
183136
export class Dok07 extends BaseRuleset {
184137
static customProperties: CustomProperties = {
185138
område: 'Dokumentation',

rulesets/SakRules.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class Sak15 extends BaseRuleset {
102102
description = '-';
103103
message = 'API-nycklar SKALL INTE inkluderas i URL eller querysträngen';
104104
given =
105-
"$..securitySchemes[?(@.type=='apiKey')]";
105+
"$.components.securitySchemes[?(@ && @.type=='apiKey')]";
106106
then = [
107107
{
108108
function: (targetVal: any, _opts: any, paths: string[]) => {
@@ -174,4 +174,4 @@ export class Sak18 extends BaseRuleset {
174174
}
175175
severity = DiagnosticSeverity.Warning;
176176
}
177-
export default { Sak09, Sak10, Sak18 };
177+
export default { Sak09, Sak10, Sak15, Sak18 };

rulesets/constants/CommonWords.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

tests/dok.test.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -80,55 +80,6 @@ testRule('Dok20', [
8080
],
8181
},
8282
]);
83-
testRule('Dok06', [
84-
{
85-
name: 'giltigt testfall',
86-
document: {
87-
openapi: '3.1.0',
88-
info: { version: '1.0', description: 'Här finns det dokumentation på svenska and english.' },
89-
},
90-
errors: [],
91-
},
92-
{
93-
name: 'ogiltigt testfall - endast svenska',
94-
document: {
95-
openapi: '3.1.0',
96-
info: { version: '1.0', description: 'Detta är på svenska' },
97-
},
98-
errors: [
99-
{
100-
message: 'Dokumentationen BÖR finnas på både svenska och engelska.',
101-
severity: DiagnosticSeverity.Warning,
102-
},
103-
],
104-
},
105-
{
106-
name: 'ogiltigt testfall - endast engelska',
107-
document: {
108-
openapi: '3.1.0',
109-
info: { version: '1.0', description: 'This is in english' },
110-
},
111-
errors: [
112-
{
113-
message: 'Dokumentationen BÖR finnas på både svenska och engelska.',
114-
severity: DiagnosticSeverity.Warning,
115-
},
116-
],
117-
},
118-
{
119-
name: 'ogiltigt testfall - båda språken med sammansatta ord',
120-
document: {
121-
openapi: '3.1.0',
122-
info: { version: '1.0', description: 'Härfinnsdetdokumentationpåsvenskaandenglish.' },
123-
},
124-
errors: [
125-
{
126-
message: 'Dokumentationen BÖR finnas på både svenska och engelska.',
127-
severity: DiagnosticSeverity.Warning,
128-
},
129-
],
130-
},
131-
]);
13283
testRule('Dok07', [
13384
{
13485
name: 'giltigt testfall',

tests/util/rulesetTest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const ruleTypes = [
5656
FnsRules.Fns07,
5757
FnsRules.Fns06,
5858
DokRules.Dok20,
59-
DokRules.Dok06,
6059
DokRules.Dok07,
6160
FelRules.Fel01,
6261
FelRules.Fel02,

0 commit comments

Comments
 (0)