summaryrefslogtreecommitdiffstats
path: root/tinyHTTP/test/test_auth.h
blob: 4a707f14611e390b5e95f5f9533a27fdeb8d3e53 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
* Copyright (C) 2009 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*	
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*	
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*	
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
#ifndef _TEST_AUTH_H_
#define _TEST_AUTH_H_

struct auth_basic_msg
{
	const char* userid;
	const char* password;

	const char* xres;
};

struct auth_basic_msg auth_basic_msgs[] = 
{
	{ "Aladdin"/*Ali baba*/, "open sesame", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==" },
};

void test_basic_auth()
{
	char *response = tsk_null;
	size_t i, size;

	for(i=0; i<sizeof(auth_basic_msgs)/sizeof(struct auth_basic_msg); i++)
	{
		size = thttp_auth_basic_response(auth_basic_msgs[i].userid, auth_basic_msgs[i].password, &response);
		if(tsk_striequals(auth_basic_msgs[i].xres, response)){
			TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> OK", i);
		}
		else{
			TSK_DEBUG_INFO("[HTTP_BASIC-%d] ==> NOK", i);
		}
	
		TSK_FREE(response);
	}
}


//========================================================================

struct auth_ws
{
	const char* key;
	const char* xres;
};

struct auth_ws auth_ws_msgs[] = 
{
	{ "dGhlIHNhbXBsZSBub25jZQ==", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=" },
	{ "x3JJHMbDL1EzLkh9GBhXDw==", "HSmrc0sMlYUkAGmm5OPpG2HaGWk=" },
};

void test_ws_auth()
{
	thttp_auth_ws_keystring_t response = {0};
	size_t i, size;

	for(i=0; i<sizeof(auth_ws_msgs)/sizeof(struct auth_ws); i++)
	{
		size = thttp_auth_ws_response(auth_ws_msgs[i].key, &response);
		if(tsk_striequals(auth_ws_msgs[i].xres, response)){
			TSK_DEBUG_INFO("[WS_AUTH-%d] ==> OK", i);
		}
		else{
			TSK_DEBUG_INFO("[WS_AUTH-%d] ==> NOK", i);
		}
	}
}



//========================================================================


struct auth_digest_msg
{
	const char* username;
	const char* password;
	const char* realm;
	const char* nonce;
	const char* method;
	const char* uri;
	const char* qop;
	const char* nc;
	const char* cnonce;
	const char* opaque;
	const char* entitybody;

	const char* response;
};

struct auth_digest_msg auth_digest_msgs[] = 
{
	{
		"Mufasa",
		"Circle Of Life",
		"testrealm@host.com",
		"dcd98b7102dd2f0e8b11d0f600bfb0c093",
		"GET",
		"/dir/index.html",
		"auth",
		"00000001",
		"0a4f113b",
		"5ccc069c403ebaf9f0171e9517f40e41",
		0,

		"6629fae49393a05397450978507c4ef1"
	}
	,


};

void test_digest_auth()
{
	tsk_md5string_t response, ha1, ha2;
	size_t i;

	for(i=0; i<sizeof(auth_digest_msgs)/sizeof(struct auth_digest_msg); i++)
	{
		tsk_buffer_t* entitybody;
		/* HA1 */
		thttp_auth_digest_HA1(auth_digest_msgs[i].username, 
			auth_digest_msgs[i].realm, 
			auth_digest_msgs[i].password, 
			&ha1);

		/* HA2 */
		entitybody = tsk_buffer_create(auth_digest_msgs[i].entitybody, strlen(auth_digest_msgs[i].entitybody));
		thttp_auth_digest_HA2(auth_digest_msgs[i].method,
			auth_digest_msgs[i].uri,
			entitybody,
			auth_digest_msgs[i].qop,
			&ha2);
		TSK_OBJECT_SAFE_FREE(entitybody);

		/* RESPONSE */
		thttp_auth_digest_response(&ha1, 
			auth_digest_msgs[i].nonce,
			auth_digest_msgs[i].nc,
			auth_digest_msgs[i].cnonce,
			auth_digest_msgs[i].qop,
			&ha2,
			&response);

		if(tsk_striequals(auth_digest_msgs[i].response, response)){
			TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> OK", i);
		}
		else{
			TSK_DEBUG_INFO("[HTTP_DIGEST-%d] ==> NOK", i);
		}
	}
}




#endif /* _TEST_AUTH_H_ */
OpenPOWER on IntegriCloud