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
3 changes: 3 additions & 0 deletions tests/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ add_oscap_test_executable(test_oscap_util

add_oscap_test("test_oscap_util.sh")

add_oscap_test_executable(test_verbose_error "test_verbose_error.c")
add_oscap_ctest("common/test_verbose_error" COMMAND test_verbose_error)

if(NOT WIN32)
add_oscap_test_executable(test_tmpdir "test_tmpdir.c")
add_oscap_test("test_tmpdir.sh")
Expand Down
29 changes: 29 additions & 0 deletions tests/common/test_verbose_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include "common/public/oscap.h"
#include "common/public/oscap_debug.h"
#include "common/public/oscap_error.h"

int main(void)
{
oscap_init();
oscap_clearerr();
/* An empty filename cannot be opened, regardless of filesystem permissions. */
bool success = oscap_set_verbose("INFO", "");
const char *description = oscap_err_desc();
int ret = 0;
if (success || !oscap_err() || oscap_err_family() != OSCAP_EFAMILY_OSCAP ||
description == NULL || strstr(description, "Failed to open file") == NULL) {
fprintf(stderr, "Log initialization failure did not populate the library error queue.\n");
ret = 1;
}
oscap_cleanup();
return ret;
}
7 changes: 7 additions & 0 deletions tests/utils/test_verbose_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@
$OSCAP xccdf eval --verbose INFO --profile default --results "$results" --verbose-log-file "$verblofile" "$xccdf" >/dev/null 2>/dev/null
grep -q "I: oscap: Identified document type: Benchmark" "$verblofile"

# A regular file cannot be used as the parent directory of the log file.
status=0
$OSCAP info --verbose INFO --verbose-log-file "$verblofile/log" "$xccdf" >"$results" 2>"$stderr" || status=$?
test "$status" -eq 1

Check failure on line 38 in tests/utils/test_verbose_options.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaGM_6lKFhqDmhoMf6j6&open=AaGM_6lKFhqDmhoMf6j6&pullRequest=2476
test ! -s "$results"

Check failure on line 39 in tests/utils/test_verbose_options.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=OpenSCAP_openscap&issues=AaGM_6lKFhqDmhoMf6j7&open=AaGM_6lKFhqDmhoMf6j7&pullRequest=2476
grep -Fq "Failed to open file $verblofile/log:" "$stderr"

rm -f "$results" "$stderr" "$verblofile"
3 changes: 3 additions & 0 deletions utils/oscap-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ int oscap_module_process(struct oscap_module *module, int argc, char **argv)

if (module->func) {
if (!check_verbose_options(&action)) {
ret = OSCAP_ERROR;
goto cleanup;
}
if (!oscap_set_verbose(action.verbosity_level, action.f_verbose_log)) {
oscap_print_error();
ret = OSCAP_ERROR;
goto cleanup;
}
oscap_print_env_vars();
Expand Down
Loading