added unit test for identification_t.matches()
This commit is contained in:
@@ -38,5 +38,6 @@ DEFINE_TEST("SSH agent", test_agent, FALSE)
|
||||
DEFINE_TEST("ID parts", test_id_parts, FALSE)
|
||||
DEFINE_TEST("ID wildcards", test_id_wildcards, FALSE)
|
||||
DEFINE_TEST("ID equals", test_id_equals, FALSE)
|
||||
DEFINE_TEST("ID matches", test_id_matches, FALSE)
|
||||
|
||||
/** @}*/
|
||||
|
||||
@@ -193,4 +193,57 @@ bool test_id_equals()
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* identification matches test
|
||||
******************************************************************************/
|
||||
|
||||
static id_match_t test_id_matches_one(identification_t *a, char *b_str)
|
||||
{
|
||||
identification_t *b;
|
||||
id_match_t match;
|
||||
|
||||
b = identification_create_from_string(b_str);
|
||||
match = a->matches(a, b);
|
||||
b->destroy(b);
|
||||
return match;
|
||||
}
|
||||
|
||||
bool test_id_matches()
|
||||
{
|
||||
identification_t *a;
|
||||
|
||||
a = identification_create_from_string(
|
||||
"C=CH, E=martin@strongswan.org, CN=martin");
|
||||
|
||||
if (test_id_matches_one(a, "C=CH, E=martin@strongswan.org, CN=martin")
|
||||
!= ID_MATCH_PERFECT)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=CH, E=*, CN=martin") != ID_MATCH_ONE_WILDCARD)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=CH, E=*, CN=*") != ID_MATCH_ONE_WILDCARD - 1)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=*, E=*, CN=*") != ID_MATCH_ONE_WILDCARD - 2)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=*, E=*, CN=*, O=BADInc") != ID_MATCH_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=*, E=*") != ID_MATCH_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (test_id_matches_one(a, "C=*, E=a@b.c, CN=*") != ID_MATCH_NONE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
a->destroy(a);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user