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 | |
---|
8 | char *sasl_get_part(char *data, char *field); |
---|
9 | |
---|
10 | #define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \ |
---|
11 | "something=\"Not \\\"standardized\\\"\"" |
---|
12 | #define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \ |
---|
13 | "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess" |
---|
14 | #define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \ |
---|
15 | "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess," |
---|
16 | |
---|
17 | struct { |
---|
18 | char *challenge; |
---|
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 | |
---|
80 | START_TEST(check_get_part) |
---|
81 | { |
---|
82 | int i; |
---|
83 | |
---|
84 | for (i = 0; get_part_tests[i].key; i++) { |
---|
85 | tcase_fn_start(get_part_tests[i].key, __FILE__, i); |
---|
86 | char *res; |
---|
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); |
---|
104 | } |
---|
105 | } |
---|
106 | END_TEST |
---|
107 | |
---|
108 | Suite *jabber_sasl_suite(void) |
---|
109 | { |
---|
110 | Suite *s = suite_create("jabber/sasl"); |
---|
111 | TCase *tc_core = tcase_create("Core"); |
---|
112 | |
---|
113 | suite_add_tcase(s, tc_core); |
---|
114 | tcase_add_test(tc_core, check_get_part); |
---|
115 | return s; |
---|
116 | } |
---|