Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature profile resolution unittesting a #1770

Merged
merged 10 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/xspec-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: OSCAL XSpec Test Suite
on:
push:
branches:
- main
- develop
- "feature-*"
- "release-*"
paths:
- /src
- "**.xsl"
- "**.xpl"
- "**.xspec"
pull_request:
branches:
- main
- develop
- "feature-*"
- "release-*"
paths:
- /src
- "**.xsl"
- "**.xpl"
- "**.xspec"
workflow_call: {}
jobs:
xspec-tests:
name: Run XSpec tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Pull the correct image
shell: bash
# Produces a tagged image oscal-common-env:selected
run: ./build/pull-oscal-env-dockerfile.sh "${{ github.head_ref || github.ref_name }}"
- name: Run XSpec tests
shell: bash
run: |
set -o pipefail # propagate return code
docker run \
-v $(pwd):/oscal \
-e TEST_DIR=/oscal/xspec \
oscal-common-env:selected \
/oscal/src/utils/util/resolver-pipeline/testing/test.sh \
| tee summary.csv || {
if [ "$?" = 83 ]; then
# For now we only fail when tests fail to compile
echo "Some test suites failed to compile, failing..."
exit 1
fi
}
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: xspec-output
path: |
xspec/*.html
summary.csv
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,5 @@ node_modules/
/docs/scratch-dir
/.skipbuild
/.runbuild

/summary.csv
29 changes: 29 additions & 0 deletions build/build-oscal-env-dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Build and tag the oscal-common-env dockerfile
#
# By default the tag is the sanitized branch name, but can be overidden
# by an argument.

set -Eeuo pipefail

IMAGE="csd773/oscal-common-env"
BRANCH=$(git branch --show-current)
BRANCH_SANITIZED=${BRANCH/\//_}

TAG="${1:-$BRANCH_SANITIZED}"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"

docker build \
--label "branch=${BRANCH}" \
--label "commit_sha=$(git rev-parse HEAD)" \
--label "dirty=$(git diff --quiet && echo 'false' || echo 'true')" \
--label "[email protected]" \
--label "author=$(git config user.email)" \
--platform linux/amd64 \
-f "$SCRIPT_DIR/Dockerfile" \
-t "$IMAGE:$TAG" \
"$SCRIPT_DIR"

echo "Built and tagged $IMAGE:$TAG, to push run:"
echo " docker push $IMAGE:$TAG"
2 changes: 1 addition & 1 deletion build/metaschema
Submodule metaschema updated 56 files
+3 −0 .github/CODEOWNERS
+39 −0 .github/dependabot.yml
+2 −2 .github/workflows/issue-triage.yml
+62 −0 .github/workflows/link-check.yml
+0 −2 .github/workflows/status-ci-cd.yml
+95 −33 .github/workflows/workflow-generate-website.yml
+31 −16 .github/workflows/workflow-validate-repo-markdown.yml
+50 −0 .github/workflows/workflow-validate-website-content.yml
+2 −1 build/config/.lycheeignore
+28 −7 build/config/.markdown-link-check/config.json
+127 −0 build/go.mod
+1,085 −0 build/go.sum
+1,426 −405 build/package-lock.json
+11 −3 build/package.json
+65 −0 build/pom.xml
+12 −0 build/tools.go
+32 −20 schema/json/metaschema-datatypes.json
+10 −15 schema/xml/metaschema-datatypes.xsd
+2 −9 schema/xml/metaschema.xsd
+1 −1 support/xspec
+38 −0 test-suite/metaschema-xspec/json-schema-gen/json-schema-gen.xspec
+70 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-closed.json
+38 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-closed_metaschema.xml
+58 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-narrow.json
+39 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-narrow_metaschema.xml
+70 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-open.json
+38 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-open_metaschema.xml
+58 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-sortof.json
+38 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_constrained-sortof_metaschema.xml
+58 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_unconstrained.json
+30 −0 test-suite/metaschema-xspec/json-schema-gen/json-value_unconstrained_metaschema.xml
+12 −7 test-suite/schema-generation/allowed-values/allowed-values-basic_test_valid_PASS.xml
+4 −2 test-suite/schema-generation/unit-tests.xml
+0 −2 toolchains/xslt-M4/converter-gen/supermodel-to-json.xsl
+1 −1 toolchains/xslt-M4/document/xml/element-map-html.xsl
+1 −1 toolchains/xslt-M4/make-metaschema-css.xpl
+2 −12 toolchains/xslt-M4/make-metaschema-sandbox.xpl
+1 −1 toolchains/xslt-M4/make-metaschema-xml-to-supermodel-xslt.xpl
+44 −192 toolchains/xslt-M4/schema-gen/make-json-schema-metamap.xsl
+28 −0 toolchains/xslt-M4/testing/issue_235_regression-metaschema.xml
+144 −0 toolchains/xslt-M4/testing/issue_235_regression.xspec
+2 −2 toolchains/xslt-M4/testing/test-xml-conversions.xpl
+2 −2 toolchains/xslt-M4/validate/metaschema-composition-check.sch
+11 −0 toolchains/xslt-M4/validate/xproc-check.sch
+167 −0 versioning-and-branching.md
+1 −1 website/config.yaml
+26 −6 website/content/_index.md
+2 −0 website/content/contribute/contact.md
+13 −443 website/content/specification/syntax/_index.md
+705 −0 website/content/specification/syntax/datatypes.md
+954 −0 website/content/tutorials/1-getting-started/_index.md
+11 −0 website/content/tutorials/_index.md
+1 −1 website/content/use/_index.md
+874 −0 website/static/img/computer.svg
+927 −0 website/static/img/computer_numbered.svg
+1 −1 website/themes/uswds
39 changes: 39 additions & 0 deletions build/pull-oscal-env-dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Pull the oscal-common-env from the registry using a defined set of tags, and
# retag the first working image with a new tag.
# This is intended to be used in CI/CD environments where rebuilding the
# oscal-common-env would be expensive, but an escape hatch to allow for a
# "special" image for a run is preferred.

set -Eeuo pipefail

# Allow the user to override the "branch" name (note that this still sanitizes the input)
if [ "${1-}" ]; then
BRANCH=${1}
else
BRANCH=$(git branch --show-current)
fi

# Docker tags cannot have "/" in them
SANITIZED_BRANCH=${BRANCH/\//_}

TAGS=("${SANITIZED_BRANCH}" "develop")

SOURCE_IMAGE="csd773/oscal-common-env"

# the output image and tag to write to
OUTPUT_IMAGE="oscal-common-env"
OUTPUT_TAG="selected"
OUTPUT_REF="${OUTPUT_IMAGE}:${OUTPUT_TAG}"

for TAG in "${TAGS[@]}"; do
REF="${SOURCE_IMAGE}:${TAG}"
docker pull "${REF}" && {
docker tag "${REF}" "${OUTPUT_REF}"
echo "Successsfully pulled ${REF} and retagged it as ${OUTPUT_REF}"
exit 0
} || echo "Pulling tag ${REF} failed..."
done

echo "Failed to pull any images in"
exit 1
39 changes: 39 additions & 0 deletions src/release/content-upgrade/json-prop-to-props.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0"
xpath-default-namespace="http://www.w3.org/2005/xpath-functions"
xmlns="http://www.w3.org/2005/xpath-functions">

<!--
Command line invocation:
$ java -jar $SAXON_HOME/saxon-he-10.2.jar -xsl:json-prop-to-props.xsl -it json-input=YOUR.json
where YOUR.json is your JSON file and the jar file is Saxon 10 or later.
The process reads the file at this URL, parses it as JSON, maps it through a filter, and reports it back.
-->

<xsl:output method="text"/>

<xsl:mode on-no-match="shallow-copy"/>

<!-- The input JSON file -->
<xsl:param name="json-input" select="'url to json file'"/>

<!-- The initial template that process the JSON -->
<xsl:template name="xsl:initial-template">
<xsl:variable name="mapped-result">
<xsl:apply-templates select="json-to-xml(unparsed-text($json-input))"/>
</xsl:variable>
<!--<xsl:copy-of select="$mapped-result"/>-->
<xsl:value-of select="xml-to-json($mapped-result)"/>
</xsl:template>

<xsl:template match="array[@key='prop']">
<array key="props">
<xsl:apply-templates/>
</array>
</xsl:template>

</xsl:stylesheet>
2 changes: 2 additions & 0 deletions src/specifications/profile-resolution/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!oscal-specs_share.xpr
requirement-tests/output-actual/
128 changes: 128 additions & 0 deletions src/specifications/profile-resolution/example-set.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- autogenerated 2021-12-14T16:02:57.305-05:00 following model in example-set.xspec-->
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
xmlns:opr="http://csrc.nist.gov/ns/oscal/profile-resolution"
xmlns:o="http://csrc.nist.gov/ns/oscal/1.0"
stylesheet="../../utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl"
run-as="external"
xmlns:ov="http://csrc.nist.gov/ns/oscal/test/variable">
<x:helper stylesheet="lib/oscal-profile-test-helper.xsl"/>
<!-- old tests are out of whack need update to current functionality /spec -->
<!-- but the XSpec provides a functional model -->
<x:scenario label="Base test">
<!-- Alternative model for test scrubbing both the result and the expected
result for comparison -->
<x:context href="profile-resolution-examples/base-test_profile.xml"/>
<x:variable name="ov:expected-output"
href="profile-resolution-examples/output-expected/base-test_profile_RESOLVED.xml"/>
<x:expect label="Base test - fully resolved"
test="opr:scrub($x:result)" select="opr:scrub($ov:expected-output)"/>
</x:scenario>

<x:scenario label="Testing base-test_profile.xml">

<x:context href="profile-resolution-examples/base-test_profile.xml"/>
<x:expect label="Resolution of base-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/base-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing base2-test_profile.xml">
<x:context href="profile-resolution-examples/base2-test_profile.xml"/>
<x:expect label="Resolution of base2-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/base2-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing broken_profile.xml" pending="galtm">
<x:context href="profile-resolution-examples/broken_profile.xml"/>
<x:expect label="Resolution of broken_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/broken_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing circular_profile.xml">
<x:context href="profile-resolution-examples/circular_profile.xml"/>
<x:expect label="Resolution of circular_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/circular_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing exclude-call-test_profile.xml">
<x:context href="profile-resolution-examples/exclude-call-test_profile.xml"/>
<x:expect label="Resolution of exclude-call-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/exclude-call-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing full-test_profile.xml">
<x:context href="profile-resolution-examples/full-test_profile.xml"/>
<x:expect label="Resolution of full-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/full-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing home_profile.xml">
<x:context href="profile-resolution-examples/home_profile.xml"/>
<x:expect label="Resolution of home_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/home_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing import-twice_profile.xml">
<x:context href="profile-resolution-examples/import-twice_profile.xml"/>
<x:expect label="Resolution of import-twice_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/import-twice_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing include-all-no-children-test_profile.xml">
<x:context href="profile-resolution-examples/include-all-no-children-test_profile.xml"/>
<x:expect label="Resolution of include-all-no-children-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/include-all-no-children-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing include-all-test_profile.xml">
<x:context href="profile-resolution-examples/include-all-test_profile.xml"/>
<x:expect label="Resolution of include-all-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/include-all-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing include-call-with-children-test_profile.xml">
<x:context href="profile-resolution-examples/include-call-with-children-test_profile.xml"/>
<x:expect label="Resolution of include-call-with-children-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/include-call-with-children-test_profile_RESOLVED.xml"/>
<x:expect label="Includes grandparent in result" test="$x:result//o:control/@id = 'c3'"/>
<x:expect label="Includes grandchild in result" test="$x:result//o:control/@id = 'c3.a-1'"/>
<x:expect label="Is missing a control not included" test="not( $x:result//o:control/@id = 'c2' )"/>
</x:scenario>
<x:scenario label="Testing include-loose-param-test_profile.xml">
<x:context href="profile-resolution-examples/include-loose-param-test_profile.xml"/>
<x:expect label="Resolution of include-loose-param-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/include-loose-param-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing include-match-test_profile.xml">
<x:context href="profile-resolution-examples/include-match-test_profile.xml"/>
<x:expect label="Resolution of include-match-test_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/include-match-test_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing merge-implicit-keep_profile.xml">
<x:context href="profile-resolution-examples/merge-implicit-keep_profile.xml"/>
<x:expect label="Resolution of merge-implicit-keep_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/merge-implicit-keep_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing merge-keep-resources_profile.xml">
<x:context href="profile-resolution-examples/merge-keep-resources_profile.xml"/>
<x:expect label="Resolution of merge-keep-resources_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/merge-keep-resources_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing merge-keep_profile.xml">
<x:context href="profile-resolution-examples/merge-keep_profile.xml"/>
<x:expect label="Resolution of merge-keep_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/merge-keep_profile_RESOLVED.xml"/>
</x:scenario>
<x:scenario label="Testing modify-adds_profile.xml">
<x:context href="profile-resolution-examples/modify-adds_profile.xml"/>
<x:expect label="Resolution of modify-adds_profile.xml"
select="opr:scrub(.)"
href="profile-resolution-examples/output-expected/modify-adds_profile_RESOLVED.xml"/>
</x:scenario>
</x:description>
Loading