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