Implement verify_signature, check_integrity, and get_system_profile functions

This commit is contained in:
Liam Waldron
2025-03-22 14:08:01 -04:00
parent 1c52dab7b0
commit 0fad47d8ed
6 changed files with 284 additions and 1 deletions

View File

View File

View File

@@ -44,6 +44,41 @@ test_init_config(void)
CU_ASSERT_TRUE(init_config());
}
void
test_verify_signature(void)
{
/* This test assumes that both files exist in the test environment */
CU_ASSERT_EQUAL(verify_signature("test_files/package.tar", "test_files/package.tar.sig"), 0);
/* Test with non-existent files */
CU_ASSERT_EQUAL(verify_signature("non_existent_file.tar", "non_existent_file.tar.sig"), 2);
}
void
test_check_integrity(void)
{
/* This test assumes that test_files/package.tar exists in the test environment
with a known hash value for testing */
char *valid_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; /* Empty file hash */
/* Test file existence check */
CU_ASSERT_EQUAL(check_integrity("non_existent_file.tar", valid_hash), 2);
/* Note: For actual hash comparison testing, we would need a real file with known hash.
These tests would need to be adjusted with real files and hashes for proper testing. */
}
void
test_get_system_profile(void)
{
/* Ensure that get_system_profile doesn't return NULL */
CU_ASSERT_PTR_NOT_NULL(get_system_profile());
/* Ensure the profile format seems correct (contains a dash) */
const char *profile = get_system_profile();
CU_ASSERT_TRUE(strchr(profile, '-') != NULL);
}
int
main(void)
{
@@ -75,7 +110,26 @@ main(void)
return CU_get_error();
}
CU_pSuite security_tests = CU_add_suite("Security Functions Suite", NULL, NULL);
if (! security_tests) {
CU_cleanup_registry();
return CU_get_error();
}
if (! CU_add_test(security_tests, "test of verify_signature()", test_verify_signature)) {
CU_cleanup_registry();
return CU_get_error();
}
if (! CU_add_test(security_tests, "test of check_integrity()", test_check_integrity)) {
CU_cleanup_registry();
return CU_get_error();
}
if (! CU_add_test(runtime_tests, "test of get_system_profile()", test_get_system_profile)) {
CU_cleanup_registry();
return CU_get_error();
}
CU_basic_run_tests();
CU_cleanup_registry();