Skip to content
Open
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
59 changes: 59 additions & 0 deletions tests/oscap_info_profiles/test_list_rules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,62 @@
rm -rf "$temp_dir"

rm -f $stdout $stderr

# --profiles must produce only ID:title rows for standalone tailoring files.
stdout=$(mktemp -t info_profiles.out.XXXXXX)
stderr=$(mktemp -t info_profiles.err.XXXXXX)
tailoring=$(mktemp -t info_profiles.xml.XXXXXX)
expected=$(mktemp -t info_profiles.expected.XXXXXX)
trap 'rm -f "$stdout" "$stderr" "$tailoring" "$expected"' EXIT

$OSCAP info --profiles "$srcdir/test_tailoring_file.xml" >"$stdout" 2>"$stderr"
[ ! -s "$stderr" ]

Check failure on line 108 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVbx&open=AaHGltQioLmZGk9rVVbx&pullRequest=2484
printf '%s\n' 'xccdf_com.example.www_profile_P1_tailored:Tailored P1' >"$expected"
diff -u "$expected" "$stdout"

# An unavailable benchmark must not prevent listing locally defined profiles.
cat >"$tailoring" <<'XML'
<Tailoring xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_com.example.www_tailoring_profiles">
<benchmark href="missing-benchmark.xml"/>
<version>1.0</version>
<Profile id="xccdf_com.example.www_profile_first" extends="xccdf_com.example.www_profile_base">
<title>First
profile</title>
</Profile>
<Profile id="xccdf_com.example.www_profile_untitled" extends="xccdf_com.example.www_profile_base"/>
<Profile id="xccdf_com.example.www_profile_abstract" abstract="true"><title>Abstract profile</title></Profile>
</Tailoring>
XML
$OSCAP info --profiles "$tailoring" >"$stdout" 2>"$stderr"
[ ! -s "$stderr" ]

Check failure on line 126 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVby&open=AaHGltQioLmZGk9rVVby&pullRequest=2484
cat >"$expected" <<'ROWS'
xccdf_com.example.www_profile_first:Firstprofile
xccdf_com.example.www_profile_untitled:
xccdf_com.example.www_profile_abstract:Abstract profile
ROWS
diff -u "$expected" "$stdout"

# Normal info retains its document header, benchmark hint and verbose profiles.
$OSCAP info "$tailoring" >"$stdout" 2>"$stderr"
[ ! -s "$stderr" ]

Check failure on line 136 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVbz&open=AaHGltQioLmZGk9rVVbz&pullRequest=2484
grep -Fx 'Document type: XCCDF Tailoring' "$stdout"
grep -Fx 'Benchmark Hint: missing-benchmark.xml' "$stdout"
grep -Fx 'Profiles:' "$stdout"

# SDS tailoring profiles use the same terse output without a benchmark hint.
$OSCAP info --profiles "$srcdir/test_reference_ds_with_tailoring.xml" >"$stdout" 2>"$stderr"
[ ! -s "$stderr" ]

Check failure on line 143 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVb0&open=AaHGltQioLmZGk9rVVb0&pullRequest=2484
! grep -q 'Benchmark Hint:' "$stdout"
grep -Fx 'xccdf_com.example.www_profile_P1_tailored:Tailored P1' "$stdout"
! grep -vE '^xccdf_[^:]+:.*$' "$stdout"

# Tailoring without local profiles has an empty terse listing, not headers.
cat >"$tailoring" <<'XML'
<Tailoring xmlns="http://checklists.nist.gov/xccdf/1.2" id="xccdf_com.example.www_tailoring_empty">
<benchmark href="missing-benchmark.xml"/>
<version>1.0</version>
</Tailoring>
XML
$OSCAP info --profiles "$tailoring" >"$stdout" 2>"$stderr"
[ ! -s "$stderr" ]

Check failure on line 156 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVb1&open=AaHGltQioLmZGk9rVVb1&pullRequest=2484
[ ! -s "$stdout" ]

Check failure on line 157 in tests/oscap_info_profiles/test_list_rules.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use '[[' instead of '[' for conditional tests. The '[[' construct is safer and more feature-rich.

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaHGltQioLmZGk9rVVb2&open=AaHGltQioLmZGk9rVVb2&pullRequest=2484
7 changes: 5 additions & 2 deletions utils/oscap-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void _print_xccdf_profile_terse(const struct xccdf_profile *prof, const c
_remove_occurence_of_character_from_string(cleaned_profile_id, '\n');
printf("%s:%s\n",
cleaned_profile_id,
profile_title);
profile_title != NULL ? profile_title : "");
free(profile_title);
}

Expand Down Expand Up @@ -314,7 +314,8 @@ static inline void _print_xccdf_tailoring_header(struct xccdf_tailoring *tailori
static inline void _print_xccdf_tailoring(struct oscap_source *source, const char *prefix, void (*print_one_profile)(const struct xccdf_profile *, const char *))
{
struct xccdf_tailoring *tailoring = xccdf_tailoring_import_source(source, NULL);
_print_xccdf_tailoring_header(tailoring, prefix);
if (prefix != NULL)
_print_xccdf_tailoring_header(tailoring, prefix);

struct xccdf_profile_iterator *prof_it = xccdf_tailoring_get_profiles(tailoring);
_print_xccdf_profiles(prof_it, prefix, print_one_profile);
Expand Down Expand Up @@ -1023,6 +1024,8 @@ static int app_info(const struct oscap_action *action)
}
xccdf_policy_model_free(policy_model);
oscap_source_free(bench_source);
} else if (action->show_profiles_only) {
_print_xccdf_tailoring(source, NULL, _print_xccdf_profile_terse);
} else {
printf("Document type: XCCDF Tailoring\n");
print_time(action->file);
Expand Down