added unit test for identification_t.matches()
[strongswan.git] / src / charon / plugins / unit_tester / tests / test_id.c
index 9dc7e7d..a1ef76b 100644 (file)
@@ -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;
+}