-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Profile resolution unit tests and specification updates (#1219)
* Updates to tests including whitespace scrub test * Adding oXygen project * Integration work on specs and unit tests / XSLT and Schematron * Profile resolution testing infrastructure, plus some tests * Some test files with expected results * Updated and improved XSpec generation and tests - now driven directly from SpecML source * Adjusted gitignore; extended spec with more bindings; illustrator XSLT * Added XSLT producing Markdown summary of requirements w/ examples; updates * Added a small utility for converting JSON "prop" fields to "props" fields (emended 1.0.2 syntax) * Updated to Profile Resolution spec (with example files now tagged) and readme.md * Updated profile resolution (spec) readme with clarification regarding unit testing
- Loading branch information
1 parent
b7d376f
commit f5353c4
Showing
93 changed files
with
8,975 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
128
src/specifications/profile-resolution/example-set.xspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
111 changes: 111 additions & 0 deletions
111
src/specifications/profile-resolution/lib/build-examples-xspec.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:opr="http://csrc.nist.gov/ns/oscal/profile-resolution" | ||
xmlns:o="http://csrc.nist.gov/ns/oscal/1.0" | ||
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/specml" | ||
version="3.0"> | ||
|
||
<xsl:output indent="yes"/> | ||
|
||
<!-- This XSLT produces a set of file-oriented XSpecs binding to files named in the Specification document | ||
//req/@eg values --> | ||
|
||
<xsl:template match="/"> | ||
<xsl:text>
</xsl:text> | ||
<xsl:comment expand-text="true"> autogenerated { current-dateTime() } following model in example-set.xspec</xsl:comment> | ||
<xsl:processing-instruction name="xml-model">href="lib/xspec-test-dev.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"</xsl:processing-instruction> | ||
<xsl:processing-instruction name="xml-stylesheet">type="text/css" href="lib/xspec-oxygen.css"</xsl:processing-instruction> | ||
<xsl:processing-instruction name="specification" expand-text="true">{ replace(document-uri(/),'.*/','') }</xsl:processing-instruction> | ||
<x:description stylesheet="../../utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl" | ||
run-as="external"> | ||
|
||
<!-- x:description/@run-as='external' permits the context item to be determined dynamically per scenario | ||
cf https://github.com/xspec/xspec/wiki/External-Transformation#global-context-item | ||
helper function for cleaning up whitespace: | ||
see https://github.com/xspec/xspec/wiki/Integrating-Your-Own-Test-Helpers for | ||
for an example see https://github.com/xspec/xspec/blob/master/tutorial/helper/ws-only-text/href_stylesheet.xspec | ||
--> | ||
|
||
<x:helper stylesheet="lib/oscal-profile-test-helper.xsl"/> | ||
<!-- looking at all the profile documents in the same directory as this XSLT --> | ||
|
||
<xsl:apply-templates select="*" mode="make-file-scenario"/> | ||
|
||
</x:description> | ||
|
||
</xsl:template> | ||
|
||
<xsl:template match="SPECIFICATION" mode="make-file-scenario" expand-text="true"> | ||
<xsl:for-each-group select="//eg" group-by="@href"> | ||
<x:scenario label="{ current-grouping-key() }"> | ||
<x:context href="{ current-grouping-key() }"/> | ||
<xsl:apply-templates select="current-group()" | ||
mode="make-file-scenario"/> | ||
</x:scenario> | ||
</xsl:for-each-group> | ||
</xsl:template> | ||
|
||
<xsl:template match="head" mode="make-file-scenario"/> | ||
|
||
|
||
<xsl:template match="section" mode="test-header"> | ||
<!--<xsl:apply-templates select="parent::section" mode="#current"/>--> | ||
<!--<xsl:text> </xsl:text>--> | ||
<xsl:number level="multiple" format="1.1"/> | ||
<xsl:text> </xsl:text> | ||
<xsl:apply-templates select="head"/> | ||
<xsl:text> | </xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="req" mode="test-header"> | ||
<xsl:apply-templates select="ancestor::section[1]" mode="#current"/> | ||
<xsl:text> </xsl:text> | ||
<xsl:apply-templates/> | ||
</xsl:template> | ||
|
||
<!-- dropped in default (no mode) traversal --> | ||
<xsl:template match="eg"/> | ||
|
||
|
||
|
||
<xsl:template match="eg" mode="make-file-scenario" expand-text="true"> | ||
<xsl:apply-templates select="ancestor::req" mode="#current"> | ||
<xsl:with-param name="eg" select="."/> | ||
</xsl:apply-templates> | ||
</xsl:template> | ||
|
||
<xsl:template match="req" mode="make-file-scenario" expand-text="true"> | ||
<xsl:param required="true" name="eg" as="element(eg)?" /> | ||
<xsl:variable name="test-header"> | ||
<xsl:apply-templates select="." mode="test-header"/> | ||
</xsl:variable> | ||
|
||
<x:scenario label="{ $test-header => normalize-space() }"> | ||
<xsl:if test="starts-with($eg,'PENDING')"> | ||
<xsl:attribute name="pending">[spec]</xsl:attribute> | ||
</xsl:if> | ||
<xsl:call-template name="make-file-scenario"> | ||
<xsl:with-param name="req-id" select="@id"/> | ||
<xsl:with-param name="egfile" select="$eg/@href"/> | ||
</xsl:call-template> | ||
</x:scenario> | ||
|
||
</xsl:template> | ||
|
||
<xsl:template name="make-file-scenario" expand-text="true"> | ||
<xsl:param name="req-id" as="xs:string" required="true"/> | ||
<xsl:param name="egfile" as="xs:string?" required="true"/> | ||
<xsl:variable name="basename" as="xs:string" select="$egfile => substring-after('requirement-tests/') => replace('\.xml$','')"/> | ||
<xsl:processing-instruction name="requirement">{ $req-id} </xsl:processing-instruction> | ||
<!--<x:context href="requirement-tests/{ $egfile }"/>--> | ||
|
||
<x:expect label="Resolution of { $basename }.xml" select="opr:scrub(.)" href="requirement-tests/output-expected/{$basename}_RESOLVED.xml"/> | ||
</xsl:template> | ||
|
||
<xsl:template match="xref" expand-text="true"> | ||
<xsl:text>[Section {@rid}]</xsl:text> | ||
</xsl:template> | ||
</xsl:stylesheet> |
94 changes: 94 additions & 0 deletions
94
src/specifications/profile-resolution/lib/build-reqs-xspec.xsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:x="http://www.jenitennison.com/xslt/xspec" | ||
xmlns:xs="http://www.w3.org/2001/XMLSchema" | ||
xmlns:opr="http://csrc.nist.gov/ns/oscal/profile-resolution" | ||
xmlns:o="http://csrc.nist.gov/ns/oscal/1.0" | ||
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/specml" | ||
version="3.0"> | ||
|
||
<xsl:output indent="yes"/> | ||
|
||
<xsl:template match="/"> | ||
<xsl:text>
</xsl:text> | ||
<xsl:comment expand-text="true"> autogenerated { current-dateTime() } following model in example-set.xspec</xsl:comment> | ||
<xsl:processing-instruction name="xml-model">href="lib/xspec-test-dev.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"</xsl:processing-instruction> | ||
<xsl:processing-instruction name="xml-stylesheet">type="text/css" href="lib/xspec-oxygen.css"</xsl:processing-instruction> | ||
<xsl:processing-instruction name="specification" expand-text="true">{ replace(document-uri(/),'.*/','') }</xsl:processing-instruction> | ||
<x:description stylesheet="../../utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl" | ||
run-as="external"> | ||
|
||
<!-- x:description/@run-as='external' permits the context item to be determined dynamically per scenario | ||
cf https://github.com/xspec/xspec/wiki/External-Transformation#global-context-item | ||
helper function for cleaning up whitespace: | ||
see https://github.com/xspec/xspec/wiki/Integrating-Your-Own-Test-Helpers for | ||
for an example see https://github.com/xspec/xspec/blob/master/tutorial/helper/ws-only-text/href_stylesheet.xspec | ||
--> | ||
|
||
<x:helper | ||
stylesheet="lib/oscal-profile-test-helper.xsl"/> | ||
<!-- looking at all the profile documents in the same directory as this XSLT --> | ||
|
||
|
||
<xsl:apply-templates select="//req" mode="make-file-scenario"/> | ||
|
||
</x:description> | ||
|
||
</xsl:template> | ||
|
||
<xsl:template match="section" mode="test-header"> | ||
<!--<xsl:apply-templates select="parent::section" mode="#current"/>--> | ||
<!--<xsl:text> </xsl:text>--> | ||
<xsl:number level="multiple" format="1.1"/> | ||
<xsl:text> </xsl:text> | ||
<xsl:apply-templates select="head"/> | ||
<xsl:text> | </xsl:text> | ||
</xsl:template> | ||
|
||
|
||
<xsl:template match="req" mode="test-header"> | ||
<xsl:apply-templates select="ancestor::section[1]" mode="#current"/> | ||
<xsl:text> </xsl:text> | ||
<xsl:apply-templates/> | ||
</xsl:template> | ||
|
||
<xsl:template match="eg"/> | ||
|
||
<xsl:template match="req" mode="make-file-scenario" expand-text="true"> | ||
<xsl:variable name="me" select="."/> | ||
<xsl:variable name="test-header"> | ||
<xsl:apply-templates select="$me" mode="test-header"/> | ||
</xsl:variable> | ||
|
||
<x:scenario label="{ $test-header => normalize-space() }"> | ||
<xsl:if test="empty(descendant::eg/@href)"> | ||
<xsl:attribute name="pending">[dev]</xsl:attribute> | ||
</xsl:if> | ||
<xsl:apply-templates select="descendant::eg" mode="make-file-scenario"/> | ||
</x:scenario> | ||
</xsl:template> | ||
|
||
<xsl:template mode="make-file-scenario" match="eg" expand-text="true"> | ||
<xsl:variable name="basename" as="xs:string" select="@href => substring-after('requirement-tests/') => replace('\.xml$','')"/> | ||
<x:scenario label="Example TBD - {.}"> | ||
<xsl:if test="not(matches(@href,'\S')) or starts-with(.,'PENDING')"> | ||
<xsl:attribute name="pending">{ replace(.,'^PENDING:?\s*','') }</xsl:attribute> | ||
</xsl:if> | ||
|
||
<xsl:if test="matches(@href,'\S')"> | ||
<xsl:attribute name="label">Example { $basename }.xml - {.}</xsl:attribute> | ||
<xsl:processing-instruction name="requirement">{ ancestor::req[1]/@id } </xsl:processing-instruction> | ||
<x:context href="{ @href }"/> | ||
<x:expect label="Resolution of { $basename }.xml" select="opr:scrub(.)" | ||
href="requirement-tests/output-expected/{$basename}_RESOLVED.xml"/> | ||
</xsl:if> | ||
|
||
|
||
</x:scenario> | ||
</xsl:template> | ||
|
||
<xsl:template match="xref" expand-text="true"> | ||
<xsl:text>[Section {@rid}]</xsl:text> | ||
</xsl:template> | ||
</xsl:stylesheet> |
Oops, something went wrong.