Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/sntp/tests/keyFile.c
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | CompareKeysAlternative(int key_id, | ||||
return CompareKeys(temp, actual); | return CompareKeys(temp, actual); | ||||
} | } | ||||
void | void | ||||
test_ReadEmptyKeyFile(void) { | test_ReadEmptyKeyFile(void) { | ||||
struct key* keys = NULL; | struct key* keys = NULL; | ||||
const char *path = CreatePath("key-test-empty", INPUT_DIR); | |||||
TEST_ASSERT_EQUAL(0, auth_init(CreatePath("key-test-empty", INPUT_DIR), &keys)); | TEST_ASSERT_NOT_NULL(path); | ||||
TEST_ASSERT_EQUAL(0, auth_init(path, &keys)); | |||||
TEST_ASSERT_NULL(keys); | TEST_ASSERT_NULL(keys); | ||||
free((void *)path); | |||||
} | } | ||||
void | void | ||||
test_ReadASCIIKeys(void) { | test_ReadASCIIKeys(void) { | ||||
struct key* keys = NULL; | struct key* keys = NULL; | ||||
const char *path = CreatePath("key-test-ascii", INPUT_DIR); | |||||
TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-ascii", INPUT_DIR), &keys)); | TEST_ASSERT_NOT_NULL(path); | ||||
TEST_ASSERT_EQUAL(2, auth_init(path, &keys)); | |||||
TEST_ASSERT_NOT_NULL(keys); | TEST_ASSERT_NOT_NULL(keys); | ||||
free((void *)path); | |||||
struct key* result = NULL; | struct key* result = NULL; | ||||
get_key(40, &result); | get_key(40, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(40, 11, "MD5", "asciikeyTwo", *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(40, 11, "MD5", "asciikeyTwo", *result)); | ||||
result = NULL; | result = NULL; | ||||
get_key(50, &result); | get_key(50, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(50, 11, "MD5", "asciikeyOne", *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(50, 11, "MD5", "asciikeyOne", *result)); | ||||
} | } | ||||
void | void | ||||
test_ReadHexKeys(void) { | test_ReadHexKeys(void) { | ||||
struct key* keys = NULL; | struct key* keys = NULL; | ||||
const char *path = CreatePath("key-test-hex", INPUT_DIR); | |||||
TEST_ASSERT_EQUAL(3, auth_init(CreatePath("key-test-hex", INPUT_DIR), &keys)); | TEST_ASSERT_NOT_NULL(path); | ||||
TEST_ASSERT_EQUAL(3, auth_init(path, &keys)); | |||||
TEST_ASSERT_NOT_NULL(keys); | TEST_ASSERT_NOT_NULL(keys); | ||||
free((void *)path); | |||||
struct key* result = NULL; | struct key* result = NULL; | ||||
get_key(10, &result); | get_key(10, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 13, "MD5", | TEST_ASSERT_TRUE(CompareKeysAlternative(10, 13, "MD5", | ||||
"\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89", *result)); | "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89", *result)); | ||||
result = NULL; | result = NULL; | ||||
get_key(20, &result); | get_key(20, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
char data1[15]; memset(data1, 0x11, 15); | char data1[15]; memset(data1, 0x11, 15); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(20, 15, "MD5", data1, *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(20, 15, "MD5", data1, *result)); | ||||
result = NULL; | result = NULL; | ||||
get_key(30, &result); | get_key(30, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
char data2[13]; memset(data2, 0x01, 13); | char data2[13]; memset(data2, 0x01, 13); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(30, 13, "MD5", data2, *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(30, 13, "MD5", data2, *result)); | ||||
} | } | ||||
void | void | ||||
test_ReadKeyFileWithComments(void) { | test_ReadKeyFileWithComments(void) { | ||||
struct key* keys = NULL; | struct key* keys = NULL; | ||||
const char *path = CreatePath("key-test-comments", INPUT_DIR); | |||||
TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-comments", INPUT_DIR), &keys)); | TEST_ASSERT_NOT_NULL(path); | ||||
TEST_ASSERT_EQUAL(2, auth_init(path, &keys)); | |||||
TEST_ASSERT_NOT_NULL(keys); | TEST_ASSERT_NOT_NULL(keys); | ||||
free((void *)path); | |||||
struct key* result = NULL; | struct key* result = NULL; | ||||
get_key(10, &result); | get_key(10, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
char data[15]; memset(data, 0x01, 15); | char data[15]; memset(data, 0x01, 15); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result)); | ||||
result = NULL; | result = NULL; | ||||
get_key(34, &result); | get_key(34, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(34, 3, "MD5", "xyz", *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(34, 3, "MD5", "xyz", *result)); | ||||
} | } | ||||
void | void | ||||
test_ReadKeyFileWithInvalidHex(void) { | test_ReadKeyFileWithInvalidHex(void) { | ||||
struct key* keys = NULL; | struct key* keys = NULL; | ||||
const char *path = CreatePath("key-test-invalid-hex", INPUT_DIR); | |||||
TEST_ASSERT_EQUAL(1, auth_init(CreatePath("key-test-invalid-hex", INPUT_DIR), &keys)); | TEST_ASSERT_NOT_NULL(path); | ||||
TEST_ASSERT_EQUAL(1, auth_init(path, &keys)); | |||||
TEST_ASSERT_NOT_NULL(keys); | TEST_ASSERT_NOT_NULL(keys); | ||||
free((void *)path); | |||||
struct key* result = NULL; | struct key* result = NULL; | ||||
get_key(10, &result); | get_key(10, &result); | ||||
TEST_ASSERT_NOT_NULL(result); | TEST_ASSERT_NOT_NULL(result); | ||||
char data[15]; memset(data, 0x01, 15); | char data[15]; memset(data, 0x01, 15); | ||||
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result)); | TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result)); | ||||
result = NULL; | result = NULL; | ||||
get_key(30, &result); // Should not exist, and result should remain NULL. | get_key(30, &result); // Should not exist, and result should remain NULL. | ||||
TEST_ASSERT_NULL(result); | TEST_ASSERT_NULL(result); | ||||
} | } |