aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_jabber_sasl.c
blob: 96c058370a69049f87b7a93996091b372a758045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include <check.h>
#include <string.h>
#include <stdio.h>
#include "arc.h"

char *sasl_get_part( char *data, char *field );

#define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \
                   "something=\"Not \\\"standardized\\\"\""
#define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \
                   "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess"
#define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \
                   "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess,"

struct
{
	const char *challenge;
	char *key;
	char *value;
} get_part_tests[] = {
	{
		challenge1,
		"nonce",
		"1669585310"
	},
	{
		challenge1,
		"charset",
		"utf-8"
	},
	{
		challenge1,
		"harset",
		NULL
	},
	{
		challenge1,
		"something",
		"Not \"standardized\""
	},
	{
		challenge1,
		"something_else",
		NULL
	},
	{
		challenge2,
		"realm",
		"quadpoint.org",
	},
	{
		challenge2,
		"real",
		NULL
	},
	{
		challenge2,
		"qop",
		"auth, auth-int"
	},
	{
		challenge3,
		"realm",
		"localhost"
	},
	{
		challenge3,
		"qop",
		"auth, auth-int, "
	},
	{
		challenge3,
		"charset",
		"utf-8"
	},
	{ NULL, NULL, NULL }
};

static void check_get_part(int l)
{
	int i;
	
	for( i = 0; get_part_tests[i].key; i++ )
	{
  		tcase_fn_start( get_part_tests[i].key, __FILE__, i );
		char *res;
		int len;
		
		res = sasl_get_part( get_part_tests[i].challenge,
		                     get_part_tests[i].key );
		
		if( get_part_tests[i].value == NULL )
			fail_if( res != NULL, "Found key %s in %s while it shouldn't be there!",
			         get_part_tests[i].key, get_part_tests[i].challenge );
		else if( res )
			fail_unless( strcmp( res, get_part_tests[i].value ) == 0,
			             "Incorrect value for key %s in %s: %s",
			             get_part_tests[i].key, get_part_tests[i].challenge, res );
		else
			fail( "Could not find key %s in %s",
			      get_part_tests[i].key, get_part_tests[i].challenge );
		
		g_free( res );
	}
}

Suite *jabber_sasl_suite (void)
{
	Suite *s = suite_create("jabber/sasl");
	TCase *tc_core = tcase_create("Core");
	suite_add_tcase (s, tc_core);
	tcase_add_test (tc_core, check_get_part);
	return s;
}