From 065ef6f4cf2f98f66fd6068b89ac9d447eccfab4 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Thu, 5 Nov 2026 13:00:16 -0600 Subject: [PATCH] Setup clang-format --- .github/workflows/ci.yaml | 27 +++++ src/C/create-empty-client-keytab.c | 1 - test/test_client_keytab_name.c | 12 +- test/test_framework.h | 169 +++++++++++++---------------- test/test_kcron_caps.c | 102 ++++++++--------- test/test_kcron_filename.c | 61 ++++------- test/test_kcron_keytab.c | 9 +- test/test_kcron_keytab_file.c | 32 ++---- 8 files changed, 189 insertions(+), 224 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5189c76..9874284 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,8 +13,35 @@ on: - main jobs: + clang-format: + runs-on: ubuntu-latest + container: + image: fedora:latest + + # clang-format reads the repository's .clang-format and reflows to its + # ColumnLimit. --dry-run discards the output and --Werror makes clang-format + # exit non-zero if any tracked source file would be changed, so this job + # fails (rather than silently reformatting) whenever the tree drifts. + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Install clang-format + run: | + dnf -y update + dnf -y install clang-tools-extra findutils + + # Enumerate sources with find rather than `git ls-files`: actions/checkout + # downloads the tree as a plain archive inside the container (git is not + # present at checkout time), so no .git directory exists for git to read. + # Running from the checkout root makes the repo's .clang-format apply. + - name: Verify formatting + run: find . -type f \( -name '*.c' -o -name '*.h' \) -exec clang-format --dry-run --Werror {} + + build-test: runs-on: ubuntu-latest + # Compile/test will not run until formatting passes. + needs: clang-format container: image: fedora:latest diff --git a/src/C/create-empty-client-keytab.c b/src/C/create-empty-client-keytab.c index e26df1f..49989ea 100644 --- a/src/C/create-empty-client-keytab.c +++ b/src/C/create-empty-client-keytab.c @@ -82,7 +82,6 @@ static void free_buffers(char *keytab, char *keytab_dirname, char *keytab_filena } } - int main(void) { char *keytab = calloc(FILE_PATH_MAX_LENGTH + 3, sizeof(char)); char *keytab_dirname = calloc(FILE_PATH_MAX_LENGTH + 3, sizeof(char)); diff --git a/test/test_client_keytab_name.c b/test/test_client_keytab_name.c index 6e7dac5..a60be11 100644 --- a/test/test_client_keytab_name.c +++ b/test/test_client_keytab_name.c @@ -68,8 +68,7 @@ static int compute_expected(char *buf, size_t n) { if (snprintf(uid_str, sizeof(uid_str), "%u", (unsigned)getuid()) < 0) { return -1; } - if (snprintf(dirname, sizeof(dirname), "%s/%s", __CLIENT_KEYTAB_DIR, - uid_str) < 0) { + if (snprintf(dirname, sizeof(dirname), "%s/%s", __CLIENT_KEYTAB_DIR, uid_str) < 0) { return -1; } if (snprintf(path, sizeof(path), "%s/client.keytab", dirname) < 0) { @@ -88,11 +87,9 @@ TEST(binary_prints_expected_path) { (void)memset(out, 0, sizeof(out)); (void)memset(expected, 0, sizeof(expected)); - TEST_ASSERT_EQ(run_binary(out, sizeof(out)), 0, - "binary must exit successfully and print the path"); + TEST_ASSERT_EQ(run_binary(out, sizeof(out)), 0, "binary must exit successfully and print the path"); - TEST_ASSERT_EQ(compute_expected(expected, sizeof(expected)), 0, - "expected-path computation must succeed"); + TEST_ASSERT_EQ(compute_expected(expected, sizeof(expected)), 0, "expected-path computation must succeed"); /* strip the trailing newline captured from stdout */ size_t len = strlen(out); @@ -100,8 +97,7 @@ TEST(binary_prints_expected_path) { out[len - 1] = '\0'; } - TEST_ASSERT_STR_EQ(out, expected, - "binary stdout must equal the derived keytab path"); + TEST_ASSERT_STR_EQ(out, expected, "binary stdout must equal the derived keytab path"); } TEST(binary_output_has_no_extra_lines) { diff --git a/test/test_framework.h b/test/test_framework.h index 94f5e9b..7c10b13 100644 --- a/test/test_framework.h +++ b/test/test_framework.h @@ -8,7 +8,7 @@ * Creative Commons Public Domain Dedication and Certification (CC-PDDC). * This license applies only to the framework, not uses of the framework. * - * Minimal TAP 14–compliant unit test framework (fork-isolated). + * Minimal TAP 14-compliant unit test framework (fork-isolated). * * Features: * - TAP version 14 output @@ -97,67 +97,66 @@ static int _test_registry_count = 0; * ============================================================================ */ -#define TEST_ASSERT_EQ(actual, expected, msg) \ - do { \ - long _a = (long)(actual); \ - long _e = (long)(expected); \ - if (_a != _e) { \ - fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "# Expected: %ld\n", _e); \ - fprintf(stderr, "# Got: %ld\n", _a); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ +#define TEST_ASSERT_EQ(actual, expected, msg) \ + do { \ + long _a = (long)(actual); \ + long _e = (long)(expected); \ + if (_a != _e) { \ + fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ + fprintf(stderr, "# Expected: %ld\n", _e); \ + fprintf(stderr, "# Got: %ld\n", _a); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ } while (0) -#define TEST_ASSERT_NOT_EQ(actual, expected, msg) \ - do { \ - long _a = (long)(actual); \ - long _e = (long)(expected); \ - if (_a == _e) { \ - fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "# Should not equal: %ld\n", _e); \ - fprintf(stderr, "# Got: %ld\n", _a); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ +#define TEST_ASSERT_NOT_EQ(actual, expected, msg) \ + do { \ + long _a = (long)(actual); \ + long _e = (long)(expected); \ + if (_a == _e) { \ + fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ + fprintf(stderr, "# Should not equal: %ld\n", _e); \ + fprintf(stderr, "# Got: %ld\n", _a); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ } while (0) -#define TEST_ASSERT_STR_EQ(actual, expected, msg) \ - do { \ - const char *_a = (actual); \ - const char *_e = (expected); \ - if (_a == NULL || _e == NULL) { \ - fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ - if (strcmp(_a, _e) != 0) { \ - fprintf(stderr, "# FAIL: %s:%d: strings differ\n", __FILE__, __LINE__); \ - fprintf(stderr, "# Expected: \"%s\"\n", _e); \ - fprintf(stderr, "# Got: \"%s\"\n", _a); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ +#define TEST_ASSERT_STR_EQ(actual, expected, msg) \ + do { \ + const char *_a = (actual); \ + const char *_e = (expected); \ + if (_a == NULL || _e == NULL) { \ + fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ + if (strcmp(_a, _e) != 0) { \ + fprintf(stderr, "# FAIL: %s:%d: strings differ\n", __FILE__, __LINE__); \ + fprintf(stderr, "# Expected: \"%s\"\n", _e); \ + fprintf(stderr, "# Got: \"%s\"\n", _a); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ } while (0) -#define TEST_ASSERT_STR_NOT_EQ(actual, expected, msg) \ - do { \ - const char *_a = (actual); \ - const char *_e = (expected); \ - if (_a == NULL || _e == NULL) { \ - fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ - if (strcmp(_a, _e) == 0) { \ - fprintf(stderr, "# FAIL: %s:%d: strings should differ\n", __FILE__, \ - __LINE__); \ - fprintf(stderr, "# Should not equal: \"%s\"\n", _e); \ - fprintf(stderr, "# Got: \"%s\"\n", _a); \ - fprintf(stderr, "# %s\n", msg); \ - exit(1); \ - } \ +#define TEST_ASSERT_STR_NOT_EQ(actual, expected, msg) \ + do { \ + const char *_a = (actual); \ + const char *_e = (expected); \ + if (_a == NULL || _e == NULL) { \ + fprintf(stderr, "# FAIL: %s:%d\n", __FILE__, __LINE__); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ + if (strcmp(_a, _e) == 0) { \ + fprintf(stderr, "# FAIL: %s:%d: strings should differ\n", __FILE__, __LINE__); \ + fprintf(stderr, "# Should not equal: \"%s\"\n", _e); \ + fprintf(stderr, "# Got: \"%s\"\n", _a); \ + fprintf(stderr, "# %s\n", msg); \ + exit(1); \ + } \ } while (0) /* ============================================================================ @@ -168,15 +167,15 @@ static int _test_registry_count = 0; #define TEST(name) static void test_##name(void) /* Register a test - must be called inside main() */ -#define RUN_TEST(test_name) \ - do { \ - if (_test_registry_count >= MAX_TESTS) { \ - fprintf(stderr, "Too many tests registered\n"); \ - exit(EXIT_FAILURE); \ - } \ - _test_registry[_test_registry_count].name = #test_name; \ - _test_registry[_test_registry_count].func = test_##test_name; \ - _test_registry_count++; \ +#define RUN_TEST(test_name) \ + do { \ + if (_test_registry_count >= MAX_TESTS) { \ + fprintf(stderr, "Too many tests registered\n"); \ + exit(EXIT_FAILURE); \ + } \ + _test_registry[_test_registry_count].name = #test_name; \ + _test_registry[_test_registry_count].func = test_##test_name; \ + _test_registry_count++; \ } while (0) /* ============================================================================ @@ -236,8 +235,7 @@ static inline void _filter_add(struct _test_filter *f, const char *pattern) { f->patterns[f->count++] = strdup(pattern); } -static inline int _filter_matches(const struct _test_filter *f, - const char *name) { +static inline int _filter_matches(const struct _test_filter *f, const char *name) { if (f->count == 0) return 1; /* No filter = match all */ @@ -297,8 +295,7 @@ static inline int _run_test_isolated(const char *name, void (*func)(void)) { clock_gettime(CLOCK_MONOTONIC, &end); /* Cast to double to avoid -Wconversion warnings */ - duration = (double)(end.tv_sec - start.tv_sec) + - (double)(end.tv_nsec - start.tv_nsec) / 1e9; + duration = (double)(end.tv_sec - start.tv_sec) + (double)(end.tv_nsec - start.tv_nsec) / 1e9; } if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { @@ -312,8 +309,7 @@ static inline int _run_test_isolated(const char *name, void (*func)(void)) { } else { if (WIFSIGNALED(status) && WTERMSIG(status) == SIGALRM) { if (_test_config.show_duration) { - printf("not ok %d - %s # TIMEOUT (>%ds)\n", _test_state.current, name, - _test_config.timeout_seconds); + printf("not ok %d - %s # TIMEOUT (>%ds)\n", _test_state.current, name, _test_config.timeout_seconds); } else { printf("not ok %d - %s # TIMEOUT\n", _test_state.current, name); } @@ -355,8 +351,7 @@ static inline int _test_execute_all(struct _test_filter *filter) { _test_state.current++; - if (_run_test_isolated(_test_registry[i].name, _test_registry[i].func) != - 0) { + if (_run_test_isolated(_test_registry[i].name, _test_registry[i].func) != 0) { _test_state.failed++; } } @@ -371,10 +366,7 @@ static inline int _test_execute_all(struct _test_filter *filter) { */ /* Initialize test framework - call at start of main() */ -static inline void _test_init(int argc, char **argv, - struct _test_filter *filter, int default_timeout, - bool default_verbose, - bool default_show_duration) { +static inline void _test_init(int argc, char **argv, struct _test_filter *filter, int default_timeout, bool default_verbose, bool default_show_duration) { _filter_init(filter); /* Set defaults */ @@ -398,19 +390,15 @@ static inline void _test_init(int argc, char **argv, _test_config.show_duration = true; break; case 'h': - fprintf(stderr, "Usage: %s [-svd] [-t timeout] [test1 test2 ...]\n", - argv[0]); + fprintf(stderr, "Usage: %s [-svd] [-t timeout] [test1 test2 ...]\n", argv[0]); fprintf(stderr, " -s Show test stdout/stderr\n"); - fprintf(stderr, - " -t SECONDS Set per-test timeout (0=disabled, default=%d)\n", - default_timeout); + fprintf(stderr, " -t SECONDS Set per-test timeout (0=disabled, default=%d)\n", default_timeout); fprintf(stderr, " -v Verbose output\n"); fprintf(stderr, " -d Show test duration\n"); fprintf(stderr, " -h Show this help\n"); exit(EXIT_SUCCESS); default: - fprintf(stderr, "Usage: %s [-svd] [-t timeout] [test1 test2 ...]\n", - argv[0]); + fprintf(stderr, "Usage: %s [-svd] [-t timeout] [test1 test2 ...]\n", argv[0]); exit(EXIT_FAILURE); } } @@ -424,12 +412,9 @@ static inline void _test_init(int argc, char **argv, if (_test_config.verbose) { fprintf(stderr, "# Test configuration:\n"); fprintf(stderr, "# Timeout: %d seconds\n", _test_config.timeout_seconds); - fprintf(stderr, "# Verbose: %s\n", - _test_config.verbose ? "enabled" : "disabled"); - fprintf(stderr, "# Show duration: %s\n", - _test_config.show_duration ? "enabled" : "disabled"); - fprintf(stderr, "# Show outputs: %s\n", - _show_test_outputs ? "enabled" : "disabled"); + fprintf(stderr, "# Verbose: %s\n", _test_config.verbose ? "enabled" : "disabled"); + fprintf(stderr, "# Show duration: %s\n", _test_config.show_duration ? "enabled" : "disabled"); + fprintf(stderr, "# Show outputs: %s\n", _show_test_outputs ? "enabled" : "disabled"); } _test_state.current = 0; @@ -437,8 +422,8 @@ static inline void _test_init(int argc, char **argv, _test_registry_count = 0; } -#define TEST_INIT(timeout, verbose, show_duration) \ - struct _test_filter filter; \ +#define TEST_INIT(timeout, verbose, show_duration) \ + struct _test_filter filter; \ _test_init(argc, argv, &filter, timeout, verbose, show_duration) /* Execute all registered tests */ diff --git a/test/test_kcron_caps.c b/test/test_kcron_caps.c index 3a5a815..0bbefa4 100644 --- a/test/test_kcron_caps.c +++ b/test/test_kcron_caps.c @@ -55,9 +55,9 @@ static void thunks_valid(void) { * ============================================================================ */ TEST(disable_capabilities_clears_set) { - /* Returns void and exits only on failure; reaching here means success. */ - disable_capabilities(); - TEST_ASSERT_EQ(1, 1, "disable_capabilities must clear the capability set"); + /* Returns void and exits only on failure; reaching here means success. */ + disable_capabilities(); + TEST_ASSERT_EQ(1, 1, "disable_capabilities must clear the capability set"); } /* ============================================================================ @@ -65,24 +65,24 @@ TEST(disable_capabilities_clears_set) { * ============================================================================ */ TEST(print_cap_error_reports_capabilities) { - /* - * With valid pointers this prints the capability name derived from - * cap_to_name(3) and returns; it never exits on the happy path. - */ - print_cap_error("EFFECTIVE", SAMPLE_CAPS, 1); - TEST_ASSERT_EQ(1, 1, "print_cap_error must format and return"); + /* + * With valid pointers this prints the capability name derived from + * cap_to_name(3) and returns; it never exits on the happy path. + */ + print_cap_error("EFFECTIVE", SAMPLE_CAPS, 1); + TEST_ASSERT_EQ(1, 1, "print_cap_error must format and return"); } TEST(print_cap_error_null_mode_is_safe) { - /* The NULL mode guard returns without printing. */ - print_cap_error(NULL, SAMPLE_CAPS, 1); - TEST_ASSERT_EQ(1, 1, "print_cap_error must tolerate NULL mode"); + /* The NULL mode guard returns without printing. */ + print_cap_error(NULL, SAMPLE_CAPS, 1); + TEST_ASSERT_EQ(1, 1, "print_cap_error must tolerate NULL mode"); } TEST(print_cap_error_null_array_is_safe) { - /* The NULL array guard returns without printing. */ - print_cap_error("EFFECTIVE", NULL, 1); - TEST_ASSERT_EQ(1, 1, "print_cap_error must tolerate NULL array"); + /* The NULL array guard returns without printing. */ + print_cap_error("EFFECTIVE", NULL, 1); + TEST_ASSERT_EQ(1, 1, "print_cap_error must tolerate NULL array"); } /* ============================================================================ @@ -97,34 +97,34 @@ TEST(print_cap_error_null_array_is_safe) { * keeping the parent fully able to continue and _exit(0) cleanly. */ static void expect_exit(void (*fn)(void)) { - pid_t pid = fork(); - if (pid == 0) { - fn(); - /* Unreachable: every enable_capabilities path calls exit(). */ - _exit(7); - } - int status = 0; - waitpid(pid, &status, 0); - (void)status; + pid_t pid = fork(); + if (pid == 0) { + fn(); + /* Unreachable: every enable_capabilities path calls exit(). */ + _exit(7); + } + int status = 0; + waitpid(pid, &status, 0); + (void)status; } TEST(enable_capabilities_null_array_exits) { - /* The NULL-array guard calls exit(EXIT_FAILURE). */ - expect_exit(thunks_null); + /* The NULL-array guard calls exit(EXIT_FAILURE). */ + expect_exit(thunks_null); } TEST(enable_capabilities_zero_count_exits) { - /* The num_caps <= 0 guard calls exit(EXIT_FAILURE). */ - expect_exit(thunks_zero); + /* The num_caps <= 0 guard calls exit(EXIT_FAILURE). */ + expect_exit(thunks_zero); } TEST(enable_capabilities_privilege_required) { - /* - * With a valid array the function raises the permitted/effective sets but - * cap_set_proc(3) fails for an unprivileged process, so it exits via - * print_cap_error("APPLY"). Confirms the documented non-return-on-failure. - */ - expect_exit(thunks_valid); + /* + * With a valid array the function raises the permitted/effective sets but + * cap_set_proc(3) fails for an unprivileged process, so it exits via + * print_cap_error("APPLY"). Confirms the documented non-return-on-failure. + */ + expect_exit(thunks_valid); } /* ============================================================================ @@ -132,21 +132,21 @@ TEST(enable_capabilities_privilege_required) { * ============================================================================ */ int main(int argc, char **argv) { - int result; - - TEST_INIT(10, false, false); /* timeout, verbose, duration */ - - /* disable_capabilities */ - RUN_TEST(disable_capabilities_clears_set); - /* print_cap_error */ - RUN_TEST(print_cap_error_reports_capabilities); - RUN_TEST(print_cap_error_null_mode_is_safe); - RUN_TEST(print_cap_error_null_array_is_safe); - /* enable_capabilities */ - RUN_TEST(enable_capabilities_null_array_exits); - RUN_TEST(enable_capabilities_zero_count_exits); - RUN_TEST(enable_capabilities_privilege_required); - - result = TEST_EXECUTE(); - return result; + int result; + + TEST_INIT(10, false, false); /* timeout, verbose, duration */ + + /* disable_capabilities */ + RUN_TEST(disable_capabilities_clears_set); + /* print_cap_error */ + RUN_TEST(print_cap_error_reports_capabilities); + RUN_TEST(print_cap_error_null_mode_is_safe); + RUN_TEST(print_cap_error_null_array_is_safe); + /* enable_capabilities */ + RUN_TEST(enable_capabilities_null_array_exits); + RUN_TEST(enable_capabilities_zero_count_exits); + RUN_TEST(enable_capabilities_privilege_required); + + result = TEST_EXECUTE(); + return result; } diff --git a/test/test_kcron_filename.c b/test/test_kcron_filename.c index 23f8114..1c6871f 100644 --- a/test/test_kcron_filename.c +++ b/test/test_kcron_filename.c @@ -35,8 +35,7 @@ * Recomputes what get_filenames() should produce using getuid() plus the same * string pieces, so the test does not hardcode the UID or the base directory. */ -static int compute_expected(char *keytab_dir, char *keytab_filename, - char *keytab) { +static int compute_expected(char *keytab_dir, char *keytab_filename, char *keytab) { char uid_str[32]; /* 64-bit unsigned IDs fit in 21 characters */ if (snprintf(uid_str, sizeof(uid_str), "%u", (unsigned)getuid()) < 0) { @@ -46,12 +45,10 @@ static int compute_expected(char *keytab_dir, char *keytab_filename, if (snprintf(keytab_filename, FILE_PATH_MAX_LENGTH, "client.keytab") < 0) { return -1; } - if (snprintf(keytab_dir, FILE_PATH_MAX_LENGTH, "%s/%s", __CLIENT_KEYTAB_DIR, - uid_str) < 0) { + if (snprintf(keytab_dir, FILE_PATH_MAX_LENGTH, "%s/%s", __CLIENT_KEYTAB_DIR, uid_str) < 0) { return -1; } - if (snprintf(keytab, FILE_PATH_MAX_LENGTH, "%s/%s", keytab_dir, - keytab_filename) < 0) { + if (snprintf(keytab, FILE_PATH_MAX_LENGTH, "%s/%s", keytab_dir, keytab_filename) < 0) { return -1; } return 0; @@ -67,8 +64,7 @@ TEST(client_dirname_matches_config) { (void)memset(buf, 0, sizeof(buf)); TEST_ASSERT_EQ(get_client_dirname(buf), 0, "expected success"); - TEST_ASSERT_STR_EQ(buf, __CLIENT_KEYTAB_DIR, - "must equal the compiled-in client keytab directory"); + TEST_ASSERT_STR_EQ(buf, __CLIENT_KEYTAB_DIR, "must equal the compiled-in client keytab directory"); } TEST(client_dirname_buffer_has_null_terminator) { @@ -96,8 +92,7 @@ TEST(get_filenames_succeeds) { (void)memset(keytab_dir, 0, sizeof(keytab_dir)); (void)memset(keytab_filename, 0, sizeof(keytab_filename)); (void)memset(keytab, 0, sizeof(keytab)); - TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, - "expected success"); + TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, "expected success"); } TEST(get_filenames_filename_is_constant) { @@ -108,10 +103,8 @@ TEST(get_filenames_filename_is_constant) { (void)memset(keytab_dir, 0, sizeof(keytab_dir)); (void)memset(keytab_filename, 0, sizeof(keytab_filename)); (void)memset(keytab, 0, sizeof(keytab)); - TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, - "expected success"); - TEST_ASSERT_STR_EQ(keytab_filename, "client.keytab", - "filename must always be client.keytab"); + TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, "expected success"); + TEST_ASSERT_STR_EQ(keytab_filename, "client.keytab", "filename must always be client.keytab"); } TEST(get_filenames_directory_under_config) { @@ -123,17 +116,12 @@ TEST(get_filenames_directory_under_config) { (void)memset(keytab_dir, 0, sizeof(keytab_dir)); (void)memset(keytab_filename, 0, sizeof(keytab_filename)); (void)memset(keytab, 0, sizeof(keytab)); - TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, - "expected success"); + TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, "expected success"); dir_len = strlen(keytab_dir); - TEST_ASSERT_EQ(dir_len > strlen(__CLIENT_KEYTAB_DIR), 1, - "directory must be nested below the configured base"); - TEST_ASSERT_EQ(strncmp(keytab_dir, __CLIENT_KEYTAB_DIR, - strlen(__CLIENT_KEYTAB_DIR)), 0, - "directory must start with the configured base"); - TEST_ASSERT_EQ((int)keytab_dir[strlen(__CLIENT_KEYTAB_DIR)], (int)'/', - "base must be followed by a path separator"); + TEST_ASSERT_EQ(dir_len > strlen(__CLIENT_KEYTAB_DIR), 1, "directory must be nested below the configured base"); + TEST_ASSERT_EQ(strncmp(keytab_dir, __CLIENT_KEYTAB_DIR, strlen(__CLIENT_KEYTAB_DIR)), 0, "directory must start with the configured base"); + TEST_ASSERT_EQ((int)keytab_dir[strlen(__CLIENT_KEYTAB_DIR)], (int)'/', "base must be followed by a path separator"); } TEST(get_filenames_reproducible) { @@ -151,17 +139,12 @@ TEST(get_filenames_reproducible) { (void)memset(exp_name, 0, sizeof(exp_name)); (void)memset(exp_path, 0, sizeof(exp_path)); - TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, - "get_filenames must succeed"); - TEST_ASSERT_EQ(compute_expected(exp_dir, exp_name, exp_path), 0, - "compute_expected must succeed"); - - TEST_ASSERT_STR_EQ(keytab_dir, exp_dir, - "computed directory must match independent computation"); - TEST_ASSERT_STR_EQ(keytab_filename, exp_name, - "computed filename must match independent computation"); - TEST_ASSERT_STR_EQ(keytab, exp_path, - "computed path must match independent computation"); + TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, "get_filenames must succeed"); + TEST_ASSERT_EQ(compute_expected(exp_dir, exp_name, exp_path), 0, "compute_expected must succeed"); + + TEST_ASSERT_STR_EQ(keytab_dir, exp_dir, "computed directory must match independent computation"); + TEST_ASSERT_STR_EQ(keytab_filename, exp_name, "computed filename must match independent computation"); + TEST_ASSERT_STR_EQ(keytab, exp_path, "computed path must match independent computation"); } TEST(get_filenames_path_ends_with_filename) { @@ -174,16 +157,12 @@ TEST(get_filenames_path_ends_with_filename) { (void)memset(keytab_dir, 0, sizeof(keytab_dir)); (void)memset(keytab_filename, 0, sizeof(keytab_filename)); (void)memset(keytab, 0, sizeof(keytab)); - TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, - "expected success"); + TEST_ASSERT_EQ(get_filenames(keytab_dir, keytab_filename, keytab), 0, "expected success"); path_len = strlen(keytab); name_len = strlen(keytab_filename); - TEST_ASSERT_EQ((int)(path_len >= name_len), 1, - "path must be at least as long as filename"); - TEST_ASSERT_EQ(strncmp(keytab + (path_len - name_len), keytab_filename, - name_len), 0, - "path must end with the keytab filename"); + TEST_ASSERT_EQ((int)(path_len >= name_len), 1, "path must be at least as long as filename"); + TEST_ASSERT_EQ(strncmp(keytab + (path_len - name_len), keytab_filename, name_len), 0, "path must end with the keytab filename"); } /* ============================================================================ diff --git a/test/test_kcron_keytab.c b/test/test_kcron_keytab.c index 3b334df..b93952a 100644 --- a/test/test_kcron_keytab.c +++ b/test/test_kcron_keytab.c @@ -76,8 +76,7 @@ TEST(write_empty_keytab_writes_exact_magic) { return; } - TEST_ASSERT_EQ(write_empty_keytab(filedescriptor), 0, - "expected successful write of magic bytes"); + TEST_ASSERT_EQ(write_empty_keytab(filedescriptor), 0, "expected successful write of magic bytes"); (void)lseek(filedescriptor, 0, SEEK_SET); nread = read(filedescriptor, readback, sizeof(readback)); @@ -85,10 +84,8 @@ TEST(write_empty_keytab_writes_exact_magic) { TEST_ASSERT_EQ(nread, 2, "must read exactly the two magic bytes"); if (nread == 2) { - TEST_ASSERT_EQ((int)readback[0], (int)EXPECTED_MAGIC[0], - "first magic byte must be the version (0x05)"); - TEST_ASSERT_EQ((int)readback[1], (int)EXPECTED_MAGIC[1], - "second magic byte must be the format (0x02)"); + TEST_ASSERT_EQ((int)readback[0], (int)EXPECTED_MAGIC[0], "first magic byte must be the version (0x05)"); + TEST_ASSERT_EQ((int)readback[1], (int)EXPECTED_MAGIC[1], "second magic byte must be the format (0x02)"); } } diff --git a/test/test_kcron_keytab_file.c b/test/test_kcron_keytab_file.c index bc644d5..5970fb4 100644 --- a/test/test_kcron_keytab_file.c +++ b/test/test_kcron_keytab_file.c @@ -81,14 +81,9 @@ static void make_regular_file(const char *file_path) { * validate_client_dirname * ============================================================================ */ -TEST(validate_client_dirname_null_is_rejected) { - TEST_ASSERT_EQ(validate_client_dirname(NULL), 1, "NULL directory must be rejected"); -} +TEST(validate_client_dirname_null_is_rejected) { TEST_ASSERT_EQ(validate_client_dirname(NULL), 1, "NULL directory must be rejected"); } -TEST(validate_client_dirname_missing_is_rejected) { - TEST_ASSERT_EQ(validate_client_dirname("/this/does/not/exist/kron"), 1, - "non-existent directory must be rejected"); -} +TEST(validate_client_dirname_missing_is_rejected) { TEST_ASSERT_EQ(validate_client_dirname("/this/does/not/exist/kron"), 1, "non-existent directory must be rejected"); } TEST(validate_client_dirname_symlink_is_rejected) { char *dir = make_temp_dir(); @@ -116,14 +111,9 @@ TEST(validate_client_dirname_real_directory_is_accepted) { * validate_keytab_directory * ============================================================================ */ -TEST(validate_keytab_directory_null_is_rejected) { - TEST_ASSERT_EQ(validate_keytab_directory(NULL), 1, "NULL directory must be rejected"); -} +TEST(validate_keytab_directory_null_is_rejected) { TEST_ASSERT_EQ(validate_keytab_directory(NULL), 1, "NULL directory must be rejected"); } -TEST(validate_keytab_directory_missing_is_rejected) { - TEST_ASSERT_EQ(validate_keytab_directory("/no/such/path/kron_keytab"), 1, - "non-existent directory must be rejected"); -} +TEST(validate_keytab_directory_missing_is_rejected) { TEST_ASSERT_EQ(validate_keytab_directory("/no/such/path/kron_keytab"), 1, "non-existent directory must be rejected"); } TEST(validate_keytab_directory_symlink_is_rejected) { char *dir = make_temp_dir(); @@ -164,10 +154,7 @@ TEST(validate_keytab_directory_real_directory_is_accepted) { * create_keytab_file * ============================================================================ */ -TEST(create_keytab_file_null_dirname_rejected) { - TEST_ASSERT_EQ(create_keytab_file(NULL, "client.keytab", "/x"), 1, - "NULL dirname must be rejected"); -} +TEST(create_keytab_file_null_dirname_rejected) { TEST_ASSERT_EQ(create_keytab_file(NULL, "client.keytab", "/x"), 1, "NULL dirname must be rejected"); } TEST(create_keytab_file_null_filename_rejected) { char *dir = make_temp_dir(); @@ -179,16 +166,11 @@ TEST(create_keytab_file_null_filename_rejected) { TEST(create_keytab_file_null_keytab_rejected) { char *dir = make_temp_dir(); - TEST_ASSERT_EQ(create_keytab_file(dir, "client.keytab", NULL), 1, - "NULL keytab path must be rejected"); + TEST_ASSERT_EQ(create_keytab_file(dir, "client.keytab", NULL), 1, "NULL keytab path must be rejected"); free(dir); } -TEST(create_keytab_file_missing_dir_rejected) { - TEST_ASSERT_EQ(create_keytab_file("/no/such/dir/kron", "client.keytab", - "/no/such/dir/kron/1/client.keytab"), - 1, "non-existent directory must be rejected"); -} +TEST(create_keytab_file_missing_dir_rejected) { TEST_ASSERT_EQ(create_keytab_file("/no/such/dir/kron", "client.keytab", "/no/such/dir/kron/1/client.keytab"), 1, "non-existent directory must be rejected"); } TEST(create_keytab_file_symlink_dir_rejected) { char *dir = make_temp_dir();