aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_jabber_sasl.c
blob: 63118d3980b7d12ac1e21ef12db90d23f215a62d (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb00
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include <check.h>
#include <string.h>
#include <stdio.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
{
	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;
}