From fd95852594c10ccf1d19ca1690ace46cfc72abe2 Mon Sep 17 00:00:00 2001 From: "A.J. Stein" Date: Wed, 31 Jan 2024 17:35:59 -0500 Subject: [PATCH 1/2] Regression test for usnistgov/liboscal-java#232 --- .../profile/resolver/ProfileResolutionTests.java | 12 +++++++++++- src/test/resources/content/issue106-catalog.xml | 16 ++++++++++++++++ src/test/resources/content/issue106-profile.xml | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/content/issue106-catalog.xml create mode 100644 src/test/resources/content/issue106-profile.xml diff --git a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java index 38c602be..2c7e18a7 100644 --- a/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java +++ b/src/test/java/gov/nist/secauto/oscal/lib/profile/resolver/ProfileResolutionTests.java @@ -182,7 +182,8 @@ void performTest(String profileName) throws IOException, SaxonApiException { StringWriter writer = new StringWriter(); serializer.serialize(catalog, writer); - // OscalBindingContext.instance().newSerializer(Format.YAML, Catalog.class).serialize(catalog, + // OscalBindingContext.instance().newSerializer(Format.YAML, + // Catalog.class).serialize(catalog, // System.out); // System.out.println("Pre scrub: " + writer.getBuffer().toString()); @@ -256,4 +257,13 @@ void testArsModerateProfile() throws IOException, ProfileResolutionException, UR assertNotNull(resolvedCatalog); } + + @Test + void testIssue106Profile() throws IOException, ProfileResolutionException, URISyntaxException { + Path profileFile = Paths.get(JUNIT_TEST_PATH, "content/issue106-profile.xml"); + assert profileFile != null; + Catalog catalog = resolveProfile(profileFile); + assertNotNull(catalog); + assertEquals("1.1.1", catalog.getMetadata().getOscalVersion()); + } } diff --git a/src/test/resources/content/issue106-catalog.xml b/src/test/resources/content/issue106-catalog.xml new file mode 100644 index 00000000..d32a2006 --- /dev/null +++ b/src/test/resources/content/issue106-catalog.xml @@ -0,0 +1,16 @@ + + + + + + <last-modified>2023-02-18T13:06:18Z</last-modified> + <version>2023-02-18T13:06:18Z</version> + <oscal-version>1.1.1</oscal-version> + </metadata> + <control id="c1"> + <title /> + <control id="c1.1"> + <title /> + </control> + </control> +</catalog> \ No newline at end of file diff --git a/src/test/resources/content/issue106-profile.xml b/src/test/resources/content/issue106-profile.xml new file mode 100644 index 00000000..1874029d --- /dev/null +++ b/src/test/resources/content/issue106-profile.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?xml-model href="https://github.com/usnistgov/OSCAL/releases/download/v1.1.1/oscal_complete_schema.xsd" schematypens="http://www.w3.org/2001/XMLSchema" title="OSCAL complete schema" ?> +<profile xmlns="http://csrc.nist.gov/ns/oscal/1.0" uuid="3353e8e1-3eef-42ef-8163-1f71616bafca"> + <metadata> + <title /> + <last-modified>2023-02-18T13:06:18Z</last-modified> + <version>2023-02-18T13:06:18Z</version> + <oscal-version>1.1.1</oscal-version> + </metadata> + <import href="issue106-catalog.xml"> + <include-controls> + <with-id>c1.1</with-id> + </include-controls> + </import> +</profile> \ No newline at end of file From 37fcc27cf33109a9270dd3104634b3dbe6b2cd4e Mon Sep 17 00:00:00 2001 From: "A.J. Stein" <alexander.stein@nist.gov> Date: Thu, 1 Feb 2024 10:09:19 -0500 Subject: [PATCH 2/2] Fix unselected control handling for #232 This may be a business logic error or perhaps at one time there was/is a valid reason, but as it stands the BasicIndexer would detect unselected controls for resolution of the profile but only drop them when their parent was selected for the default strategy of flattening. For simple trees where c1 is the root control and c1.1 is the child, so c1 -> c1.1, c1 was not being correctly removed. NOTE: Logging indicates a double index of c1.1 even with this change so that still needs to be fixed most likely to resolve this issue. --- .../profile/resolver/selection/FilterNonSelectedVisitor.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitor.java b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitor.java index 022a8a51..237aef5f 100644 --- a/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitor.java +++ b/src/main/java/gov/nist/secauto/oscal/lib/profile/resolver/selection/FilterNonSelectedVisitor.java @@ -213,10 +213,7 @@ public DefaultResult visitControl( childResult.applyTo(control); } else { // remove this control and promote any needed children - - if (SelectionStatus.SELECTED.equals(index.getSelectionStatus(parent))) { - retval.removeControl(control); - } + retval.removeControl(control); retval.appendPromoted(ObjectUtils.notNull(childResult)); index.removeItem(entity);