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

Using doc-available() correctly with invalid resource with false() result throws Java IO exception #219

Closed
aj-stein-gsa opened this issue Oct 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@aj-stein-gsa
Copy link
Contributor

aj-stein-gsa commented Oct 28, 2024

Describe the bug

When purposefully using the doc-available() Metapath function with an invalid path in a constraint test(), the current stable version of the library throws an underlying Java IO exception that the invalid location cannot be resolved and access. That is intentionally the nature of using this function as a precondition check. The processor cannot emit a test message as the stack trace halts execution before that.

Who is the bug affecting

Developers writing software processing constraints on document instances or developers maintaining the constraints themselves.

How do we replicate this issue

  1. Download the referenced model.
  2. Download the document instance.
  3. Run the following validate-content command.
  4. Review the same reproduced exception.
% metaschema-cli --version               
metaschema-java 1.2.0 built at 2024-10-08T20:00:42+0000 from branch 46df8d8fc25c5de1d7cb0485e534f31efe61b2b7 (46df8d8) at https://github.com/metaschema-framework/metaschema-java
metaschema  built at 2024-10-08T20:00:42+0000 from branch 7c03ce5844e46cf9d047193a37e44422ae6a7d61 (7c03ce5) at https://github.com/metaschema-framework/metaschema.git
% metaschema-cli validate-content -m=src/validations/constraints/unit-tests/unit_test_metaschema.xml src/validations/constraints/unit-tests/security-level-PASS.yaml --show-stack-trace
Loading 'file:/home/meunit_test_metaschema.xml'
Generating Java classes in: /var/folders/_q/y32s9yw56lb81l1sjgtp7k080000gn/T/validation-1367699447477161154
Validating 'file:/home/mesecurity-level-PASS.yaml' as YAML.
A gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultExpectConstraint constraint with id 'content-url-invalid', matching the item at path '/test-case/content[1]', resulted in an unexpected error. The error was: An error occurred while evaluating the expression '. => doc-available()'.
gov.nist.secauto.metaschema.core.metapath.MetapathException: An error occurred while evaluating the expression '. => doc-available()'.
        at gov.nist.secauto.metaschema.core.metapath.MetapathExpression.evaluate(MetapathExpression.java:423) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator.lambda$validateExpect$3(DefaultConstraintValidator.java:658) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at java.base/java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:411) [?:?]
        at java.base/java.util.stream.ReferencePipeline$Head.forEachOrdered(ReferencePipeline.java:772) [?:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator.validateExpect(DefaultConstraintValidator.java:653) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator.validateExpect(DefaultConstraintValidator.java:622) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator.validateField(DefaultConstraintValidator.java:185) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator$Visitor.visitField(DefaultConstraintValidator.java:937) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator$Visitor.visitField(DefaultConstraintValidator.java:887) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.item.node.IFieldNodeItem.accept(IFieldNodeItem.java:41) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.item.node.AbstractNodeItemVisitor.visitModelChildren(AbstractNodeItemVisitor.java:73) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.item.node.AbstractNodeItemVisitor.visitAssembly(AbstractNodeItemVisitor.java:173) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator$Visitor.visitAssembly(DefaultConstraintValidator.java:951) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator$Visitor.visitAssembly(DefaultConstraintValidator.java:887) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.item.node.IAssemblyNodeItem.accept(IAssemblyNodeItem.java:38) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.model.constraint.DefaultConstraintValidator.validate(DefaultConstraintValidator.java:142) [dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.databind.IBindingContext.validate(IBindingContext.java:360) [dev.metaschema.java.metaschema-databind-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.databind.IBindingContext.validate(IBindingContext.java:332) [dev.metaschema.java.metaschema-databind-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.databind.IBindingContext.validateWithConstraints(IBindingContext.java:416) [dev.metaschema.java.metaschema-databind-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.commands.AbstractValidateContentCommand$AbstractValidationCommandExecutor.execute(AbstractValidateContentCommand.java:289) [dev.metaschema.java.metaschema-cli-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.processor.CLIProcessor$CallingContext.invokeCommand(CLIProcessor.java:405) [dev.metaschema.java.cli-processor-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.processor.CLIProcessor$CallingContext.processCommand(CLIProcessor.java:376) [dev.metaschema.java.cli-processor-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.processor.CLIProcessor.parseCommand(CLIProcessor.java:175) [dev.metaschema.java.cli-processor-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.processor.CLIProcessor.process(CLIProcessor.java:158) [dev.metaschema.java.cli-processor-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.CLI.runCli(CLI.java:59) [dev.metaschema.java.metaschema-cli-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.cli.CLI.main(CLI.java:31) [dev.metaschema.java.metaschema-cli-1.2.0.jar:?]
Caused by: gov.nist.secauto.metaschema.core.metapath.MetapathException: Unable to execute function '{http://csrc.nist.gov/ns/metaschema/metapath-functions}doc-available(arg1 as meta:string?) as meta:boolean'
        at gov.nist.secauto.metaschema.core.metapath.function.DefaultFunction.execute(DefaultFunction.java:302) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.cst.StaticFunctionCall.accept(StaticFunctionCall.java:90) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.MetapathExpression.evaluate(MetapathExpression.java:420) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        ... 25 more
Caused by: gov.nist.secauto.metaschema.core.metapath.function.DocumentFunctionException: FODC0002: Unable to retrieve the resource identified by the URI '../content/ssp-all-VALID-no-such-file.xml'.
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.fnDocAvailable(FnDocumentAvailable.java:127) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.fnDocAvailable(FnDocumentAvailable.java:86) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.execute(FnDocumentAvailable.java:61) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.DefaultFunction.execute(DefaultFunction.java:289) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.cst.StaticFunctionCall.accept(StaticFunctionCall.java:90) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.MetapathExpression.evaluate(MetapathExpression.java:420) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        ... 25 more
Caused by: java.io.FileNotFoundException: /Users/alexanderjstein/Code/fedramp-automation/src/validations/constraints/content/ssp-all-VALID-no-such-file.xml (No such file or directory)
        at java.base/java.io.FileInputStream.open0(Native Method) ~[?:?]
        at java.base/java.io.FileInputStream.open(FileInputStream.java:213) ~[?:?]
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:152) ~[?:?]
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:106) ~[?:?]
        at java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:84) ~[?:?]
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.fnDocAvailable(FnDocumentAvailable.java:121) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.fnDocAvailable(FnDocumentAvailable.java:86) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.library.FnDocumentAvailable.execute(FnDocumentAvailable.java:61) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.function.DefaultFunction.execute(DefaultFunction.java:289) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.cst.StaticFunctionCall.accept(StaticFunctionCall.java:90) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        at gov.nist.secauto.metaschema.core.metapath.MetapathExpression.evaluate(MetapathExpression.java:420) ~[dev.metaschema.java.metaschema-core-1.2.0.jar:?]
        ... 25 more
Validation identified the following issues:
FATAL: [CRITICAL] [/test-case/content[1]] A gov.nist.secauto.metaschema.core.model.constraint.impl.DefaultExpectConstraint constraint with id 'content-url-invalid', matching the item at path '/test-case/content[1]', resulted in an unexpected error. The error was: An error occurred while evaluating the expression '. => doc-available()'.
The file 'file:/home/mesecurity-level-PASS.yaml' is invalid.

Expected behavior (i.e. solution)

Only a Metapath evaluation to false() and the constraint message is properly displayed in the case of such constraint violations.

Other comments

No response

@aj-stein-gsa aj-stein-gsa added the bug Something isn't working label Oct 28, 2024
@david-waltermire
Copy link
Contributor

david-waltermire commented Oct 28, 2024

This is fixed by PR #214.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants