OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 StunMessage* Receive2() { | 108 StunMessage* Receive2() { |
109 return Receive(client2_.get()); | 109 return Receive(client2_.get()); |
110 } | 110 } |
111 std::string ReceiveRaw1() { | 111 std::string ReceiveRaw1() { |
112 return ReceiveRaw(client1_.get()); | 112 return ReceiveRaw(client1_.get()); |
113 } | 113 } |
114 std::string ReceiveRaw2() { | 114 std::string ReceiveRaw2() { |
115 return ReceiveRaw(client2_.get()); | 115 return ReceiveRaw(client2_.get()); |
116 } | 116 } |
117 StunMessage* Receive(rtc::TestClient* client) { | 117 StunMessage* Receive(rtc::TestClient* client) { |
118 StunMessage* msg = NULL; | 118 StunMessage* msg = nullptr; |
119 rtc::TestClient::Packet* packet = | 119 rtc::TestClient::Packet* packet = |
120 client->NextPacket(rtc::TestClient::kTimeoutMs); | 120 client->NextPacket(rtc::TestClient::kTimeoutMs); |
121 if (packet) { | 121 if (packet) { |
122 rtc::ByteBufferWriter buf(packet->buf, packet->size); | 122 rtc::ByteBufferWriter buf(packet->buf, packet->size); |
123 rtc::ByteBufferReader read_buf(buf); | 123 rtc::ByteBufferReader read_buf(buf); |
124 msg = new RelayMessage(); | 124 msg = new RelayMessage(); |
125 msg->Read(&read_buf); | 125 msg->Read(&read_buf); |
126 delete packet; | 126 delete packet; |
127 } | 127 } |
128 return msg; | 128 return msg; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 res; | 193 res; |
194 | 194 |
195 Send1(req.get()); | 195 Send1(req.get()); |
196 res.reset(Receive1()); | 196 res.reset(Receive1()); |
197 | 197 |
198 ASSERT_TRUE(res); | 198 ASSERT_TRUE(res); |
199 EXPECT_EQ(STUN_ALLOCATE_ERROR_RESPONSE, res->type()); | 199 EXPECT_EQ(STUN_ALLOCATE_ERROR_RESPONSE, res->type()); |
200 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 200 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
201 | 201 |
202 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 202 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
203 ASSERT_TRUE(err != NULL); | 203 ASSERT_TRUE(err != nullptr); |
204 EXPECT_EQ(4, err->eclass()); | 204 EXPECT_EQ(4, err->eclass()); |
205 EXPECT_EQ(32, err->number()); | 205 EXPECT_EQ(32, err->number()); |
206 EXPECT_EQ("Missing Username", err->reason()); | 206 EXPECT_EQ("Missing Username", err->reason()); |
207 } | 207 } |
208 | 208 |
209 // Send a binding request and verify that it is rejected. | 209 // Send a binding request and verify that it is rejected. |
210 TEST_F(RelayServerTest, TestBindingRequest) { | 210 TEST_F(RelayServerTest, TestBindingRequest) { |
211 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), | 211 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), |
212 res; | 212 res; |
213 AddUsernameAttr(req.get(), username_); | 213 AddUsernameAttr(req.get(), username_); |
214 | 214 |
215 Send1(req.get()); | 215 Send1(req.get()); |
216 res.reset(Receive1()); | 216 res.reset(Receive1()); |
217 | 217 |
218 ASSERT_TRUE(res); | 218 ASSERT_TRUE(res); |
219 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, res->type()); | 219 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, res->type()); |
220 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 220 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
221 | 221 |
222 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 222 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
223 ASSERT_TRUE(err != NULL); | 223 ASSERT_TRUE(err != nullptr); |
224 EXPECT_EQ(6, err->eclass()); | 224 EXPECT_EQ(6, err->eclass()); |
225 EXPECT_EQ(0, err->number()); | 225 EXPECT_EQ(0, err->number()); |
226 EXPECT_EQ("Operation Not Supported", err->reason()); | 226 EXPECT_EQ("Operation Not Supported", err->reason()); |
227 } | 227 } |
228 | 228 |
229 // Send an allocate request and verify that it is accepted. | 229 // Send an allocate request and verify that it is accepted. |
230 TEST_F(RelayServerTest, TestAllocate) { | 230 TEST_F(RelayServerTest, TestAllocate) { |
231 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_ALLOCATE_REQUEST)), | 231 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_ALLOCATE_REQUEST)), |
232 res; | 232 res; |
233 AddUsernameAttr(req.get(), username_); | 233 AddUsernameAttr(req.get(), username_); |
234 AddLifetimeAttr(req.get(), LIFETIME); | 234 AddLifetimeAttr(req.get(), LIFETIME); |
235 | 235 |
236 Send1(req.get()); | 236 Send1(req.get()); |
237 res.reset(Receive1()); | 237 res.reset(Receive1()); |
238 | 238 |
239 ASSERT_TRUE(res); | 239 ASSERT_TRUE(res); |
240 EXPECT_EQ(STUN_ALLOCATE_RESPONSE, res->type()); | 240 EXPECT_EQ(STUN_ALLOCATE_RESPONSE, res->type()); |
241 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 241 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
242 | 242 |
243 const StunAddressAttribute* mapped_addr = | 243 const StunAddressAttribute* mapped_addr = |
244 res->GetAddress(STUN_ATTR_MAPPED_ADDRESS); | 244 res->GetAddress(STUN_ATTR_MAPPED_ADDRESS); |
245 ASSERT_TRUE(mapped_addr != NULL); | 245 ASSERT_TRUE(mapped_addr != nullptr); |
246 EXPECT_EQ(1, mapped_addr->family()); | 246 EXPECT_EQ(1, mapped_addr->family()); |
247 EXPECT_EQ(server_ext_addr.port(), mapped_addr->port()); | 247 EXPECT_EQ(server_ext_addr.port(), mapped_addr->port()); |
248 EXPECT_EQ(server_ext_addr.ipaddr(), mapped_addr->ipaddr()); | 248 EXPECT_EQ(server_ext_addr.ipaddr(), mapped_addr->ipaddr()); |
249 | 249 |
250 const StunUInt32Attribute* res_lifetime_attr = | 250 const StunUInt32Attribute* res_lifetime_attr = |
251 res->GetUInt32(STUN_ATTR_LIFETIME); | 251 res->GetUInt32(STUN_ATTR_LIFETIME); |
252 ASSERT_TRUE(res_lifetime_attr != NULL); | 252 ASSERT_TRUE(res_lifetime_attr != nullptr); |
253 EXPECT_EQ(LIFETIME, res_lifetime_attr->value()); | 253 EXPECT_EQ(LIFETIME, res_lifetime_attr->value()); |
254 } | 254 } |
255 | 255 |
256 // Send a second allocate request and verify that it is also accepted, though | 256 // Send a second allocate request and verify that it is also accepted, though |
257 // the lifetime should be ignored. | 257 // the lifetime should be ignored. |
258 TEST_F(RelayServerTest, TestReallocate) { | 258 TEST_F(RelayServerTest, TestReallocate) { |
259 Allocate(); | 259 Allocate(); |
260 | 260 |
261 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_ALLOCATE_REQUEST)), | 261 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_ALLOCATE_REQUEST)), |
262 res; | 262 res; |
263 AddMagicCookieAttr(req.get()); | 263 AddMagicCookieAttr(req.get()); |
264 AddUsernameAttr(req.get(), username_); | 264 AddUsernameAttr(req.get(), username_); |
265 | 265 |
266 Send1(req.get()); | 266 Send1(req.get()); |
267 res.reset(Receive1()); | 267 res.reset(Receive1()); |
268 | 268 |
269 ASSERT_TRUE(res); | 269 ASSERT_TRUE(res); |
270 EXPECT_EQ(STUN_ALLOCATE_RESPONSE, res->type()); | 270 EXPECT_EQ(STUN_ALLOCATE_RESPONSE, res->type()); |
271 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 271 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
272 | 272 |
273 const StunAddressAttribute* mapped_addr = | 273 const StunAddressAttribute* mapped_addr = |
274 res->GetAddress(STUN_ATTR_MAPPED_ADDRESS); | 274 res->GetAddress(STUN_ATTR_MAPPED_ADDRESS); |
275 ASSERT_TRUE(mapped_addr != NULL); | 275 ASSERT_TRUE(mapped_addr != nullptr); |
276 EXPECT_EQ(1, mapped_addr->family()); | 276 EXPECT_EQ(1, mapped_addr->family()); |
277 EXPECT_EQ(server_ext_addr.port(), mapped_addr->port()); | 277 EXPECT_EQ(server_ext_addr.port(), mapped_addr->port()); |
278 EXPECT_EQ(server_ext_addr.ipaddr(), mapped_addr->ipaddr()); | 278 EXPECT_EQ(server_ext_addr.ipaddr(), mapped_addr->ipaddr()); |
279 | 279 |
280 const StunUInt32Attribute* lifetime_attr = | 280 const StunUInt32Attribute* lifetime_attr = |
281 res->GetUInt32(STUN_ATTR_LIFETIME); | 281 res->GetUInt32(STUN_ATTR_LIFETIME); |
282 ASSERT_TRUE(lifetime_attr != NULL); | 282 ASSERT_TRUE(lifetime_attr != nullptr); |
283 EXPECT_EQ(LIFETIME, lifetime_attr->value()); | 283 EXPECT_EQ(LIFETIME, lifetime_attr->value()); |
284 } | 284 } |
285 | 285 |
286 // Send a request from another client and see that it arrives at the first | 286 // Send a request from another client and see that it arrives at the first |
287 // client in the binding. | 287 // client in the binding. |
288 TEST_F(RelayServerTest, TestRemoteBind) { | 288 TEST_F(RelayServerTest, TestRemoteBind) { |
289 Allocate(); | 289 Allocate(); |
290 | 290 |
291 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), | 291 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), |
292 res; | 292 res; |
293 AddUsernameAttr(req.get(), username_); | 293 AddUsernameAttr(req.get(), username_); |
294 | 294 |
295 Send2(req.get()); | 295 Send2(req.get()); |
296 res.reset(Receive1()); | 296 res.reset(Receive1()); |
297 | 297 |
298 ASSERT_TRUE(res); | 298 ASSERT_TRUE(res); |
299 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); | 299 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); |
300 | 300 |
301 const StunByteStringAttribute* recv_data = | 301 const StunByteStringAttribute* recv_data = |
302 res->GetByteString(STUN_ATTR_DATA); | 302 res->GetByteString(STUN_ATTR_DATA); |
303 ASSERT_TRUE(recv_data != NULL); | 303 ASSERT_TRUE(recv_data != nullptr); |
304 | 304 |
305 rtc::ByteBufferReader buf(recv_data->bytes(), recv_data->length()); | 305 rtc::ByteBufferReader buf(recv_data->bytes(), recv_data->length()); |
306 std::unique_ptr<StunMessage> res2(new StunMessage()); | 306 std::unique_ptr<StunMessage> res2(new StunMessage()); |
307 EXPECT_TRUE(res2->Read(&buf)); | 307 EXPECT_TRUE(res2->Read(&buf)); |
308 EXPECT_EQ(STUN_BINDING_REQUEST, res2->type()); | 308 EXPECT_EQ(STUN_BINDING_REQUEST, res2->type()); |
309 EXPECT_EQ(req->transaction_id(), res2->transaction_id()); | 309 EXPECT_EQ(req->transaction_id(), res2->transaction_id()); |
310 | 310 |
311 const StunAddressAttribute* src_addr = | 311 const StunAddressAttribute* src_addr = |
312 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); | 312 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); |
313 ASSERT_TRUE(src_addr != NULL); | 313 ASSERT_TRUE(src_addr != nullptr); |
314 EXPECT_EQ(1, src_addr->family()); | 314 EXPECT_EQ(1, src_addr->family()); |
315 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); | 315 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); |
316 EXPECT_EQ(client2_addr.port(), src_addr->port()); | 316 EXPECT_EQ(client2_addr.port(), src_addr->port()); |
317 | 317 |
318 EXPECT_TRUE(Receive2Fails()); | 318 EXPECT_TRUE(Receive2Fails()); |
319 } | 319 } |
320 | 320 |
321 // Send a complete nonsense message to the established connection and verify | 321 // Send a complete nonsense message to the established connection and verify |
322 // that it is dropped by the server. | 322 // that it is dropped by the server. |
323 TEST_F(RelayServerTest, TestRemoteBadRequest) { | 323 TEST_F(RelayServerTest, TestRemoteBadRequest) { |
(...skipping 14 matching lines...) Expand all Loading... |
338 AddMagicCookieAttr(req.get()); | 338 AddMagicCookieAttr(req.get()); |
339 | 339 |
340 Send1(req.get()); | 340 Send1(req.get()); |
341 res.reset(Receive1()); | 341 res.reset(Receive1()); |
342 | 342 |
343 ASSERT_TRUE(res); | 343 ASSERT_TRUE(res); |
344 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 344 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
345 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 345 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
346 | 346 |
347 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 347 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
348 ASSERT_TRUE(err != NULL); | 348 ASSERT_TRUE(err != nullptr); |
349 EXPECT_EQ(4, err->eclass()); | 349 EXPECT_EQ(4, err->eclass()); |
350 EXPECT_EQ(32, err->number()); | 350 EXPECT_EQ(32, err->number()); |
351 EXPECT_EQ("Missing Username", err->reason()); | 351 EXPECT_EQ("Missing Username", err->reason()); |
352 } | 352 } |
353 | 353 |
354 // Send a send request with the wrong username and verify it is rejected. | 354 // Send a send request with the wrong username and verify it is rejected. |
355 TEST_F(RelayServerTest, TestSendRequestBadUsername) { | 355 TEST_F(RelayServerTest, TestSendRequestBadUsername) { |
356 Allocate(); | 356 Allocate(); |
357 Bind(); | 357 Bind(); |
358 | 358 |
359 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 359 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
360 AddMagicCookieAttr(req.get()); | 360 AddMagicCookieAttr(req.get()); |
361 AddUsernameAttr(req.get(), "foobarbizbaz"); | 361 AddUsernameAttr(req.get(), "foobarbizbaz"); |
362 | 362 |
363 Send1(req.get()); | 363 Send1(req.get()); |
364 res.reset(Receive1()); | 364 res.reset(Receive1()); |
365 | 365 |
366 ASSERT_TRUE(res); | 366 ASSERT_TRUE(res); |
367 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 367 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
368 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 368 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
369 | 369 |
370 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 370 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
371 ASSERT_TRUE(err != NULL); | 371 ASSERT_TRUE(err != nullptr); |
372 EXPECT_EQ(4, err->eclass()); | 372 EXPECT_EQ(4, err->eclass()); |
373 EXPECT_EQ(30, err->number()); | 373 EXPECT_EQ(30, err->number()); |
374 EXPECT_EQ("Stale Credentials", err->reason()); | 374 EXPECT_EQ("Stale Credentials", err->reason()); |
375 } | 375 } |
376 | 376 |
377 // Send a send request without a destination address and verify that it is | 377 // Send a send request without a destination address and verify that it is |
378 // rejected. | 378 // rejected. |
379 TEST_F(RelayServerTest, TestSendRequestNoDestinationAddress) { | 379 TEST_F(RelayServerTest, TestSendRequestNoDestinationAddress) { |
380 Allocate(); | 380 Allocate(); |
381 Bind(); | 381 Bind(); |
382 | 382 |
383 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 383 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
384 AddMagicCookieAttr(req.get()); | 384 AddMagicCookieAttr(req.get()); |
385 AddUsernameAttr(req.get(), username_); | 385 AddUsernameAttr(req.get(), username_); |
386 | 386 |
387 Send1(req.get()); | 387 Send1(req.get()); |
388 res.reset(Receive1()); | 388 res.reset(Receive1()); |
389 | 389 |
390 ASSERT_TRUE(res); | 390 ASSERT_TRUE(res); |
391 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 391 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
392 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 392 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
393 | 393 |
394 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 394 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
395 ASSERT_TRUE(err != NULL); | 395 ASSERT_TRUE(err != nullptr); |
396 EXPECT_EQ(4, err->eclass()); | 396 EXPECT_EQ(4, err->eclass()); |
397 EXPECT_EQ(0, err->number()); | 397 EXPECT_EQ(0, err->number()); |
398 EXPECT_EQ("Bad Request", err->reason()); | 398 EXPECT_EQ("Bad Request", err->reason()); |
399 } | 399 } |
400 | 400 |
401 // Send a send request without data and verify that it is rejected. | 401 // Send a send request without data and verify that it is rejected. |
402 TEST_F(RelayServerTest, TestSendRequestNoData) { | 402 TEST_F(RelayServerTest, TestSendRequestNoData) { |
403 Allocate(); | 403 Allocate(); |
404 Bind(); | 404 Bind(); |
405 | 405 |
406 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 406 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
407 AddMagicCookieAttr(req.get()); | 407 AddMagicCookieAttr(req.get()); |
408 AddUsernameAttr(req.get(), username_); | 408 AddUsernameAttr(req.get(), username_); |
409 AddDestinationAttr(req.get(), client2_addr); | 409 AddDestinationAttr(req.get(), client2_addr); |
410 | 410 |
411 Send1(req.get()); | 411 Send1(req.get()); |
412 res.reset(Receive1()); | 412 res.reset(Receive1()); |
413 | 413 |
414 ASSERT_TRUE(res); | 414 ASSERT_TRUE(res); |
415 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 415 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
416 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 416 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
417 | 417 |
418 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 418 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
419 ASSERT_TRUE(err != NULL); | 419 ASSERT_TRUE(err != nullptr); |
420 EXPECT_EQ(4, err->eclass()); | 420 EXPECT_EQ(4, err->eclass()); |
421 EXPECT_EQ(00, err->number()); | 421 EXPECT_EQ(00, err->number()); |
422 EXPECT_EQ("Bad Request", err->reason()); | 422 EXPECT_EQ("Bad Request", err->reason()); |
423 } | 423 } |
424 | 424 |
425 // Send a binding request after an allocate and verify that it is rejected. | 425 // Send a binding request after an allocate and verify that it is rejected. |
426 TEST_F(RelayServerTest, TestSendRequestWrongType) { | 426 TEST_F(RelayServerTest, TestSendRequestWrongType) { |
427 Allocate(); | 427 Allocate(); |
428 Bind(); | 428 Bind(); |
429 | 429 |
430 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), | 430 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_BINDING_REQUEST)), |
431 res; | 431 res; |
432 AddMagicCookieAttr(req.get()); | 432 AddMagicCookieAttr(req.get()); |
433 AddUsernameAttr(req.get(), username_); | 433 AddUsernameAttr(req.get(), username_); |
434 | 434 |
435 Send1(req.get()); | 435 Send1(req.get()); |
436 res.reset(Receive1()); | 436 res.reset(Receive1()); |
437 | 437 |
438 ASSERT_TRUE(res); | 438 ASSERT_TRUE(res); |
439 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, res->type()); | 439 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, res->type()); |
440 EXPECT_EQ(req->transaction_id(), res->transaction_id()); | 440 EXPECT_EQ(req->transaction_id(), res->transaction_id()); |
441 | 441 |
442 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 442 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
443 ASSERT_TRUE(err != NULL); | 443 ASSERT_TRUE(err != nullptr); |
444 EXPECT_EQ(6, err->eclass()); | 444 EXPECT_EQ(6, err->eclass()); |
445 EXPECT_EQ(0, err->number()); | 445 EXPECT_EQ(0, err->number()); |
446 EXPECT_EQ("Operation Not Supported", err->reason()); | 446 EXPECT_EQ("Operation Not Supported", err->reason()); |
447 } | 447 } |
448 | 448 |
449 // Verify that we can send traffic back and forth between the clients after a | 449 // Verify that we can send traffic back and forth between the clients after a |
450 // successful allocate and bind. | 450 // successful allocate and bind. |
451 TEST_F(RelayServerTest, TestSendRaw) { | 451 TEST_F(RelayServerTest, TestSendRaw) { |
452 Allocate(); | 452 Allocate(); |
453 Bind(); | 453 Bind(); |
(...skipping 12 matching lines...) Expand all Loading... |
466 Send1(req.get()); | 466 Send1(req.get()); |
467 EXPECT_EQ(msg1, ReceiveRaw2()); | 467 EXPECT_EQ(msg1, ReceiveRaw2()); |
468 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 468 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
469 res.reset(Receive1()); | 469 res.reset(Receive1()); |
470 | 470 |
471 ASSERT_TRUE(res); | 471 ASSERT_TRUE(res); |
472 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); | 472 EXPECT_EQ(STUN_DATA_INDICATION, res->type()); |
473 | 473 |
474 const StunAddressAttribute* src_addr = | 474 const StunAddressAttribute* src_addr = |
475 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); | 475 res->GetAddress(STUN_ATTR_SOURCE_ADDRESS2); |
476 ASSERT_TRUE(src_addr != NULL); | 476 ASSERT_TRUE(src_addr != nullptr); |
477 EXPECT_EQ(1, src_addr->family()); | 477 EXPECT_EQ(1, src_addr->family()); |
478 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); | 478 EXPECT_EQ(client2_addr.ipaddr(), src_addr->ipaddr()); |
479 EXPECT_EQ(client2_addr.port(), src_addr->port()); | 479 EXPECT_EQ(client2_addr.port(), src_addr->port()); |
480 | 480 |
481 const StunByteStringAttribute* recv_data = | 481 const StunByteStringAttribute* recv_data = |
482 res->GetByteString(STUN_ATTR_DATA); | 482 res->GetByteString(STUN_ATTR_DATA); |
483 ASSERT_TRUE(recv_data != NULL); | 483 ASSERT_TRUE(recv_data != nullptr); |
484 EXPECT_EQ(strlen(msg2), recv_data->length()); | 484 EXPECT_EQ(strlen(msg2), recv_data->length()); |
485 EXPECT_EQ(0, memcmp(msg2, recv_data->bytes(), recv_data->length())); | 485 EXPECT_EQ(0, memcmp(msg2, recv_data->bytes(), recv_data->length())); |
486 } | 486 } |
487 } | 487 } |
488 | 488 |
489 // Verify that a binding expires properly, and rejects send requests. | 489 // Verify that a binding expires properly, and rejects send requests. |
490 // Flaky, see https://code.google.com/p/webrtc/issues/detail?id=4134 | 490 // Flaky, see https://code.google.com/p/webrtc/issues/detail?id=4134 |
491 TEST_F(RelayServerTest, DISABLED_TestExpiration) { | 491 TEST_F(RelayServerTest, DISABLED_TestExpiration) { |
492 Allocate(); | 492 Allocate(); |
493 Bind(); | 493 Bind(); |
494 | 494 |
495 // Wait twice the lifetime to make sure the server has expired the binding. | 495 // Wait twice the lifetime to make sure the server has expired the binding. |
496 rtc::Thread::Current()->ProcessMessages((LIFETIME * 2) * 1000); | 496 rtc::Thread::Current()->ProcessMessages((LIFETIME * 2) * 1000); |
497 | 497 |
498 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; | 498 std::unique_ptr<StunMessage> req(CreateStunMessage(STUN_SEND_REQUEST)), res; |
499 AddMagicCookieAttr(req.get()); | 499 AddMagicCookieAttr(req.get()); |
500 AddUsernameAttr(req.get(), username_); | 500 AddUsernameAttr(req.get(), username_); |
501 AddDestinationAttr(req.get(), client2_addr); | 501 AddDestinationAttr(req.get(), client2_addr); |
502 | 502 |
503 StunByteStringAttribute* data_attr = | 503 StunByteStringAttribute* data_attr = |
504 StunAttribute::CreateByteString(STUN_ATTR_DATA); | 504 StunAttribute::CreateByteString(STUN_ATTR_DATA); |
505 data_attr->CopyBytes(msg1); | 505 data_attr->CopyBytes(msg1); |
506 req->AddAttribute(data_attr); | 506 req->AddAttribute(data_attr); |
507 | 507 |
508 Send1(req.get()); | 508 Send1(req.get()); |
509 res.reset(Receive1()); | 509 res.reset(Receive1()); |
510 | 510 |
511 ASSERT_TRUE(res.get() != NULL); | 511 ASSERT_TRUE(res.get() != nullptr); |
512 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); | 512 EXPECT_EQ(STUN_SEND_ERROR_RESPONSE, res->type()); |
513 | 513 |
514 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 514 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
515 ASSERT_TRUE(err != NULL); | 515 ASSERT_TRUE(err != nullptr); |
516 EXPECT_EQ(6, err->eclass()); | 516 EXPECT_EQ(6, err->eclass()); |
517 EXPECT_EQ(0, err->number()); | 517 EXPECT_EQ(0, err->number()); |
518 EXPECT_EQ("Operation Not Supported", err->reason()); | 518 EXPECT_EQ("Operation Not Supported", err->reason()); |
519 | 519 |
520 // Also verify that traffic from the external client is ignored. | 520 // Also verify that traffic from the external client is ignored. |
521 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 521 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
522 EXPECT_TRUE(ReceiveRaw1().empty()); | 522 EXPECT_TRUE(ReceiveRaw1().empty()); |
523 } | 523 } |
OLD | NEW |