Skip to content

Commit

Permalink
Add integration tests for #178.
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-stein-nist committed Oct 26, 2023
1 parent beab59c commit 76c970c
Show file tree
Hide file tree
Showing 43 changed files with 1,740 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/test/java/gov/nist/secauto/oscal/tools/cli/core/CLITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;

import gov.nist.secauto.metaschema.cli.processor.ExitCode;
import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
import gov.nist.secauto.oscal.lib.profile.resolver.ProfileResolutionException;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -79,4 +87,56 @@ void testConvertSubcommandsHelp() {
evaluateResult(CLI.runCli(args), ExitCode.INVALID_COMMAND);
}
}

@Test
void testValidateSubCommandInvalidFile() throws IOException, URISyntaxException {
for (String cmd : modelCommands) {
URL url = getClass().getResource("/cli/example_" + cmd + "_invalid.xml");
String path = Path.of(url.toURI()).toString();
String[] args = { cmd, "validate", path };
ExitStatus result = CLI.runCli(args);
evaluateResult(result, ExitCode.FAIL);
}
}

@Test
void testValidateSubCommandValidFile() throws IOException, URISyntaxException {
for (String cmd : modelCommands) {
URL url = getClass().getResource("/cli/example_" + cmd + "_valid.xml");
String path = Path.of(url.toURI()).toString();
String[] args = { cmd, "validate", path };
ExitStatus result = CLI.runCli(args);
evaluateResult(result, ExitCode.OK);
}
}

@Test
void testConvertSubCommandXmlJsonValidFile() throws IOException, URISyntaxException {
for (String cmd : modelCommands) {
URL url = getClass().getResource("/cli/example_" + cmd + "_invalid.xml");
String path = Path.of(url.toURI()).toString();
String outputPath = path.replace(".xml", ".json");
String[] args = { cmd, "convert", "--to=json", path, outputPath, "--overwrite" };
ExitStatus result = CLI.runCli(args);
evaluateResult(result, ExitCode.OK);
}
}

@Test
void testResolveSubCommandValidFile() throws IOException, URISyntaxException {
URL url = getClass().getResource("/cli/example_profile_valid.xml");
String path = Path.of(url.toURI()).toString();
String[] args = { "profile", "resolve", "--to=xml", path };
ExitStatus result = CLI.runCli(args);
evaluateResult(result, ExitCode.OK);
}

@Test
void testResolveSubCommandInvalidFile() throws IOException, URISyntaxException {
URL url = getClass().getResource("/cli/example_profile_invalid.xml");
String path = Path.of(url.toURI()).toString();
String[] args = { "profile", "resolve", "--to=xml", path };
ExitStatus result = CLI.runCli(args);
evaluateResult(result, ExitCode.PROCESSING_ERROR, ProfileResolutionException.class);
}
}
39 changes: 39 additions & 0 deletions src/test/resources/cli/example_ap_invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"assessment-plan" : {
"uuid" : "bd49e556-187a-458a-9000-0b557f553dae",
"metadata" : {
"title" : "Invalid OSCAL Document",
"last-modified" : "2023-10-24T00:00:00Z",
"version" : "1.0",
"oscal-version" : "1.1.1",
"roles" : [ {
"id" : "maintainer",
"title" : "Maintainer of oscal-cli"
} ],
"parties" : [ {
"uuid" : "4ba3f2b7-e894-48d7-b940-91c68661df55",
"type" : "person",
"name" : "NIST ITL CSD Developer"
} ],
"responsible-parties" : [ {
"role-id" : "maintainer",
"party-uuids" : [ "4ba3f2b7-e894-48d7-b940-91c68661df55" ]
} ]
},
"import-ssp" : {
"href" : "#1db9626b-1ef9-47f9-944f-a71ce8494322"
},
"back-matter" : {
"resources" : [ {
"uuid" : "1db9626b-1ef9-47f9-944f-a71ce8494322",
"rlinks" : [ {
"href" : "example_ssp_invalid.xml"
}, {
"href" : "example_ssp_invalid.json"
}, {
"href" : "example_ssp_invalid.yaml"
} ]
} ]
}
}
}
27 changes: 27 additions & 0 deletions src/test/resources/cli/example_ap_invalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://github.com/usnistgov/OSCAL/releases/download/v1.1.1/oscal_complete_schema.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<assessment-plan xmlns="http://csrc.nist.gov/ns/oscal/1.0" uuid="bd49e556-187a-458a-9000-0b557f553dae">
<metadata>
<title>Invalid OSCAL Document</title>
<last-modified>2023-10-24T00:00:00.000000-00:00</last-modified>
<version>1.0</version>
<oscal-version>1.1.1</oscal-version>
<role id="maintainer">
<title>Maintainer of oscal-cli</title>
</role>
<party uuid="4ba3f2b7-e894-48d7-b940-91c68661df55" type="person">
<name>NIST ITL CSD Developer</name>
</party>
<responsible-party role-id="maintainer">
<party-uuid>4ba3f2b7-e894-48d7-b940-91c68661df55</party-uuid>
</responsible-party>
</metadata>
<import-ssp href="#1db9626b-1ef9-47f9-944f-a71ce8494322"/>
<back-matter>
<resource uuid="1db9626b-1ef9-47f9-944f-a71ce8494322">
<rlink href="example_ssp_invalid.xml"/>
<rlink href="example_ssp_invalid.json"/>
<rlink href="example_ssp_invalid.yaml"/>
</resource>
</back-matter>
</assessment-plan>
28 changes: 28 additions & 0 deletions src/test/resources/cli/example_ap_invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
assessment-plan:
uuid: bd49e556-187a-458a-9000-0b557f553dae
metadata:
title: Invalid OSCAL Document
last-modified: 2023-10-24T00:00:00Z
version: "1.0"
oscal-version: 1.1.1
roles:
- id: maintainer
title: Maintainer of oscal-cli
parties:
- uuid: 4ba3f2b7-e894-48d7-b940-91c68661df55
type: person
name: NIST ITL CSD Developer
responsible-parties:
- role-id: maintainer
party-uuids:
- 4ba3f2b7-e894-48d7-b940-91c68661df55
import-ssp:
href: '#1db9626b-1ef9-47f9-944f-a71ce8494322'
back-matter:
resources:
- uuid: 1db9626b-1ef9-47f9-944f-a71ce8494322
rlinks:
- href: example_ssp_invalid.xml
- href: example_ssp_invalid.json
- href: example_ssp_invalid.yaml
44 changes: 44 additions & 0 deletions src/test/resources/cli/example_ap_valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"assessment-plan" : {
"uuid" : "948a30b0-a706-43b0-ac5a-4c64fda1c3d0",
"metadata" : {
"title" : "Valid OSCAL Document",
"last-modified" : "2023-10-24T00:00:00Z",
"version" : "1.0",
"oscal-version" : "1.1.1",
"roles" : [ {
"id" : "maintainer",
"title" : "Maintainer of oscal-cli"
} ],
"parties" : [ {
"uuid" : "4ba3f2b7-e894-48d7-b940-91c68661df55",
"type" : "person",
"name" : "NIST ITL CSD Developer"
} ],
"responsible-parties" : [ {
"role-id" : "maintainer",
"party-uuids" : [ "4ba3f2b7-e894-48d7-b940-91c68661df55" ]
} ]
},
"import-ssp" : {
"href" : "#4a8f42e8-1357-4664-bd88-aac54cb9aeb8"
},
"reviewed-controls" : {
"control-selections" : [ {
"include-all" : { }
} ]
},
"back-matter" : {
"resources" : [ {
"uuid" : "4a8f42e8-1357-4664-bd88-aac54cb9aeb8",
"rlinks" : [ {
"href" : "example_ssp_valid.xml"
}, {
"href" : "example_ssp_valid.json"
}, {
"href" : "example_ssp_valid.yaml"
} ]
} ]
}
}
}
32 changes: 32 additions & 0 deletions src/test/resources/cli/example_ap_valid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://github.com/usnistgov/OSCAL/releases/download/v1.1.1/oscal_complete_schema.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<assessment-plan xmlns="http://csrc.nist.gov/ns/oscal/1.0" uuid="948a30b0-a706-43b0-ac5a-4c64fda1c3d0">
<metadata>
<title>Valid OSCAL Document</title>
<last-modified>2023-10-24T00:00:00.000000-00:00</last-modified>
<version>1.0</version>
<oscal-version>1.1.1</oscal-version>
<role id="maintainer">
<title>Maintainer of oscal-cli</title>
</role>
<party uuid="4ba3f2b7-e894-48d7-b940-91c68661df55" type="person">
<name>NIST ITL CSD Developer</name>
</party>
<responsible-party role-id="maintainer">
<party-uuid>4ba3f2b7-e894-48d7-b940-91c68661df55</party-uuid>
</responsible-party>
</metadata>
<import-ssp href="#4a8f42e8-1357-4664-bd88-aac54cb9aeb8"/>
<reviewed-controls>
<control-selection>
<include-all />
</control-selection>
</reviewed-controls>
<back-matter>
<resource uuid="4a8f42e8-1357-4664-bd88-aac54cb9aeb8">
<rlink href="example_ssp_valid.xml"/>
<rlink href="example_ssp_valid.json"/>
<rlink href="example_ssp_valid.yaml"/>
</resource>
</back-matter>
</assessment-plan>
31 changes: 31 additions & 0 deletions src/test/resources/cli/example_ap_valid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
assessment-plan:
uuid: 948a30b0-a706-43b0-ac5a-4c64fda1c3d0
metadata:
title: Valid OSCAL Document
last-modified: 2023-10-24T00:00:00Z
version: "1.0"
oscal-version: 1.1.1
roles:
- id: maintainer
title: Maintainer of oscal-cli
parties:
- uuid: 4ba3f2b7-e894-48d7-b940-91c68661df55
type: person
name: NIST ITL CSD Developer
responsible-parties:
- role-id: maintainer
party-uuids:
- 4ba3f2b7-e894-48d7-b940-91c68661df55
import-ssp:
href: '#4a8f42e8-1357-4664-bd88-aac54cb9aeb8'
reviewed-controls:
control-selections:
- include-all: {}
back-matter:
resources:
- uuid: 4a8f42e8-1357-4664-bd88-aac54cb9aeb8
rlinks:
- href: example_ssp_valid.xml
- href: example_ssp_valid.json
- href: example_ssp_valid.yaml
39 changes: 39 additions & 0 deletions src/test/resources/cli/example_ar_invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"assessment-results" : {
"uuid" : "33bef05b-dda4-4c4e-aaec-2721acaee3dc",
"metadata" : {
"title" : "Invalid OSCAL Document",
"last-modified" : "2023-10-24T00:00:00Z",
"version" : "1.0",
"oscal-version" : "1.1.1",
"roles" : [ {
"id" : "maintainer",
"title" : "Maintainer of oscal-cli"
} ],
"parties" : [ {
"uuid" : "4ba3f2b7-e894-48d7-b940-91c68661df55",
"type" : "person",
"name" : "NIST ITL CSD Developer"
} ],
"responsible-parties" : [ {
"role-id" : "maintainer",
"party-uuids" : [ "4ba3f2b7-e894-48d7-b940-91c68661df55" ]
} ]
},
"import-ap" : {
"href" : "#f1a6f923-ca07-4d61-8415-40e873aef6ea"
},
"back-matter" : {
"resources" : [ {
"uuid" : "f1a6f923-ca07-4d61-8415-40e873aef6ea",
"rlinks" : [ {
"href" : "example_ap_invalid.xml"
}, {
"href" : "example_ap_invalid.json"
}, {
"href" : "example_ap_invalid.yaml"
} ]
} ]
}
}
}
27 changes: 27 additions & 0 deletions src/test/resources/cli/example_ar_invalid.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://github.com/usnistgov/OSCAL/releases/download/v1.1.1/oscal_complete_schema.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
<assessment-results xmlns="http://csrc.nist.gov/ns/oscal/1.0" uuid="33bef05b-dda4-4c4e-aaec-2721acaee3dc">
<metadata>
<title>Invalid OSCAL Document</title>
<last-modified>2023-10-24T00:00:00.000000-00:00</last-modified>
<version>1.0</version>
<oscal-version>1.1.1</oscal-version>
<role id="maintainer">
<title>Maintainer of oscal-cli</title>
</role>
<party uuid="4ba3f2b7-e894-48d7-b940-91c68661df55" type="person">
<name>NIST ITL CSD Developer</name>
</party>
<responsible-party role-id="maintainer">
<party-uuid>4ba3f2b7-e894-48d7-b940-91c68661df55</party-uuid>
</responsible-party>
</metadata>
<import-ap href="#f1a6f923-ca07-4d61-8415-40e873aef6ea"/>
<back-matter>
<resource uuid="f1a6f923-ca07-4d61-8415-40e873aef6ea">
<rlink href="example_ap_invalid.xml"/>
<rlink href="example_ap_invalid.json"/>
<rlink href="example_ap_invalid.yaml"/>
</resource>
</back-matter>
</assessment-results>
28 changes: 28 additions & 0 deletions src/test/resources/cli/example_ar_invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
assessment-results:
uuid: 33bef05b-dda4-4c4e-aaec-2721acaee3dc
metadata:
title: Invalid OSCAL Document
last-modified: 2023-10-24T00:00:00Z
version: "1.0"
oscal-version: 1.1.1
roles:
- id: maintainer
title: Maintainer of oscal-cli
parties:
- uuid: 4ba3f2b7-e894-48d7-b940-91c68661df55
type: person
name: NIST ITL CSD Developer
responsible-parties:
- role-id: maintainer
party-uuids:
- 4ba3f2b7-e894-48d7-b940-91c68661df55
import-ap:
href: '#f1a6f923-ca07-4d61-8415-40e873aef6ea'
back-matter:
resources:
- uuid: f1a6f923-ca07-4d61-8415-40e873aef6ea
rlinks:
- href: example_ap_invalid.xml
- href: example_ap_invalid.json
- href: example_ap_invalid.yaml
Loading

0 comments on commit 76c970c

Please sign in to comment.