Skip to content

Commit

Permalink
Add profile checks with Schematron for usnistgov/oscal-content#128.
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-nist committed Oct 20, 2022
1 parent e4f710c commit 7cc3a83
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion build/ci-cd/validate-content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if [ -z ${OSCAL_SCRIPT_INIT+x} ]; then
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)/include/init-oscal.sh"
fi
source "$OSCALDIR/build/metaschema/scripts/include/init-validate-content.sh"
source "$OSCALDIR/build/metaschema/scripts/include/init-schematron.sh"

# Option defaults
ARTIFACT_DIR="${OSCALDIR}"
Expand All @@ -26,7 +27,8 @@ Usage: $0 [options]
EOF
}

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
OPTS=`getopt -o o:vhc:a: --long artifact-dir:,oscal-dir:,help,config-file: -n "$0" -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; usage ; exit 1 ; fi

# Process arguments
eval set -- "$OPTS"
Expand Down Expand Up @@ -76,6 +78,10 @@ if [ "$VERBOSE" = "true" ]; then
echo -e "${P_INFO}Using config file:${P_END} ${CONFIG_FILE}"
fi

profile_schematron="oscal/src/utils/schematron/oscal-profile.sch"
compiled_profile_schematron="/tmp/oscal-profile.xsl"
build_schematron "${profile_schematron}" "${compiled_profile_schematron}"

exitcode=0
shopt -s nullglob
shopt -s globstar
Expand Down Expand Up @@ -113,6 +119,20 @@ while IFS="|" read path format model converttoformats || [ -n "$path" ]; do
else
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}"
fi

if [ "${model}" == "profile" ]; then
echo -e "${P_INFO}Validating profile with Schematron for project's requirements and recommendations.${P_INFO}${P_END}"
target_file=$(basename -- "${file_relative}")
svrl_result="/tmp/${target_file}.svrl"
result=$(validate_with_schematron "/tmp/oscal-profile.xsl" "${file_relative}" "$svrl_result" 2>&1)
if [ $cmd_exitcode -ne 0 ]; then
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}"
echo -e "${P_ERROR}${result}${P_END}"
exitcode=1
else
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}"
fi
fi
;;
json)
schema="$WORKING_DIR/json/schema/oscal_${model}_schema.json"
Expand Down

0 comments on commit 7cc3a83

Please sign in to comment.