forked from ChelseaKR/oscal-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversions.py
More file actions
50 lines (44 loc) · 1.81 KB
/
Copy pathversions.py
File metadata and controls
50 lines (44 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Check 5: which OSCAL release the document was authored against.
This produces no verdict on the document. It states, in the output, the one
fact a reader needs to interpret every other finding: which release's schema
and constraints the findings above were produced from, and whether that is the
release the document itself names.
A document authored against an earlier OSCAL release is entirely legitimate.
It may nonetheless collect findings here that say more about the gap between
two releases than about the document, and a report that did not say so would be
misleading.
"""
from __future__ import annotations
from .. import rules
from ..findings import Finding, Severity
from ..session import Session
def check(session: Session) -> list[Finding]:
walked = session.corpus.primary.walked
declared = [
scalar
for scalar in walked.scalars
if scalar.name == "oscal-version" and scalar.pointer.count("/") == 3
]
vendored = rules.OSCAL_RELEASE
findings: list[Finding] = []
for scalar in declared:
value = str(scalar.value)
if value == vendored:
continue
findings.append(
Finding(
code="OSCAL_VERSION_DIFFERS",
severity=Severity.WARNING,
location=scalar.pointer,
prop="oscal-version",
value=value,
message=(
f"The document declares OSCAL {value}. Every finding in this report "
f"was produced against the vendored OSCAL {vendored} schema and "
"constraint layer, so a difference between the two releases can show "
"up here as a finding about the document."
),
rule=rules.OSCAL_VERSION_FIELD,
)
)
return findings