[af97b23] | 1 | #include <stdlib.h> |
---|
| 2 | #include <glib.h> |
---|
| 3 | #include <gmodule.h> |
---|
| 4 | #include <check.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | |
---|
[5ebff60] | 8 | char *sasl_get_part(char *data, char *field); |
---|
[af97b23] | 9 | |
---|
| 10 | #define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \ |
---|
[5ebff60] | 11 | "something=\"Not \\\"standardized\\\"\"" |
---|
[af97b23] | 12 | #define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \ |
---|
[5ebff60] | 13 | "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess" |
---|
[af97b23] | 14 | #define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \ |
---|
[5ebff60] | 15 | "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess," |
---|
[af97b23] | 16 | |
---|
[5ebff60] | 17 | struct { |
---|
[2d88d25a] | 18 | char *challenge; |
---|
[af97b23] | 19 | char *key; |
---|
| 20 | char *value; |
---|
| 21 | } get_part_tests[] = { |
---|
| 22 | { |
---|
| 23 | challenge1, |
---|
| 24 | "nonce", |
---|
| 25 | "1669585310" |
---|
| 26 | }, |
---|
| 27 | { |
---|
| 28 | challenge1, |
---|
| 29 | "charset", |
---|
| 30 | "utf-8" |
---|
| 31 | }, |
---|
| 32 | { |
---|
| 33 | challenge1, |
---|
| 34 | "harset", |
---|
| 35 | NULL |
---|
| 36 | }, |
---|
| 37 | { |
---|
| 38 | challenge1, |
---|
| 39 | "something", |
---|
| 40 | "Not \"standardized\"" |
---|
| 41 | }, |
---|
| 42 | { |
---|
| 43 | challenge1, |
---|
| 44 | "something_else", |
---|
| 45 | NULL |
---|
| 46 | }, |
---|
| 47 | { |
---|
| 48 | challenge2, |
---|
| 49 | "realm", |
---|
| 50 | "quadpoint.org", |
---|
| 51 | }, |
---|
| 52 | { |
---|
| 53 | challenge2, |
---|
| 54 | "real", |
---|
| 55 | NULL |
---|
| 56 | }, |
---|
| 57 | { |
---|
| 58 | challenge2, |
---|
| 59 | "qop", |
---|
| 60 | "auth, auth-int" |
---|
| 61 | }, |
---|
| 62 | { |
---|
| 63 | challenge3, |
---|
| 64 | "realm", |
---|
| 65 | "localhost" |
---|
| 66 | }, |
---|
| 67 | { |
---|
| 68 | challenge3, |
---|
| 69 | "qop", |
---|
| 70 | "auth, auth-int, " |
---|
| 71 | }, |
---|
| 72 | { |
---|
| 73 | challenge3, |
---|
| 74 | "charset", |
---|
| 75 | "utf-8" |
---|
| 76 | }, |
---|
| 77 | { NULL, NULL, NULL } |
---|
| 78 | }; |
---|
| 79 | |
---|
[6ff651b] | 80 | START_TEST(check_get_part) |
---|
[af97b23] | 81 | { |
---|
| 82 | int i; |
---|
[5ebff60] | 83 | |
---|
| 84 | for (i = 0; get_part_tests[i].key; i++) { |
---|
| 85 | tcase_fn_start(get_part_tests[i].key, __FILE__, i); |
---|
[af97b23] | 86 | char *res; |
---|
[5ebff60] | 87 | |
---|
| 88 | res = sasl_get_part(get_part_tests[i].challenge, |
---|
| 89 | get_part_tests[i].key); |
---|
| 90 | |
---|
| 91 | if (get_part_tests[i].value == NULL) { |
---|
| 92 | fail_if(res != NULL, "Found key %s in %s while it shouldn't be there!", |
---|
| 93 | get_part_tests[i].key, get_part_tests[i].challenge); |
---|
| 94 | } else if (res) { |
---|
| 95 | fail_unless(strcmp(res, get_part_tests[i].value) == 0, |
---|
| 96 | "Incorrect value for key %s in %s: %s", |
---|
| 97 | get_part_tests[i].key, get_part_tests[i].challenge, res); |
---|
| 98 | } else { |
---|
| 99 | fail("Could not find key %s in %s", |
---|
| 100 | get_part_tests[i].key, get_part_tests[i].challenge); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | g_free(res); |
---|
[af97b23] | 104 | } |
---|
| 105 | } |
---|
[6ff651b] | 106 | END_TEST |
---|
[af97b23] | 107 | |
---|
[5ebff60] | 108 | Suite *jabber_sasl_suite(void) |
---|
[af97b23] | 109 | { |
---|
| 110 | Suite *s = suite_create("jabber/sasl"); |
---|
| 111 | TCase *tc_core = tcase_create("Core"); |
---|
[5ebff60] | 112 | |
---|
| 113 | suite_add_tcase(s, tc_core); |
---|
| 114 | tcase_add_test(tc_core, check_get_part); |
---|
[af97b23] | 115 | return s; |
---|
| 116 | } |
---|