Skip to content

AC-210 #24

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

Merged
merged 3 commits into from
Nov 10, 2021
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This repository provides `case_validate` as an adaptation of the `pyshacl` comma
To see a human-readable validation report of an instance-data file:

```bash
case_validate input.json
case_validate input.json [input-2.json ...]
```

If `input.json` is not conformant, a report will be emitted, and `case_validate` will exit with status `1`. (This is a `pyshacl` behavior, where `0` and `1` report validation success. Status of >`1` is for other errors.)
Expand Down
10 changes: 6 additions & 4 deletions case_utils/case_validate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def main() -> None:
# parser.
logging.basicConfig(level=logging.DEBUG if ("--debug" in sys.argv or "-d" in sys.argv) else logging.INFO)

case_version_choices_list = ["none", "case-" + CURRENT_CASE_VERSION]
built_version_choices_list = ["none", "case-" + CURRENT_CASE_VERSION]

# Add arguments specific to case_validate.
parser.add_argument(
Expand All @@ -67,7 +67,7 @@ def main() -> None:
)
parser.add_argument(
"--built-version",
choices=tuple(case_version_choices_list),
choices=tuple(built_version_choices_list),
default="case-"+CURRENT_CASE_VERSION,
help="Monolithic aggregation of CASE ontology files at certain versions. Does not require networking to use. Default is most recent CASE release."
)
Expand Down Expand Up @@ -119,12 +119,14 @@ def main() -> None:
default=sys.stdout,
)

parser.add_argument("in_graph")
parser.add_argument("in_graph", nargs="+")

args = parser.parse_args()

data_graph = rdflib.Graph()
data_graph.parse(args.in_graph)
for in_graph in args.in_graph:
_logger.debug("in_graph = %r.", in_graph)
data_graph.parse(in_graph)

ontology_graph = rdflib.Graph()
if args.built_version != "none":
Expand Down
35 changes: 34 additions & 1 deletion tests/case_utils/case_validate/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ files_to_generate := \
format_unspecified_output_jsonld.jsonld \
format_unspecified_output_turtle.ttl \
format_unspecified_output_txt.txt \
format_unspecified_output_unspecified.txt
format_unspecified_output_unspecified.txt \
split_data_graph_PASS.txt \
split_data_graph_XFAIL.txt

all: \
$(files_to_generate)
Expand Down Expand Up @@ -183,3 +185,34 @@ format_unspecified_output_unspecified.txt: \
$< \
> _$@
mv _$@ $@

split_data_graph_PASS.txt: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.ontology.done.log \
$(top_srcdir)/case_utils/case_validate/__init__.py \
$(top_srcdir)/case_utils/ontology/__init__.py \
split_data_graph_1.json \
split_data_graph_2.json
rm -f _$@
source $(tests_srcdir)/venv/bin/activate \
&& case_validate \
--debug \
split_data_graph_1.json \
split_data_graph_2.json \
> _$@
mv _$@ $@

split_data_graph_XFAIL.txt: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.ontology.done.log \
$(top_srcdir)/case_utils/case_validate/__init__.py \
$(top_srcdir)/case_utils/ontology/__init__.py \
split_data_graph_1.json
rm -f _$@
source $(tests_srcdir)/venv/bin/activate \
&& case_validate \
--debug \
split_data_graph_1.json \
> _$@ \
; rc=$$? ; test 1 -eq $$rc
mv _$@ $@
16 changes: 16 additions & 0 deletions tests/case_utils/case_validate/cli/split_data_graph_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"@context": {
"kb": "http://example.org/kb/",
"case-investigation": "https://ontology.caseontology.org/case/investigation/",
"uco-core": "https://unifiedcyberontology.org/ontology/uco/core#"
},
"@graph": [
{
"@id": "kb:provenance-record-1",
"@type": "case-investigation:ProvenanceRecord",
"uco-core:object": {
"@id": "kb:file-1"
}
}
]
}
13 changes: 13 additions & 0 deletions tests/case_utils/case_validate/cli/split_data_graph_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"@context": {
"kb": "http://example.org/kb/",
"uco-observable": "https://unifiedcyberontology.org/ontology/uco/observable#"
},
"@graph": [
{
"@id": "kb:file-1",
"@type": "uco-observable:File"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Validation Report
Conforms: True
10 changes: 10 additions & 0 deletions tests/case_utils/case_validate/cli/split_data_graph_XFAIL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Validation Report
Conforms: False
Results (1):
Constraint Violation in ClassConstraintComponent (http://www.w3.org/ns/shacl#ClassConstraintComponent):
Severity: sh:Violation
Source Shape: [ sh:class core:UcoObject ; sh:minCount Literal("1", datatype=xsd:integer) ; sh:nodeKind sh:BlankNodeOrIRI ; sh:path core:object ]
Focus Node: kb:provenance-record-1
Value Node: kb:file-1
Result Path: core:object
Message: Value does not have class core:UcoObject