Skip to content

Commit 354fe57

Browse files
committed
Add profile checks with Schematron for usnistgov/oscal-content#128. (#1513)
Profile checker Schematron queryBinding from xslt3->xslt2. We need to do this in the interim or we will need to significantly change or upgrade the CI/CD Schematron checker from current Schematron/schematron skeleton to SchXslt or equivalent. The former is mothballed and there was no addition of XSLT3 support. Potentially investigate further. Team discussion: https://gitter.im/usnistgov-OSCAL/xslt-etc?at=634dc527dcbf067fdc9c47cd Schematron issue: Schematron/schematron#20 SchXslt docs on XSLT 3.0 support: https://github.com/schxslt/schxslt/blob/62f1141613c9d4c02d8de86713bb3f3b29d6cf1c/README.md#additional-xslt-elements
1 parent 2c0bc49 commit 354fe57

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

build/ci-cd/validate-content.sh

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if [ -z ${OSCAL_SCRIPT_INIT+x} ]; then
66
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/include/init-oscal.sh"
77
fi
88
source "$OSCALDIR/build/metaschema/scripts/include/init-validate-content.sh"
9+
source "$OSCALDIR/build/metaschema/scripts/include/init-schematron.sh"
910

1011
# Option defaults
1112
ARTIFACT_DIR="${OSCALDIR}"
@@ -23,10 +24,16 @@ Usage: $0 [options]
2324
-o DIR, --oscal-dir DIR OSCAL schema are located in DIR.
2425
-h, --help Display help
2526
-v Provide verbose output
27+
--scratch-dir DIR Generate temporary artifacts in DIR
28+
If not provided a new directory will be
29+
created under \$TMPDIR if set or in /tmp.
30+
--keep-temp-scratch-dir If a scratch directory is automatically
31+
created, it will not be automatically removed.
2632
EOF
2733
}
2834

29-
if ! OPTS=$(getopt -o o:vhc:a: --long artifact-dir:,oscal-dir:,help,config-file: -n "$0" -- "$@"); then echo "Failed parsing options." >&2 ; usage ; exit 1 ; fi
35+
OPTS=$(getopt -o o:vhc:a: --long artifact-dir:,oscal-dir:,help,config-file:,scratch-dir:,keep-temp-scratch-dir -n "$0" -- "$@")
36+
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; usage ; exit 1 ; fi
3037

3138
# Process arguments
3239
eval set -- "$OPTS"
@@ -45,6 +52,13 @@ while [ $# -gt 0 ]; do
4552
ARTIFACT_DIR="$(realpath "$2")"
4653
shift # past path
4754
;;
55+
--scratch-dir)
56+
SCRATCH_DIR="$(realpath "$2")"
57+
shift # past path
58+
;;
59+
--keep-temp-scratch-dir)
60+
KEEP_TEMP_SCRATCH_DIR=true
61+
;;
4862
-v)
4963
VERBOSE=true
5064
;;
@@ -76,6 +90,28 @@ if [ "$VERBOSE" = "true" ]; then
7690
echo -e "${P_INFO}Using config file:${P_END} ${CONFIG_FILE}"
7791
fi
7892

93+
if [ -z "${SCRATCH_DIR+x}" ]; then
94+
SCRATCH_DIR="$(mktemp -d)"
95+
if [ "$KEEP_TEMP_SCRATCH_DIR" != "true" ]; then
96+
function CleanupScratchDir() {
97+
rc=$?
98+
if [ "$VERBOSE" = "true" ]; then
99+
echo -e ""
100+
echo -e "${P_INFO}Cleanup${P_END}"
101+
echo -e "${P_INFO}=======${P_END}"
102+
echo -e "${P_INFO}Deleting scratch directory:${P_END} ${SCRATCH_DIR}"
103+
fi
104+
rm -rf "${SCRATCH_DIR}"
105+
exit $rc
106+
}
107+
trap CleanupScratchDir EXIT
108+
fi
109+
fi
110+
111+
profile_schematron="oscal/src/utils/schematron/oscal-profile.sch"
112+
compiled_profile_schematron="${SCRATCH_DIR}/oscal-profile.xsl"
113+
build_schematron "${profile_schematron}" "${compiled_profile_schematron}"
114+
79115
exitcode=0
80116
shopt -s nullglob
81117
shopt -s globstar
@@ -113,6 +149,21 @@ while IFS="|" read path format model converttoformats || [ -n "$path" ]; do
113149
else
114150
echo -e "${P_OK}XML Schema validation passed for '${P_END}${file_relative}${P_OK}' using schema '${P_END}${schema_relative}${P_OK}'.${P_END}"
115151
fi
152+
153+
if [ "${model}" == "profile" ]; then
154+
echo -e "${P_INFO}Validating profile with Schematron for project's requirements and recommendations.${P_INFO}${P_END}"
155+
target_file=$(basename -- "${file_relative}")
156+
svrl_result="/tmp/${target_file}.svrl"
157+
result=$(validate_with_schematron "${SCRATCH_DIR}/oscal-profile.xsl" "${file_relative}" "$svrl_result" 2>&1)
158+
cmd_exitcode=$?
159+
if [ $cmd_exitcode -ne 0 ]; then
160+
echo -e "${P_ERROR}Profile validation execution for '${P_END}${file_relative}${P_ERROR}' with Schematron '${P_END}${profile_schematron}${P_ERROR}' did not complete.${P_END}"
161+
echo -e "${P_ERROR}${result}${P_END}"
162+
exitcode=1
163+
else
164+
echo -e "${P_OK}Profile validation execution for '${P_END}${file_relative}${P_OK}' with Schematron '${P_END}${profile_schematron}${P_OK}' completed successfully.${P_END}"
165+
fi
166+
fi
116167
;;
117168
json)
118169
schema="$WORKING_DIR/json/schema/oscal_${model}_schema.json"

src/utils/schematron/oscal-profile.sch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt3"
2+
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
33
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
44
xmlns:sqf="http://www.schematron-quickfix.com/validator/process"
55
xmlns:oscal="http://csrc.nist.gov/ns/oscal/1.0">

0 commit comments

Comments
 (0)