Error while running python test on Windows
While trying to run the python tests in src/examples/python/test_validate_ssp.py for release [FedRAMP 1.1.0 Release for OSCAL 1.0.0] on Wndows I get the following error (On Linux and Mac the test passes and no error is reported)-
______________________________________________________ ERROR at setup of test_failed_asserts _______________________________________________________
saxon_processor = <saxonc.PySaxonProcessor object at 0x000001BAB2194AD0>, xslt_processor = <saxonc.PyXslt30Processor object at 0x000001BAB2194890>
@pytest.fixture
def svrl_node(
saxon_processor: saxonc.PySaxonProcessor, xslt_processor: saxonc.PyXsltProcessor
) -> saxonc.PyXdmNode:
# Validate the SSP, returning an SVRL document as a string.
svrl_string = xslt_processor.transform_to_string(
source_file=EXAMPLE_SSP_PATH,
stylesheet_file=SSP_XSL_FILE,
)
> assert "<svrl:schematron-output" in svrl_string
E TypeError: argument of type 'NoneType' is not iterable
test_validate_ssp.py:77: TypeError
-------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------
Error evaluating (($value-set/allowed-values)/@allow-other = "no" and $value = $values) in xsl:param/@select on line 491 column 201 of ssp.xsl:
FODC0002: Exception thrown by URIResolver. Found while atomizing the first operand of '='
at function lv:correct on line 80 of ssp.xsl:
invoked by function call at file:///C:/Users/***/ssp.xsl#547
In template rule with match="document-node()/element(Q{http://csrc.nist.gov/ns/oscal/1.0}system-security-plan)" on line 540 of ssp.xsl
invoked by built-in template rule (text-only)
In template rule with match="/" on line 254 of ssp.xsl
invoked by xsl:apply-templates at file:///C:/Users/***/ssp.xsl#277
In template rule with match="/" on line 254 of ssp.xsl
Similar error is reported for latest release [fedramp-1.2.1-oscal-1.0.0] on Windows -
______________________________________________________ ERROR at setup of test_failed_asserts _______________________________________________________
saxon_processor = <saxonc.PySaxonProcessor object at 0x00000195B0424390>, xslt_processor = <saxonc.PyXslt30Processor object at 0x00000195B0424270>
@pytest.fixture
def svrl_node(
saxon_processor: saxonc.PySaxonProcessor, xslt_processor: saxonc.PyXsltProcessor
) -> saxonc.PyXdmNode:
# Validate the SSP, returning an SVRL document as a string.
svrl_string = xslt_processor.transform_to_string(
source_file=EXAMPLE_SSP_PATH,
stylesheet_file=SSP_XSL_FILE,
)
> assert "<svrl:schematron-output" in svrl_string
E TypeError: argument of type 'NoneType' is not iterable
test_validate_ssp.py:77: TypeError
-------------------------------------------------------------- Captured stderr setup ---------------------------------------------------------------
Error evaluating (fn:doc(...)) in xsl:param/@select on line 587 column 201 of ssp.xsl:
FODC0002: Exception thrown by URIResolver: Invalid relative URI
{C:\Users\***\git...}: Illegal character in opaque part at index 2:
C:\Users\***\fedramp-source\dist\content\resources\xml/fedramp_values.xml
at procedure registry on line 587 of ssp.xsl:
invoked by global xsl:param
In template rule with match="document-node()/element(Q{http://csrc.nist.gov/ns/oscal/1.0}system-security-plan)" on line 636 of ssp.xsl
invoked by built-in template rule (text-only)
In template rule with match="/" on line 256 of ssp.xsl
invoked by xsl:apply-templates at file:///C:/Users/***/ssp.xsl#290
In template rule with match="/" on line 256 of ssp.xsl
It seems something to do with how file paths are specified in ssp.xsl or some invalid character on Windows.
@danielnaab : does this look like something previously encountered?
@GaryGapinski No, I haven't tested on Windows.
@vikas-agarwal76 I presume you're running pytest directly, with a manually configured saxonc, rather than running in the Docker container via make test-example-python in the project root? Could you clarify how you built saxonc / python-saxon and are running the tests?
Saxon doesn't seem to like the backslash in paths, but it's not clear why Saxon is resolving relative paths with backslashes.
@vikas-agarwal76 Also, does your compiled ssp.xsl include backslashes in relative paths? Could you share how it was built and perhaps share a copy of the compiled file? Thanks!
@danielnaab I am using saxonpy https://pypi.org/project/saxonpy/ which is a pypi package built using SxaonC. On Linux and Mac it works, but fails on Windows.
I am using the pre-built ssp.xsl file that are part of the release versions of fedramp as mentioned above in the issue. I am not building ssp.xsl myself.
@vikas-agarwal76 Thank you - we'll look into getting the test working shortly.
@danielnaab Thanks, any updates on this issue? Were you able to replicate the problem?
@vikas-agarwal76 Sorry for the delay. We're looking into improving Windows support on this branch: https://github.com/18F/fedramp-automation/pull/414
A couple notes:
- The issue you see is due to the format of path arguments passed into the compiled XSLT. Saxon prefers
file:URIs. See here for updated code: https://github.com/18F/fedramp-automation/blob/56d3c9ece5176102a09c0ea0243c4dae386fcb88/src/examples/python/test_validate_ssp.py#L25-L38 - The PR also updated the examples to use the recently-released Saxon/C 11.3, which required some code changes. We didn't switch to the
saxonpyPyPI package since it isn't an official Saxonica build, but as you probably noticed, the example code works with it if you switch the package import fromsaxonctosaxonpy. Use the third-party package at your own risk; since it includes compiled binaries, there could be vulnerabilities within. I would recommend using the official build process from Saxonica, as described here and here.