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