@@ -169,6 +169,38 @@ function test_api_xccdf_tailoring_profile_generate_guide {
169169 rm -f $guide
170170}
171171
172+ function test_api_xccdf_tailoring_with_extended_component_ordering {
173+ # Regression test for the fix ensuring tailoring extended-component is inserted
174+ # before existing extended-components (e.g. SCE scripts) to maintain schema ordering
175+ # See https://github.com/OpenSCAP/openscap/issues/2260 for more details
176+
177+ local INPUT=$srcdir /$1
178+ local TAILORING=$srcdir /$2
179+
180+ result=` mktemp`
181+ stderr=` mktemp`
182+
183+ # Generate ARF with tailoring
184+ $OSCAP xccdf eval --tailoring-file $TAILORING --profile " xccdf_com.example.www_profile_customized" --results-arf $result $INPUT 2> $stderr || [ " $? " == " 2" ]
185+
186+ # Validate the ARF against schema - this would fail if ordering is wrong
187+ $OSCAP ds rds-validate $result 2> $stderr
188+
189+ # Verify that tailoring extended-component exists
190+ assert_exists 1 ' /arf:asset-report-collection/arf:report-requests/arf:report-request/arf:content/ds:data-stream-collection/ds:component/xccdf:Tailoring'
191+
192+ # Additional check: If we have multiple extended-components, verify tailoring comes before others
193+ # This uses xmllint to check the position - tailoring should come before any other extended-component
194+ extended_comp_count=$( $XPATH $result ' count(//ds:extended-component)' )
195+ if [ " $extended_comp_count " -gt " 1" ]; then
196+ # Get the first extended-component and verify it contains Tailoring
197+ first_ext_comp_has_tailoring=$( $XPATH $result ' count(//ds:extended-component[1]/xccdf:Tailoring)' )
198+ [ " $first_ext_comp_has_tailoring " == " 1" ] || return 1
199+ fi
200+
201+ rm -f " $result " " $stderr "
202+ }
203+
172204# Testing.
173205
174206test_init " test_api_xccdf_tailoring.log"
@@ -191,6 +223,6 @@ test_run "test_api_xccdf_tailoring_simple_include_in_arf_xlink_namespace" test_a
191223test_run " test_api_xccdf_tailoring_profile_include_in_arf" test_api_xccdf_tailoring_profile_include_in_arf baseline.xccdf.xml baseline.tailoring.xml
192224test_run " test_api_xccdf_tailoring_profile_generate_fix" test_api_xccdf_tailoring_profile_generate_fix baseline.xccdf.xml baseline.tailoring.xml
193225test_run " test_api_xccdf_tailoring_profile_generate_guide" test_api_xccdf_tailoring_profile_generate_guide baseline.xccdf.xml baseline.tailoring.xml
194-
226+ test_run " test_api_xccdf_tailoring_with_extended_component_ordering " test_api_xccdf_tailoring_with_extended_component_ordering baseline.xccdf.xml baseline.tailoring.xml
195227
196228test_exit
0 commit comments