belle_sip_register_tester.c 32.9 KB
Newer Older
Simon Morlat's avatar
Simon Morlat committed
1 2
/*
	belle-sip - SIP (RFC3261) library.
3
	Copyright (C) 2010  Belledonne Communications SARL
Simon Morlat's avatar
Simon Morlat committed
4

5 6 7 8
	This program 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 2 of the License, or
	(at your option) any later version.
Simon Morlat's avatar
Simon Morlat committed
9

10 11 12 13
	This program 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 General Public License for more details.
Simon Morlat's avatar
Simon Morlat committed
14

15 16
	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
Simon Morlat's avatar
Simon Morlat committed
17 18 19
*/

#include "belle-sip/belle-sip.h"
20
#include "belle_sip_internal.h"
Ghislain MARY's avatar
Ghislain MARY committed
21
#include "belle_sip_tester.h"
Simon Morlat's avatar
Simon Morlat committed
22

Simon Morlat's avatar
Simon Morlat committed
23 24
#include "register_tester.h"

Ghislain MARY's avatar
Ghislain MARY committed
25

26
const char *test_domain="sip2.linphone.org";
27
const char *auth_domain="sip.linphone.org";
jehan's avatar
jehan committed
28
const char *client_auth_domain="client.example.org";
Simon Morlat's avatar
Simon Morlat committed
29
const char *client_auth_outbound_proxy="sips:sip2.linphone.org:5063";
30
const char *no_server_running_here="sip:test.linphone.org:3;transport=tcp";
31
const char *no_response_here="sip:78.220.48.77:3;transport=%s";
32
const char *test_domain_tls_to_tcp="sip:sip2.linphone.org:5060;transport=tls";
33 34
const char *test_http_proxy_addr="sip.linphone.org";
int test_http_proxy_port = 3128 ;
jehan's avatar
jehan committed
35

jehan's avatar
jehan committed
36
static int is_register_ok;
37
static int number_of_challenge;
38
static int using_transaction;
39 40
static int io_error_count=0;

jehan's avatar
jehan committed
41 42 43
belle_sip_stack_t * stack;
belle_sip_provider_t *prov;
static belle_sip_listener_t* l;
Ghislain MARY's avatar
Ghislain MARY committed
44 45 46 47
belle_sip_request_t* authorized_request;
belle_sip_listener_callbacks_t listener_callbacks;
belle_sip_listener_t *listener;

jehan's avatar
jehan committed
48

jehan's avatar
jehan committed
49
static void process_dialog_terminated(void *user_ctx, const belle_sip_dialog_terminated_event_t *event){
50 51
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
Simon Morlat's avatar
Simon Morlat committed
52 53
	belle_sip_message("process_dialog_terminated called");
}
Ghislain MARY's avatar
Ghislain MARY committed
54

jehan's avatar
jehan committed
55
static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
56 57
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
58
	belle_sip_message("process_io_error, exiting main loop");
59
	belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
60
	io_error_count++;
61
	/*BC_ASSERT(CU_FALSE);*/
Simon Morlat's avatar
Simon Morlat committed
62
}
Ghislain MARY's avatar
Ghislain MARY committed
63

jehan's avatar
jehan committed
64
static void process_request_event(void *user_ctx, const belle_sip_request_event_t *event){
65 66
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
Simon Morlat's avatar
Simon Morlat committed
67 68
	belle_sip_message("process_request_event");
}
Ghislain MARY's avatar
Ghislain MARY committed
69

jehan's avatar
jehan committed
70
static void process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
71 72
	int status;
	belle_sip_request_t* request;
73
	BELLESIP_UNUSED(user_ctx);
74
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_response(event));
75 76 77
	belle_sip_message("process_response_event [%i] [%s]"
					,status=belle_sip_response_get_status_code(belle_sip_response_event_get_response(event))
					,belle_sip_response_get_reason_phrase(belle_sip_response_event_get_response(event)));
78 79 80


	if (status==401){
81 82
		belle_sip_header_cseq_t* cseq;
		belle_sip_client_transaction_t *t;
83
		belle_sip_uri_t *dest;
84 85
		// BC_ASSERT_NOT_EQUAL_FATAL(number_of_challenge,2);
		BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_client_transaction(event)); /*require transaction mode*/
86
		dest=belle_sip_client_transaction_get_route(belle_sip_response_event_get_client_transaction(event));
87
		request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event)));
88
		cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ);
89
		belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1);
90 91
		belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_AUTHORIZATION);
		belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_PROXY_AUTHORIZATION);
92
		BC_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL,NULL,auth_domain));
93

94
		t=belle_sip_provider_create_client_transaction(prov,request);
95
		belle_sip_client_transaction_send_request_to(t,dest);
96
		number_of_challenge++;
97
		authorized_request=request;
Simon Morlat's avatar
Simon Morlat committed
98
		belle_sip_object_ref(authorized_request);
99
	}  else {
100
		BC_ASSERT_EQUAL(status,200,int,"%d");
101 102 103 104
		is_register_ok=1;
		using_transaction=belle_sip_response_event_get_client_transaction(event)!=NULL;
		belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
	}
Simon Morlat's avatar
Simon Morlat committed
105
}
Ghislain MARY's avatar
Ghislain MARY committed
106

jehan's avatar
jehan committed
107
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event){
108 109
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
Simon Morlat's avatar
Simon Morlat committed
110 111
	belle_sip_message("process_timeout");
}
Ghislain MARY's avatar
Ghislain MARY committed
112

jehan's avatar
jehan committed
113
static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event){
114 115
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
Simon Morlat's avatar
Simon Morlat committed
116 117
	belle_sip_message("process_transaction_terminated");
}
Ghislain MARY's avatar
Ghislain MARY committed
118

Simon Morlat's avatar
Simon Morlat committed
119
const char* belle_sip_tester_client_cert = /*for URI:sip:tester@client.example.org*/
jehan's avatar
jehan committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
		"-----BEGIN CERTIFICATE-----\n"
		"MIIDYzCCAsygAwIBAgIBCDANBgkqhkiG9w0BAQUFADCBuzELMAkGA1UEBhMCRlIx\n"
		"EzARBgNVBAgMClNvbWUtU3RhdGUxETAPBgNVBAcMCEdyZW5vYmxlMSIwIAYDVQQK\n"
		"DBlCZWxsZWRvbm5lIENvbW11bmljYXRpb25zMQwwCgYDVQQLDANMQUIxFjAUBgNV\n"
		"BAMMDUplaGFuIE1vbm5pZXIxOjA4BgkqhkiG9w0BCQEWK2plaGFuLm1vbm5pZXJA\n"
		"YmVsbGVkb25uZS1jb21tdW5pY2F0aW9ucy5jb20wHhcNMTMxMDAzMTQ0MTEwWhcN\n"
		"MjMxMDAxMTQ0MTEwWjCBtTELMAkGA1UEBhMCRlIxDzANBgNVBAgMBkZyYW5jZTER\n"
		"MA8GA1UEBwwIR3Jlbm9ibGUxIjAgBgNVBAoMGUJlbGxlZG9ubmUgQ29tbXVuaWNh\n"
		"dGlvbnMxDDAKBgNVBAsMA0xBQjEUMBIGA1UEAwwLY2xpZW50IGNlcnQxOjA4Bgkq\n"
		"hkiG9w0BCQEWK2plaGFuLm1vbm5pZXJAYmVsbGVkb25uZS1jb21tdW5pY2F0aW9u\n"
		"cy5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALZxC/qBi/zB/4lgI7V7\n"
		"I5TsmMmOp0+R/TCyVnYvKQuaJXh9i+CobVM7wj/pQg8RgsY1x+4mVwH1QbhOdIN0\n"
		"ExYHKgLTPlo9FaN6oHPOcHxU/wt552aZhCHC+ushwUUyjy8+T09UOP+xK9V7y5uD\n"
		"ZY+vIOvi6QNwc5cqyy8TREwNAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZIAYb4\n"
		"QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBTL\n"
		"eWEg7jewRbQbKXSdBvsyygGIFzAfBgNVHSMEGDAWgBQGX13HFq9i+C1ucQOIoNYd\n"
		"KwR/ujANBgkqhkiG9w0BAQUFAAOBgQBTbEoi94pVfevbK22Oj8PJFsuy+el1pJG+\n"
		"h0XGM9SQGfbcS7PsV/MhFXtmpnmj3vQB3u5QtMGtWcLA2uxXi79i82gw+oEpBKHR\n"
		"sLqsNCzWNCL9n1pjpNSdqqBFGUdB9pSpnYalujAbuzkqq1ZLyzsElvK7pCaLQcSs\n"
		"oEncRDdPOA==\n"
		"-----END CERTIFICATE-----";

142 143 144
/* fingerprint of certificate generated using openssl x509 -fingerprint */
const char* belle_sip_tester_client_cert_fingerprint =
		"SHA-1 79:2F:9E:8B:28:CC:38:53:90:1D:71:DC:8F:70:66:75:E5:34:CE:C4";
jehan's avatar
jehan committed
145

Simon Morlat's avatar
Simon Morlat committed
146
const char* belle_sip_tester_private_key =
jehan's avatar
jehan committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
		"-----BEGIN ENCRYPTED PRIVATE KEY-----\n"
		"MIICxjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIbEHnQwhgRwoCAggA\n"
		"MBQGCCqGSIb3DQMHBAgmrtCEBCP9kASCAoCq9EKInROalaBSLWY44U4RVAC+CKdx\n"
		"Q8ooT7Bz/grgZuCiaGf0UKINJeV4LYHoP+AWjCH8EeebIA8dldNy5rGcBTt7sXd1\n"
		"QOGmnkBplXTW/NTsb9maYRK56kNJhLE4DR5X5keziV1Tdy2KBmTlpllsCXWsSOBq\n"
		"iI63PTaakIvZxA0TEmie5QQWpH777e/LmW3vVHdH8hhp2zeDDjfSW2E290+ce4Yj\n"
		"SDW9oFXvauzhzhSYRkUdfoJSbpu5MYwyzhjAXQpmBJDauu7+jAU/rQw6TLmYjDNZ\n"
		"3PYHzyD4N7tCG9u4mPBo33dhUirP+8E1BftHB+i/VIn6pI3ypMyiFZ1ZCHqi4vhW\n"
		"z7aChRrUY/8XWCpln3azcfj4SW+Mz62sAChY8rn+yyxFgIno8d9rrx67jyAnYJ6Q\n"
		"sfIMwKp3Sz5oI7IDk8If5SuBVkpqlRV+eZFT6zRRFk65beYpq70BN2mYaKzSV8A7\n"
		"rnciho/dfa9wvyWmkqXciBgWh18UTACOM9HPLmQef3FGaUDLiTAGS1osyypGUEPt\n"
		"Ox3u51qpYkibwyQZo1+ujQkh9PiKfevIAXmty0nTFWMEED15G2SJKjunw5N1rEAh\n"
		"M9jlYpLnATcfigPfGo19QrIPQ1c0LB4BqdwAWN3ZLe0QqYdgwzdcwIoLQRp9iDcw\n"
		"Omc31+38cTc2yGQ2Y2XHZkL8GY/rkqkbhVt9Rnh+VJxFeB6FlsL66EycApe07ngx\n"
		"QimGP57yp4aBzpJyW+6GPf8A/Ogsv3ay1QBLUiGEJtUglRHnl9F6nm5Nxm7wubVx\n"
		"WEuSefVM4xgB+mfQauAJu2N9yKhzXOytslZflpa06qJedlLYFk9njvcv\n"
		"-----END ENCRYPTED PRIVATE KEY-----\n";

Simon Morlat's avatar
Simon Morlat committed
165
const char* belle_sip_tester_private_key_passwd="secret";
jehan's avatar
jehan committed
166 167


jehan's avatar
jehan committed
168
static void process_auth_requested(void *user_ctx, belle_sip_auth_event_t *event){
169
	BELLESIP_UNUSED(user_ctx);
170
	if (belle_sip_auth_event_get_mode(event) == BELLE_SIP_AUTH_MODE_HTTP_DIGEST) {
171 172
		const char *username = belle_sip_auth_event_get_username(event);
		const char *realm = belle_sip_auth_event_get_realm(event);
jehan's avatar
jehan committed
173
		belle_sip_message("process_auth_requested requested for [%s@%s]"
174 175
				,username?username:""
				,realm?realm:"");
jehan's avatar
jehan committed
176 177
		belle_sip_auth_event_set_passwd(event,"secret");
	} else if (belle_sip_auth_event_get_mode(event) == BELLE_SIP_AUTH_MODE_TLS) {
178
		const char *distinguished_name = NULL;
Simon Morlat's avatar
Simon Morlat committed
179 180
		belle_sip_certificates_chain_t* cert = belle_sip_certificates_chain_parse(belle_sip_tester_client_cert,strlen(belle_sip_tester_client_cert),BELLE_SIP_CERTIFICATE_RAW_FORMAT_PEM);
		belle_sip_signing_key_t* key = belle_sip_signing_key_parse(belle_sip_tester_private_key,strlen(belle_sip_tester_private_key),belle_sip_tester_private_key_passwd);
jehan's avatar
jehan committed
181 182
		belle_sip_auth_event_set_client_certificates_chain(event,cert);
		belle_sip_auth_event_set_signing_key(event,key);
183 184
		distinguished_name = belle_sip_auth_event_get_distinguished_name(event);
		belle_sip_message("process_auth_requested requested for  DN[%s]",distinguished_name?distinguished_name:"");
jehan's avatar
jehan committed
185 186 187 188

	} else {
		belle_sip_error("Unexpected auth mode");
	}
189
}
Simon Morlat's avatar
Simon Morlat committed
190

191
int register_before_all(void) {
192
	belle_sip_listening_point_t *lp;
jehan's avatar
jehan committed
193
	stack=belle_sip_stack_new(NULL);
194
	lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP");
Simon Morlat's avatar
Simon Morlat committed
195
	prov=belle_sip_stack_create_provider(stack,lp);
196

Simon Morlat's avatar
Simon Morlat committed
197 198
	lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"TCP");
	belle_sip_provider_add_listening_point(prov,lp);
199
	lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7061,"TLS");
jehan's avatar
jehan committed
200
	if (lp) {
201 202
		/* since test.linphone.org does not have proper certificates, don't verify anything*/
		belle_sip_tls_listening_point_set_verify_exceptions(BELLE_SIP_TLS_LISTENING_POINT(lp),BELLE_SIP_TLS_LISTENING_POINT_BADCERT_ANY_REASON);
203 204 205
		if (belle_sip_tester_get_root_ca_path() != NULL) {
			belle_sip_tls_listening_point_set_root_ca(BELLE_SIP_TLS_LISTENING_POINT(lp), belle_sip_tester_get_root_ca_path());
		}
jehan's avatar
jehan committed
206 207
		belle_sip_provider_add_listening_point(prov,lp);
	}
jehan's avatar
jehan committed
208

jehan's avatar
jehan committed
209 210 211 212 213 214 215 216 217
	listener_callbacks.process_dialog_terminated=process_dialog_terminated;
	listener_callbacks.process_io_error=process_io_error;
	listener_callbacks.process_request_event=process_request_event;
	listener_callbacks.process_response_event=process_response_event;
	listener_callbacks.process_timeout=process_timeout;
	listener_callbacks.process_transaction_terminated=process_transaction_terminated;
	listener_callbacks.process_auth_requested=process_auth_requested;
	listener_callbacks.listener_destroyed=NULL;
	listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,NULL);
jehan's avatar
jehan committed
218 219
	return 0;
}
Ghislain MARY's avatar
Ghislain MARY committed
220

221
int register_after_all(void) {
Simon Morlat's avatar
Simon Morlat committed
222
	belle_sip_object_unref(prov);
jehan's avatar
jehan committed
223
	belle_sip_object_unref(stack);
Simon Morlat's avatar
Simon Morlat committed
224
	belle_sip_object_unref(listener);
jehan's avatar
jehan committed
225 226
	return 0;
}
jehan's avatar
jehan committed
227 228 229 230 231 232

void unregister_user(belle_sip_stack_t * stack
					,belle_sip_provider_t *prov
					,belle_sip_request_t* initial_request
					,int use_transaction) {
	belle_sip_request_t *req;
233 234 235
	belle_sip_header_cseq_t* cseq;
	belle_sip_header_expires_t* expires_header;
	int i;
jehan's avatar
jehan committed
236 237 238 239
	belle_sip_provider_add_sip_listener(prov,l);
	is_register_ok=0;
	using_transaction=0;
	req=(belle_sip_request_t*)belle_sip_object_clone((belle_sip_object_t*)initial_request);
240
	belle_sip_object_ref(req);
241
	cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header((belle_sip_message_t*)req,BELLE_SIP_CSEQ);
jehan's avatar
jehan committed
242
	belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+2); /*+2 if initial reg was challenged*/
243
	expires_header=(belle_sip_header_expires_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_EXPIRES);
jehan's avatar
jehan committed
244 245
	belle_sip_header_expires_set_expires(expires_header,0);
	if (use_transaction){
246
		belle_sip_client_transaction_t *t;
247
		belle_sip_provider_add_authorization(prov,req,NULL,NULL,NULL,NULL); /*just in case*/
248
		t=belle_sip_provider_create_client_transaction(prov,req);
jehan's avatar
jehan committed
249 250
		belle_sip_client_transaction_send_request(t);
	}else belle_sip_provider_send_request(prov,req);
251 252 253 254 255 256 257 258
	for(i=0;!is_register_ok && i<20 ;i++) {
		belle_sip_stack_sleep(stack,500);
		if (!use_transaction && !is_register_ok) {
			belle_sip_object_ref(req);
			belle_sip_provider_send_request(prov,req); /*manage retransmitions*/
		}
	}

259 260
	BC_ASSERT_EQUAL(is_register_ok,1,int,"%d");
	BC_ASSERT_EQUAL(using_transaction,use_transaction,int,"%d");
261
	belle_sip_object_unref(req);
jehan's avatar
jehan committed
262 263
	belle_sip_provider_remove_sip_listener(prov,l);
}
Ghislain MARY's avatar
Ghislain MARY committed
264

jehan's avatar
jehan committed
265
belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
266 267 268 269 270 271 272
	,belle_sip_provider_t *prov
	,const char *transport
	,int use_transaction
	,const char* username
	,const char* domain
	,const char* outbound_proxy
	,int success_expected) {
273
	belle_sip_request_t *req,*copy;
Simon Morlat's avatar
Simon Morlat committed
274 275
	char identity[256];
	char uri[256];
276
	int i;
Simon Morlat's avatar
Simon Morlat committed
277
	char *outbound=NULL;
278
	int do_manual_retransmissions = FALSE;
279

280
	number_of_challenge=0;
Simon Morlat's avatar
Simon Morlat committed
281
	if (transport)
282 283
		snprintf(uri,sizeof(uri),"sip:%s;transport=%s",domain,transport);
	else snprintf(uri,sizeof(uri),"sip:%s",domain);
jehan's avatar
jehan committed
284

Simon Morlat's avatar
Simon Morlat committed
285 286
	if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
		belle_sip_error("No TLS support, test skipped.");
jehan's avatar
jehan committed
287
		return NULL;
Simon Morlat's avatar
Simon Morlat committed
288
	}
289

Simon Morlat's avatar
Simon Morlat committed
290
	if (outbound_proxy){
jehan's avatar
jehan committed
291
		if (strstr(outbound_proxy,"sip:")==NULL && strstr(outbound_proxy,"sips:")==NULL){
Simon Morlat's avatar
Simon Morlat committed
292 293 294
			outbound=belle_sip_strdup_printf("sip:%s",outbound_proxy);
		}else outbound=belle_sip_strdup(outbound_proxy);
	}
Simon Morlat's avatar
Simon Morlat committed
295

296
	snprintf(identity,sizeof(identity),"Tester <sip:%s@%s>",username,domain);
Simon Morlat's avatar
Simon Morlat committed
297
	req=belle_sip_request_create(
298 299 300 301 302 303 304 305
						belle_sip_uri_parse(uri),
						"REGISTER",
						belle_sip_provider_create_call_id(prov),
						belle_sip_header_cseq_create(20,"REGISTER"),
						belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
						belle_sip_header_to_create2(identity,NULL),
						belle_sip_header_via_new(),
						70);
306
	belle_sip_object_ref(req);
jehan's avatar
jehan committed
307
	is_register_ok=0;
308
	io_error_count=0;
309
	using_transaction=0;
jehan's avatar
jehan committed
310
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(600)));
Simon Morlat's avatar
Simon Morlat committed
311
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_contact_new()));
312
	copy=(belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)req));
jehan's avatar
jehan committed
313
	belle_sip_provider_add_sip_listener(prov,l=BELLE_SIP_LISTENER(listener));
Simon Morlat's avatar
Simon Morlat committed
314 315
	if (use_transaction){
		belle_sip_client_transaction_t *t=belle_sip_provider_create_client_transaction(prov,req);
Simon Morlat's avatar
Simon Morlat committed
316
		belle_sip_client_transaction_send_request_to(t,outbound?belle_sip_uri_parse(outbound):NULL);
317 318
	}else{
		belle_sip_provider_send_request(prov,req);
319
		do_manual_retransmissions = (transport == NULL) || (strcasecmp(transport,"udp") == 0);
320
	}
321 322
	for(i=0;!is_register_ok && i<20 && io_error_count==0;i++) {
		belle_sip_stack_sleep(stack,500);
323
		if (do_manual_retransmissions && !is_register_ok) {
324 325 326 327
			belle_sip_object_ref(req);
			belle_sip_provider_send_request(prov,req); /*manage retransmitions*/
		}
	}
328 329
	BC_ASSERT_EQUAL(is_register_ok,success_expected,int,"%d");
	if (success_expected) BC_ASSERT_EQUAL(using_transaction,use_transaction,int,"%d");
330

331
	belle_sip_object_unref(req);
jehan's avatar
jehan committed
332
	belle_sip_provider_remove_sip_listener(prov,l);
Simon Morlat's avatar
Simon Morlat committed
333
	if (outbound) belle_sip_free(outbound);
334
	return copy;
Simon Morlat's avatar
Simon Morlat committed
335
}
Ghislain MARY's avatar
Ghislain MARY committed
336

jehan's avatar
jehan committed
337 338 339 340 341
belle_sip_request_t* register_user_at_domain(belle_sip_stack_t * stack
					,belle_sip_provider_t *prov
					,const char *transport
					,int use_transaction
					,const char* username
342
					,const char* domain
Simon Morlat's avatar
Simon Morlat committed
343 344
					,const char* outbound) {
	return try_register_user_at_domain(stack,prov,transport,use_transaction,username,domain,outbound,1);
345

jehan's avatar
jehan committed
346
}
Ghislain MARY's avatar
Ghislain MARY committed
347

348 349 350 351
belle_sip_request_t* register_user(belle_sip_stack_t * stack
					,belle_sip_provider_t *prov
					,const char *transport
					,int use_transaction
352
					,const char* username
Simon Morlat's avatar
Simon Morlat committed
353 354
					,const char* outbound) {
	return register_user_at_domain(stack,prov,transport,use_transaction,username,test_domain,outbound);
355
}
356

Simon Morlat's avatar
Simon Morlat committed
357
static void register_with_outbound(const char *transport, int use_transaction,const char* outbound ) {
jehan's avatar
jehan committed
358
	belle_sip_request_t *req;
359

Simon Morlat's avatar
Simon Morlat committed
360
	req=register_user(stack, prov, transport,use_transaction,"tester",outbound);
361 362 363 364
	if (req) {
		unregister_user(stack,prov,req,use_transaction);
		belle_sip_object_unref(req);
	}
jehan's avatar
jehan committed
365
}
Ghislain MARY's avatar
Ghislain MARY committed
366

367
static void register_test(const char *transport, int use_transaction) {
Simon Morlat's avatar
Simon Morlat committed
368
	register_with_outbound(transport,use_transaction,NULL);
369
}
Ghislain MARY's avatar
Ghislain MARY committed
370

Simon Morlat's avatar
Simon Morlat committed
371 372
static void stateless_register_udp(void){
	register_test(NULL,0);
jehan's avatar
jehan committed
373
}
Simon Morlat's avatar
Simon Morlat committed
374

jehan's avatar
jehan committed
375 376 377 378
static void stateless_register_tls(void){
	register_test("tls",0);
}

Simon Morlat's avatar
Simon Morlat committed
379 380 381 382 383 384 385
static void stateless_register_tcp(void){
	register_test("tcp",0);
}

static void stateful_register_udp(void){
	register_test(NULL,1);
}
Ghislain MARY's avatar
Ghislain MARY committed
386

387
static void stateful_register_udp_with_keep_alive(void) {
jehan's avatar
jehan committed
388 389 390 391 392
	belle_sip_listening_point_set_keep_alive(belle_sip_provider_get_listening_point(prov,"udp"),200);
	register_test(NULL,1);
	belle_sip_main_loop_sleep(belle_sip_stack_get_main_loop(stack),500);
	belle_sip_listening_point_set_keep_alive(belle_sip_provider_get_listening_point(prov,"udp"),-1);
}
Ghislain MARY's avatar
Ghislain MARY committed
393

Simon Morlat's avatar
Simon Morlat committed
394 395
static void stateful_register_udp_with_outbound_proxy(void){
	register_with_outbound("udp",1,test_domain);
396 397
}

Simon Morlat's avatar
Simon Morlat committed
398
static void stateful_register_udp_delayed(void){
399
	belle_sip_stack_set_tx_delay(stack,3000);
Simon Morlat's avatar
Simon Morlat committed
400 401 402 403
	register_test(NULL,1);
	belle_sip_stack_set_tx_delay(stack,0);
}

404
static void stateful_register_udp_with_send_error(void){
405
	belle_sip_request_t *req;
406
	belle_sip_stack_set_send_error(stack,-1);
407
	req=try_register_user_at_domain(stack, prov, NULL,1,"tester",test_domain,NULL,0);
408
	belle_sip_stack_set_send_error(stack,0);
409
	if (req) belle_sip_object_unref(req);
410 411
}

Simon Morlat's avatar
Simon Morlat committed
412 413
static void stateful_register_tcp(void){
	register_test("tcp",1);
jehan's avatar
jehan committed
414
}
Simon Morlat's avatar
Simon Morlat committed
415

416 417 418
static void stateful_register_tls(void){
	register_test("tls",1);
}
jehan's avatar
jehan committed
419

420 421 422 423 424 425
static void stateful_register_tls_with_http_proxy(void) {
	belle_sip_tls_listening_point_t * lp = (belle_sip_tls_listening_point_t*)belle_sip_provider_get_listening_point(prov, "tls");
	if (!lp) {
		belle_sip_error("No TLS support, test skipped.");
		return;
	}
426
	belle_sip_provider_clean_channels(prov);
427 428
	belle_sip_stack_set_http_proxy_host(stack, test_http_proxy_addr);
	belle_sip_stack_set_http_proxy_port(stack, test_http_proxy_port);
429
	register_test("tls",1);
430 431
	belle_sip_stack_set_http_proxy_host(stack, NULL);
	belle_sip_stack_set_http_proxy_port(stack, 0);
432 433 434 435 436 437 438 439 440 441

}

static void stateful_register_tls_with_wrong_http_proxy(void){
	
	belle_sip_tls_listening_point_t * lp = (belle_sip_tls_listening_point_t*)belle_sip_provider_get_listening_point(prov, "tls");
	if (!lp) {
		belle_sip_error("No TLS support, test skipped.");
		return;
	}
442
	belle_sip_provider_clean_channels(prov);
443 444
	belle_sip_stack_set_http_proxy_host(stack, "mauvaisproxy.linphone.org");
	belle_sip_stack_set_http_proxy_port(stack, test_http_proxy_port);
445
	try_register_user_at_domain(stack,prov,"tls",1,"tester",test_domain,NULL,0);
446 447
	belle_sip_stack_set_http_proxy_host(stack, NULL);
	belle_sip_stack_set_http_proxy_port(stack, 0);
448 449 450 451
	
}


jehan's avatar
jehan committed
452
static void bad_req_process_io_error(void *user_ctx, const belle_sip_io_error_event_t *event){
453 454
	BELLESIP_UNUSED(user_ctx);
	BELLESIP_UNUSED(event);
jehan's avatar
jehan committed
455 456
	belle_sip_message("bad_req_process_io_error not implemented yet");
}
Ghislain MARY's avatar
Ghislain MARY committed
457

jehan's avatar
jehan committed
458
static void bad_req_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){
459
	belle_sip_response_t *resp=belle_sip_response_event_get_response(event);
jehan's avatar
jehan committed
460 461 462 463 464 465
	int *bad_request_response_received=(int*)user_ctx;
	if (belle_sip_response_event_get_client_transaction(event) != NULL) {
		BC_ASSERT_TRUE(resp && belle_sip_response_get_status_code(resp)==400);
		*bad_request_response_received=1;
		belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
	}
jehan's avatar
jehan committed
466 467
}

468
static void test_bad_request(void) {
jehan's avatar
jehan committed
469
	belle_sip_request_t *req;
470 471
	belle_sip_listener_t *bad_req_listener;
	belle_sip_client_transaction_t *t;
jehan's avatar
jehan committed
472 473 474 475
	belle_sip_header_address_t* route_address=belle_sip_header_address_create(NULL,belle_sip_uri_create(NULL,test_domain));
	belle_sip_header_route_t* route;
	belle_sip_header_to_t* to = belle_sip_header_to_create2("sip:toto@titi.com",NULL);
	belle_sip_listener_callbacks_t cbs;
476
	belle_sip_listening_point_t *lp=belle_sip_provider_get_listening_point(prov,"TCP");
477
	int bad_request_response_received=0;
jehan's avatar
jehan committed
478 479 480 481
	memset(&cbs,0,sizeof(cbs));

	cbs.process_io_error=bad_req_process_io_error;
	cbs.process_response_event=bad_req_process_response_event;
482

483
	bad_req_listener = belle_sip_listener_create_from_callbacks(&cbs,&bad_request_response_received);
jehan's avatar
jehan committed
484 485

	req=belle_sip_request_create(
486 487 488 489 490 491 492 493
						BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(route_address)))),
						"REGISTER",
						belle_sip_provider_create_call_id(prov),
						belle_sip_header_cseq_create(20,"REGISTER"),
						belle_sip_header_from_create2("sip:toto@titi.com",BELLE_SIP_RANDOM_TAG),
						to,
						belle_sip_header_via_new(),
						70);
jehan's avatar
jehan committed
494 495 496 497 498 499 500 501 502

	belle_sip_uri_set_transport_param(belle_sip_header_address_get_uri(route_address),"tcp");
	route = belle_sip_header_route_create(route_address);
	belle_sip_header_set_name(BELLE_SIP_HEADER(to),"BrokenHeader");

	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(600)));
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(route));
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_contact_new()));
	belle_sip_provider_add_sip_listener(prov,bad_req_listener);
503
	t=belle_sip_provider_create_client_transaction(prov,req);
jehan's avatar
jehan committed
504
	belle_sip_client_transaction_send_request(t);
505
	belle_sip_stack_sleep(stack,3000);
506
	BC_ASSERT_TRUE(bad_request_response_received==1);
jehan's avatar
jehan committed
507
	belle_sip_provider_remove_sip_listener(prov,bad_req_listener);
Simon Morlat's avatar
Simon Morlat committed
508
	belle_sip_object_unref(bad_req_listener);
509

510
	belle_sip_listening_point_clean_channels(lp);
jehan's avatar
jehan committed
511
}
Simon Morlat's avatar
Simon Morlat committed
512

513
static void test_register_authenticate(void) {
Simon Morlat's avatar
Simon Morlat committed
514
	belle_sip_request_t *reg;
515
	number_of_challenge=0;
516
	authorized_request=NULL;
517
	reg=register_user_at_domain(stack, prov, "udp",1,"bellesip",auth_domain,NULL);
Simon Morlat's avatar
Simon Morlat committed
518 519 520 521 522
	if (authorized_request) {
		unregister_user(stack,prov,authorized_request,1);
		belle_sip_object_unref(authorized_request);
	}
	belle_sip_object_unref(reg);
523
}
jehan's avatar
jehan committed
524

525 526
static void test_register_channel_inactive(void){
	belle_sip_listening_point_t *lp=belle_sip_provider_get_listening_point(prov,"TCP");
527
	BC_ASSERT_PTR_NOT_NULL_FATAL(lp);
528 529
	belle_sip_stack_set_inactive_transport_timeout(stack,5);
	belle_sip_listening_point_clean_channels(lp);
530
	BC_ASSERT_EQUAL(belle_sip_listening_point_get_channel_count(lp),0,int,"%d");
531
	register_test("tcp",1);
532
	BC_ASSERT_EQUAL(belle_sip_listening_point_get_channel_count(lp),1,int,"%d");
533
	belle_sip_stack_sleep(stack,5000);
534
	BC_ASSERT_EQUAL(belle_sip_listening_point_get_channel_count(lp),0,int,"%d");
535 536
	belle_sip_stack_set_inactive_transport_timeout(stack,3600);
}
jehan's avatar
jehan committed
537

jehan's avatar
jehan committed
538 539 540 541 542 543 544 545


static void test_register_client_authenticated(void) {
	belle_sip_request_t *reg;
	authorized_request=NULL;
	/*we don't care to check sercer cert*/
	belle_sip_tls_listening_point_set_verify_exceptions(	(belle_sip_tls_listening_point_t*)belle_sip_provider_get_listening_point(prov,"tls")
															,BELLE_SIP_TLS_LISTENING_POINT_BADCERT_ANY_REASON);
Simon Morlat's avatar
Simon Morlat committed
546
	reg=register_user_at_domain(stack, prov, "tls",1,"tester",client_auth_domain,client_auth_outbound_proxy);
jehan's avatar
jehan committed
547 548 549 550
	if (authorized_request) {
		unregister_user(stack,prov,authorized_request,1);
		belle_sip_object_unref(authorized_request);
	}
551
	if (reg) belle_sip_object_unref(reg);
jehan's avatar
jehan committed
552 553
}

554 555 556 557
static void test_connection_failure(void){
	belle_sip_request_t *req;
	io_error_count=0;
	req=try_register_user_at_domain(stack, prov, "TCP",1,"tester","sip.linphone.org",no_server_running_here,0);
558
	BC_ASSERT_TRUE(io_error_count>=1);
559 560 561
	if (req) belle_sip_object_unref(req);
}

562
static void test_connection_too_long(const char *transport){
563 564
	belle_sip_request_t *req;
	int orig=belle_sip_stack_get_transport_timeout(stack);
565
	char *no_response_here_with_transport = belle_sip_strdup_printf(no_response_here, transport);
566
	io_error_count=0;
567 568 569 570
	if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
		belle_sip_error("No TLS support, test skipped.");
		return;
	}
571
	belle_sip_stack_set_transport_timeout(stack,2000);
572
	req=try_register_user_at_domain(stack, prov, transport,1,"tester","sip.linphone.org",no_response_here_with_transport,0);
573
	BC_ASSERT_GREATER(io_error_count, 1, int, "%d");
574
	belle_sip_stack_set_transport_timeout(stack,orig);
575
	belle_sip_free(no_response_here_with_transport);
576 577 578
	if (req) belle_sip_object_unref(req);
}

579 580 581 582 583 584 585 586
static void test_connection_too_long_tcp(void){
	test_connection_too_long("tcp");
}

static void test_connection_too_long_tls(void){
	test_connection_too_long("tls");
}

587 588 589
static void test_tls_to_tcp(void){
	belle_sip_request_t *req;
	int orig=belle_sip_stack_get_transport_timeout(stack);
590
	io_error_count=0;
591 592 593
	belle_sip_stack_set_transport_timeout(stack,2000);
	req=try_register_user_at_domain(stack, prov, "TLS",1,"tester",test_domain,test_domain_tls_to_tcp,0);
	if (req){
594
		BC_ASSERT_TRUE(io_error_count>=1);
595 596 597 598
		belle_sip_object_unref(req);
	}
	belle_sip_stack_set_transport_timeout(stack,orig);
}
jehan's avatar
jehan committed
599

Simon Morlat's avatar
Simon Morlat committed
600
static void register_dns_srv_tcp(void){
601 602 603
	belle_sip_request_t *req;
	io_error_count=0;
	req=try_register_user_at_domain(stack, prov, "TCP",1,"tester",client_auth_domain,"sip:linphone.net;transport=tcp",1);
604
	BC_ASSERT_TRUE(io_error_count==0);
605 606 607
	if (req) belle_sip_object_unref(req);
}

Simon Morlat's avatar
Simon Morlat committed
608 609 610 611
static void register_dns_srv_tls(void){
	belle_sip_request_t *req;
	io_error_count=0;
	req=try_register_user_at_domain(stack, prov, "TLS",1,"tester",client_auth_domain,"sip:linphone.net;transport=tls",1);
612
	BC_ASSERT_EQUAL(io_error_count, 0, int, "%d");
Simon Morlat's avatar
Simon Morlat committed
613 614 615
	if (req) belle_sip_object_unref(req);
}

616 617 618 619 620 621 622 623
static void register_dns_srv_tls_with_http_proxy(void){
	belle_sip_request_t *req;
	belle_sip_tls_listening_point_t * lp = (belle_sip_tls_listening_point_t*)belle_sip_provider_get_listening_point(prov, "tls");
	if (!lp) {
		belle_sip_error("No TLS support, test skipped.");
		return;
	}
	io_error_count=0;
624
	belle_sip_provider_clean_channels(prov);
625 626
	belle_sip_stack_set_http_proxy_host(stack, test_http_proxy_addr);
	belle_sip_stack_set_http_proxy_port(stack, test_http_proxy_port);
627
	req=try_register_user_at_domain(stack, prov, "TLS",1,"tester",client_auth_domain,"sip:linphone.net;transport=tls",1);
628 629
	belle_sip_stack_set_http_proxy_host(stack, NULL);
	belle_sip_stack_set_http_proxy_port(stack, 0);
630 631 632 633
	BC_ASSERT_EQUAL(io_error_count, 0, int, "%d");
	if (req) belle_sip_object_unref(req);
}

634 635 636 637
static void register_dns_load_balancing(void) {
	belle_sip_request_t *req;
	io_error_count = 0;
	req = try_register_user_at_domain(stack, prov, "TCP", 1, "tester", client_auth_domain, "sip:belle-sip.net;transport=tcp", 1);
638
	BC_ASSERT_EQUAL(io_error_count, 0, int, "%d");
639 640 641
	if (req) belle_sip_object_unref(req);
}

642 643 644
static void process_message_response_event(void *user_ctx, const belle_sip_response_event_t *event){
	int status;
	BELLESIP_UNUSED(user_ctx);
645
	BC_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_response(event));
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
	belle_sip_message("process_response_event [%i] [%s]"
					,status=belle_sip_response_get_status_code(belle_sip_response_event_get_response(event))
					,belle_sip_response_get_reason_phrase(belle_sip_response_event_get_response(event)));

	if (status >= 200){
		is_register_ok=status;
		belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
	}
}
static belle_sip_request_t* send_message(belle_sip_request_t *initial_request, const char* realm){
	int i;
	int io_error_count=0;
	belle_sip_request_t *message_request=NULL;
	belle_sip_request_t *clone_request=NULL;
	// belle_sip_header_authorization_t * h=NULL;

	is_register_ok = 0;

	message_request=belle_sip_request_create(
								belle_sip_uri_parse("sip:sip.linphone.org;transport=tcp")
								,"MESSAGE"
								,belle_sip_provider_create_call_id(prov)
								,belle_sip_header_cseq_create(22,"MESSAGE")
								,belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(initial_request), belle_sip_header_from_t)
								,belle_sip_header_to_parse("To: sip:marie@sip.linphone.org")
								,belle_sip_header_via_new()
								,70);
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(message_request),BELLE_SIP_HEADER(belle_sip_header_expires_create(600)));
	belle_sip_message_add_header(BELLE_SIP_MESSAGE(message_request),BELLE_SIP_HEADER(belle_sip_header_contact_new()));
	belle_sip_provider_add_authorization(prov,message_request,NULL,NULL,NULL,realm);
	// h = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(message_request), belle_sip_header_authorization_t);
	/*if a matching authorization was found, use it as a proxy authorization*/
	// if (h != NULL){
	// 	belle_sip_header_set_name(BELLE_SIP_HEADER(h), BELLE_SIP_PROXY_AUTHORIZATION);
	// }
	clone_request = (belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)message_request));
	belle_sip_client_transaction_send_request_to(belle_sip_provider_create_client_transaction(prov,message_request),NULL);
	for(i=0; i<2 && io_error_count==0 &&is_register_ok==0;i++)
		belle_sip_stack_sleep(stack,5000);

	return clone_request;
}
static void reuse_nonce(void) {
	belle_sip_request_t *register_request;
690
	int initial_auth_context_count=belle_sip_list_size(prov->auth_contexts);
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
	register_request=register_user_at_domain(stack, prov, "tcp",1,"marie","sip.linphone.org",NULL);
	if (register_request) {
		char * first_nonce_used;
		belle_sip_header_authorization_t * h = NULL;
		belle_sip_request_t *message_request;
		listener_callbacks.process_dialog_terminated=process_dialog_terminated;
		listener_callbacks.process_io_error=process_io_error;
		listener_callbacks.process_request_event=process_request_event;
		listener_callbacks.process_response_event=process_message_response_event;
		listener_callbacks.process_timeout=process_timeout;
		listener_callbacks.process_transaction_terminated=process_transaction_terminated;
		listener_callbacks.process_auth_requested=process_auth_requested;
		listener_callbacks.listener_destroyed=NULL;
		listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,NULL);

		belle_sip_provider_add_sip_listener(prov,BELLE_SIP_LISTENER(listener));

		/*currently only one nonce should have been used (the one for the REGISTER)*/
709
		BC_ASSERT_EQUAL(belle_sip_list_size(prov->auth_contexts), initial_auth_context_count+1,int,"%d");
710 711 712

		/*this should reuse previous nonce*/
		message_request=send_message(register_request, auth_domain);
713
		BC_ASSERT_EQUAL(is_register_ok, 404,int,"%d");
714 715 716
		 h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
					BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
				));
717 718
		BC_ASSERT_PTR_NOT_NULL_FATAL(h);
		BC_ASSERT_EQUAL(2, belle_sip_header_authorization_get_nonce_count(h),int,"%d");
719 720 721 722 723 724 725
		first_nonce_used = belle_sip_strdup(belle_sip_header_authorization_get_nonce(h));

		belle_sip_object_unref(message_request);


		/*new nonce should be created when not using outbound proxy realm*/
		message_request=send_message(register_request, NULL);
726
		BC_ASSERT_EQUAL(is_register_ok, 407,int,"%d");
727 728 729
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
730
		BC_ASSERT_PTR_NULL_FATAL(h);
731 732 733 734 735
		belle_sip_object_unref(message_request);


		/*new nonce should be created here too*/
		message_request=send_message(register_request, "wrongrealm");
736
		BC_ASSERT_EQUAL(is_register_ok, 407,int,"%d");
737 738 739
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
740
		BC_ASSERT_PTR_NULL_FATAL(h);
741 742 743 744 745
		belle_sip_object_unref(message_request);


		/*first nonce created should be reused*/
		message_request=send_message(register_request, auth_domain);
746
		BC_ASSERT_EQUAL(is_register_ok, 404,int,"%d");
747 748 749
		h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type(
				BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t
			));
750 751
		BC_ASSERT_PTR_NOT_NULL_FATAL(h);
		BC_ASSERT_EQUAL(3, belle_sip_header_authorization_get_nonce_count(h),int,"%d");
752 753 754 755 756 757 758 759 760
		belle_sip_object_unref(message_request);

		belle_sip_provider_remove_sip_listener(prov,BELLE_SIP_LISTENER(listener));
		unregister_user(stack,prov,register_request,1);
		belle_sip_object_unref(register_request);
		belle_sip_free(first_nonce_used);
	}
}

Simon Morlat's avatar
Simon Morlat committed
761

Ghislain MARY's avatar
Ghislain MARY committed
762 763 764 765 766 767 768 769
test_t register_tests[] = {
	{ "Stateful UDP", stateful_register_udp },
	{ "Stateful UDP with keep-alive", stateful_register_udp_with_keep_alive },
	{ "Stateful UDP with network delay", stateful_register_udp_delayed },
	{ "Stateful UDP with send error", stateful_register_udp_with_send_error },
	{ "Stateful UDP with outbound proxy", stateful_register_udp_with_outbound_proxy },
	{ "Stateful TCP", stateful_register_tcp },
	{ "Stateful TLS", stateful_register_tls },
770
	{ "Stateful TLS with http proxy", stateful_register_tls_with_http_proxy },
jehan's avatar
jehan committed
771
	{ "Stateful TLS with wrong http proxy", stateful_register_tls_with_wrong_http_proxy },
Ghislain MARY's avatar
Ghislain MARY committed
772 773 774 775
	{ "Stateless UDP", stateless_register_udp },
	{ "Stateless TCP", stateless_register_tcp },
	{ "Stateless TLS", stateless_register_tls },
	{ "Bad TCP request", test_bad_request },
776
	{ "Authenticate", test_register_authenticate },
jehan's avatar
jehan committed
777
	{ "TLS client cert authentication", test_register_client_authenticated },
778 779
	{ "Channel inactive", test_register_channel_inactive },
	{ "TCP connection failure", test_connection_failure },
780 781
	{ "TCP connection too long", test_connection_too_long_tcp },
	{ "TLS connection too long", test_connection_too_long_tls },
782
	{ "TLS connection to TCP server", test_tls_to_tcp },
Simon Morlat's avatar
Simon Morlat committed
783
	{ "Register with DNS SRV failover TCP", register_dns_srv_tcp },
784
	{ "Register with DNS SRV failover TLS", register_dns_srv_tls },
785
	{ "Register with DNS SRV failover TLS with http proxy", register_dns_srv_tls_with_http_proxy },
786 787
	{ "Register with DNS load-balancing", register_dns_load_balancing },
	{ "Nonce reutilization", reuse_nonce }
Ghislain MARY's avatar
Ghislain MARY committed
788 789
};

Simon Morlat's avatar
Simon Morlat committed
790 791
test_suite_t register_test_suite = {"REGISTER", register_before_all, register_after_all, NULL,
									NULL, sizeof(register_tests) / sizeof(register_tests[0]),
792
									register_tests};