added unit test for identification_t.equals()
This commit is contained in:
1 parent
01da687f78
commit
05fe0a7d25
2 files changed
+88
No files matched your search
@@ -37,5 +37,6 @@ DEFINE_TEST("IP pool", test_pool, FALSE)
|
|||||||
DEFINE_TEST("SSH agent", test_agent, FALSE)
|
DEFINE_TEST("SSH agent", test_agent, FALSE)
|
||||||
DEFINE_TEST("ID parts", test_id_parts, FALSE)
|
DEFINE_TEST("ID parts", test_id_parts, FALSE)
|
||||||
DEFINE_TEST("ID wildcards", test_id_wildcards, FALSE)
|
DEFINE_TEST("ID wildcards", test_id_wildcards, FALSE)
|
||||||
|
DEFINE_TEST("ID equals", test_id_equals, FALSE)
|
||||||
|
|
||||||
/** @}*/
|
/** @}*/
|
||||||
@@ -107,3 +107,90 @@ bool test_id_wildcards()
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* identification equals test
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
static bool test_id_equals_one(identification_t *a, char *b_str)
|
||||||
|
{
|
||||||
|
identification_t *b;
|
||||||
|
bool equals;
|
||||||
|
|
||||||
|
b = identification_create_from_string(b_str);
|
||||||
|
equals = a->equals(a, b);
|
||||||
|
b->destroy(b);
|
||||||
|
return equals;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool test_id_equals()
|
||||||
|
{
|
||||||
|
identification_t *a;
|
||||||
|
chunk_t encoding, fuzzed;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
a = identification_create_from_string(
|
||||||
|
"C=CH, E=martin@strongswan.org, CN=martin");
|
||||||
|
|
||||||
|
if (!test_id_equals_one(a, "C=CH, E=martin@strongswan.org, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!test_id_equals_one(a, "C=ch, E=martin@STRONGSWAN.ORG, CN=Martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (test_id_equals_one(a, "C=CN, E=martin@strongswan.org, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (test_id_equals_one(a, "E=martin@strongswan.org, C=CH, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (test_id_equals_one(a, "E=martin@strongswan.org, C=CH, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
encoding = chunk_clone(a->get_encoding(a));
|
||||||
|
a->destroy(a);
|
||||||
|
|
||||||
|
/* simple fuzzing, increment each byte of encoding */
|
||||||
|
for (i = 0; i < encoding.len; i++)
|
||||||
|
{
|
||||||
|
if (i == 11 || i == 30 || i == 62)
|
||||||
|
{ /* skip ASN.1 type fields, as equals() handles them graceful */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fuzzed = chunk_clone(encoding);
|
||||||
|
fuzzed.ptr[i]++;
|
||||||
|
a = identification_create_from_encoding(ID_DER_ASN1_DN, fuzzed);
|
||||||
|
if (test_id_equals_one(a, "C=CH, E=martin@strongswan.org, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
a->destroy(a);
|
||||||
|
free(fuzzed.ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* and decrement each byte of encoding */
|
||||||
|
for (i = 0; i < encoding.len; i++)
|
||||||
|
{
|
||||||
|
if (i == 11 || i == 30 || i == 62)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
fuzzed = chunk_clone(encoding);
|
||||||
|
fuzzed.ptr[i]--;
|
||||||
|
a = identification_create_from_encoding(ID_DER_ASN1_DN, fuzzed);
|
||||||
|
if (test_id_equals_one(a, "C=CH, E=martin@strongswan.org, CN=martin"))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
a->destroy(a);
|
||||||
|
free(fuzzed.ptr);
|
||||||
|
}
|
||||||
|
free(encoding.ptr);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user