| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
| 58 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | 58 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
| 59 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); | 59 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", STUN_SERVER_PORT); |
| 60 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 60 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
| 61 static const RelayCredentials kRelayCredentials("test", "test"); | 61 static const RelayCredentials kRelayCredentials("test", "test"); |
| 62 | 62 |
| 63 // TODO: Update these when RFC5245 is completely supported. | 63 // TODO: Update these when RFC5245 is completely supported. |
| 64 // Magic value of 30 is from RFC3484, for IPv4 addresses. | 64 // Magic value of 30 is from RFC3484, for IPv4 addresses. |
| 65 static const uint32 kDefaultPrflxPriority = ICE_TYPE_PREFERENCE_PRFLX << 24 | | 65 static const uint32 kDefaultPrflxPriority = ICE_TYPE_PREFERENCE_PRFLX << 24 | |
| 66 30 << 8 | (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); | 66 30 << 8 | (256 - ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 67 static const int STUN_ERROR_BAD_REQUEST_AS_GICE = | |
| 68 STUN_ERROR_BAD_REQUEST / 256 * 100 + STUN_ERROR_BAD_REQUEST % 256; | |
| 69 static const int STUN_ERROR_UNAUTHORIZED_AS_GICE = | |
| 70 STUN_ERROR_UNAUTHORIZED / 256 * 100 + STUN_ERROR_UNAUTHORIZED % 256; | |
| 71 static const int STUN_ERROR_SERVER_ERROR_AS_GICE = | |
| 72 STUN_ERROR_SERVER_ERROR / 256 * 100 + STUN_ERROR_SERVER_ERROR % 256; | |
| 73 | 67 |
| 74 static const int kTiebreaker1 = 11111; | 68 static const int kTiebreaker1 = 11111; |
| 75 static const int kTiebreaker2 = 22222; | 69 static const int kTiebreaker2 = 22222; |
| 76 | 70 |
| 77 static const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | 71 static const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; |
| 78 | 72 |
| 79 static Candidate GetCandidate(Port* port) { | 73 static Candidate GetCandidate(Port* port) { |
| 80 assert(port->Candidates().size() == 1); | 74 assert(port->Candidates().size() == 1); |
| 81 return port->Candidates()[0]; | 75 return port->Candidates()[0]; |
| 82 } | 76 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 } | 267 } |
| 274 | 268 |
| 275 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, | 269 void OnUnknownAddress(PortInterface* port, const SocketAddress& addr, |
| 276 ProtocolType proto, | 270 ProtocolType proto, |
| 277 IceMessage* msg, const std::string& rf, | 271 IceMessage* msg, const std::string& rf, |
| 278 bool /*port_muxed*/) { | 272 bool /*port_muxed*/) { |
| 279 ASSERT_EQ(src_.get(), port); | 273 ASSERT_EQ(src_.get(), port); |
| 280 if (!remote_address_.IsNil()) { | 274 if (!remote_address_.IsNil()) { |
| 281 ASSERT_EQ(remote_address_, addr); | 275 ASSERT_EQ(remote_address_, addr); |
| 282 } | 276 } |
| 283 // MI and PRIORITY attribute should be present in ping requests when port | |
| 284 // is in ICEPROTO_RFC5245 mode. | |
| 285 const cricket::StunUInt32Attribute* priority_attr = | 277 const cricket::StunUInt32Attribute* priority_attr = |
| 286 msg->GetUInt32(STUN_ATTR_PRIORITY); | 278 msg->GetUInt32(STUN_ATTR_PRIORITY); |
| 287 const cricket::StunByteStringAttribute* mi_attr = | 279 const cricket::StunByteStringAttribute* mi_attr = |
| 288 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); | 280 msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY); |
| 289 const cricket::StunUInt32Attribute* fingerprint_attr = | 281 const cricket::StunUInt32Attribute* fingerprint_attr = |
| 290 msg->GetUInt32(STUN_ATTR_FINGERPRINT); | 282 msg->GetUInt32(STUN_ATTR_FINGERPRINT); |
| 291 if (src_->IceProtocol() == cricket::ICEPROTO_RFC5245) { | 283 EXPECT_TRUE(priority_attr != NULL); |
| 292 EXPECT_TRUE(priority_attr != NULL); | 284 EXPECT_TRUE(mi_attr != NULL); |
| 293 EXPECT_TRUE(mi_attr != NULL); | 285 EXPECT_TRUE(fingerprint_attr != NULL); |
| 294 EXPECT_TRUE(fingerprint_attr != NULL); | |
| 295 } else { | |
| 296 EXPECT_TRUE(priority_attr == NULL); | |
| 297 EXPECT_TRUE(mi_attr == NULL); | |
| 298 EXPECT_TRUE(fingerprint_attr == NULL); | |
| 299 } | |
| 300 remote_address_ = addr; | 286 remote_address_ = addr; |
| 301 remote_request_.reset(CopyStunMessage(msg)); | 287 remote_request_.reset(CopyStunMessage(msg)); |
| 302 remote_frag_ = rf; | 288 remote_frag_ = rf; |
| 303 } | 289 } |
| 304 | 290 |
| 305 void OnDestroyed(Connection* conn) { | 291 void OnDestroyed(Connection* conn) { |
| 306 ASSERT_EQ(conn_, conn); | 292 ASSERT_EQ(conn_, conn); |
| 307 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; | 293 LOG(INFO) << "OnDestroy connection " << conn << " deleted"; |
| 308 conn_ = NULL; | 294 conn_ = NULL; |
| 309 // When the connection is destroyed, also clear these fields so future | 295 // When the connection is destroyed, also clear these fields so future |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 337 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 352 relay_server_(main_, | 338 relay_server_(main_, |
| 353 kRelayUdpIntAddr, | 339 kRelayUdpIntAddr, |
| 354 kRelayUdpExtAddr, | 340 kRelayUdpExtAddr, |
| 355 kRelayTcpIntAddr, | 341 kRelayTcpIntAddr, |
| 356 kRelayTcpExtAddr, | 342 kRelayTcpExtAddr, |
| 357 kRelaySslTcpIntAddr, | 343 kRelaySslTcpIntAddr, |
| 358 kRelaySslTcpExtAddr), | 344 kRelaySslTcpExtAddr), |
| 359 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), | 345 username_(rtc::CreateRandomString(ICE_UFRAG_LENGTH)), |
| 360 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), | 346 password_(rtc::CreateRandomString(ICE_PWD_LENGTH)), |
| 361 ice_protocol_(cricket::ICEPROTO_GOOGLE), | |
| 362 role_conflict_(false), | 347 role_conflict_(false), |
| 363 destroyed_(false) { | 348 destroyed_(false) { |
| 364 network_.AddIP(rtc::IPAddress(INADDR_ANY)); | 349 network_.AddIP(rtc::IPAddress(INADDR_ANY)); |
| 365 } | 350 } |
| 366 | 351 |
| 367 protected: | 352 protected: |
| 368 void TestLocalToLocal() { | 353 void TestLocalToLocal() { |
| 369 Port* port1 = CreateUdpPort(kLocalAddr1); | 354 Port* port1 = CreateUdpPort(kLocalAddr1); |
| 370 Port* port2 = CreateUdpPort(kLocalAddr2); | 355 Port* port2 = CreateUdpPort(kLocalAddr2); |
| 371 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 356 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); | 409 Port* port2 = CreateRelayPort(kLocalAddr2, rtype, proto, PROTO_SSLTCP); |
| 425 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, | 410 TestConnectivity("ssltcp", port1, RelayName(rtype, proto), port2, |
| 426 rtype == RELAY_GTURN, false, true, true); | 411 rtype == RELAY_GTURN, false, true, true); |
| 427 } | 412 } |
| 428 // helpers for above functions | 413 // helpers for above functions |
| 429 UDPPort* CreateUdpPort(const SocketAddress& addr) { | 414 UDPPort* CreateUdpPort(const SocketAddress& addr) { |
| 430 return CreateUdpPort(addr, &socket_factory_); | 415 return CreateUdpPort(addr, &socket_factory_); |
| 431 } | 416 } |
| 432 UDPPort* CreateUdpPort(const SocketAddress& addr, | 417 UDPPort* CreateUdpPort(const SocketAddress& addr, |
| 433 PacketSocketFactory* socket_factory) { | 418 PacketSocketFactory* socket_factory) { |
| 434 UDPPort* port = UDPPort::Create(main_, socket_factory, &network_, | 419 return UDPPort::Create(main_, socket_factory, &network_, |
| 435 addr.ipaddr(), 0, 0, username_, password_, | 420 addr.ipaddr(), 0, 0, username_, password_, |
| 436 std::string()); | 421 std::string()); |
| 437 port->SetIceProtocolType(ice_protocol_); | |
| 438 return port; | |
| 439 } | 422 } |
| 440 TCPPort* CreateTcpPort(const SocketAddress& addr) { | 423 TCPPort* CreateTcpPort(const SocketAddress& addr) { |
| 441 TCPPort* port = CreateTcpPort(addr, &socket_factory_); | 424 return CreateTcpPort(addr, &socket_factory_); |
| 442 port->SetIceProtocolType(ice_protocol_); | |
| 443 return port; | |
| 444 } | 425 } |
| 445 TCPPort* CreateTcpPort(const SocketAddress& addr, | 426 TCPPort* CreateTcpPort(const SocketAddress& addr, |
| 446 PacketSocketFactory* socket_factory) { | 427 PacketSocketFactory* socket_factory) { |
| 447 TCPPort* port = TCPPort::Create(main_, socket_factory, &network_, | 428 return TCPPort::Create(main_, socket_factory, &network_, |
| 448 addr.ipaddr(), 0, 0, username_, password_, | 429 addr.ipaddr(), 0, 0, username_, password_, |
| 449 true); | 430 true); |
| 450 port->SetIceProtocolType(ice_protocol_); | |
| 451 return port; | |
| 452 } | 431 } |
| 453 StunPort* CreateStunPort(const SocketAddress& addr, | 432 StunPort* CreateStunPort(const SocketAddress& addr, |
| 454 rtc::PacketSocketFactory* factory) { | 433 rtc::PacketSocketFactory* factory) { |
| 455 ServerAddresses stun_servers; | 434 ServerAddresses stun_servers; |
| 456 stun_servers.insert(kStunAddr); | 435 stun_servers.insert(kStunAddr); |
| 457 StunPort* port = StunPort::Create(main_, factory, &network_, | 436 return StunPort::Create(main_, factory, &network_, |
| 458 addr.ipaddr(), 0, 0, | 437 addr.ipaddr(), 0, 0, |
| 459 username_, password_, stun_servers, | 438 username_, password_, stun_servers, |
| 460 std::string()); | 439 std::string()); |
| 461 port->SetIceProtocolType(ice_protocol_); | |
| 462 return port; | |
| 463 } | 440 } |
| 464 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, | 441 Port* CreateRelayPort(const SocketAddress& addr, RelayType rtype, |
| 465 ProtocolType int_proto, ProtocolType ext_proto) { | 442 ProtocolType int_proto, ProtocolType ext_proto) { |
| 466 if (rtype == RELAY_TURN) { | 443 if (rtype == RELAY_TURN) { |
| 467 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); | 444 return CreateTurnPort(addr, &socket_factory_, int_proto, ext_proto); |
| 468 } else { | 445 } else { |
| 469 return CreateGturnPort(addr, int_proto, ext_proto); | 446 return CreateGturnPort(addr, int_proto, ext_proto); |
| 470 } | 447 } |
| 471 } | 448 } |
| 472 TurnPort* CreateTurnPort(const SocketAddress& addr, | 449 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 473 PacketSocketFactory* socket_factory, | 450 PacketSocketFactory* socket_factory, |
| 474 ProtocolType int_proto, ProtocolType ext_proto) { | 451 ProtocolType int_proto, ProtocolType ext_proto) { |
| 475 return CreateTurnPort(addr, socket_factory, | 452 return CreateTurnPort(addr, socket_factory, |
| 476 int_proto, ext_proto, kTurnUdpIntAddr); | 453 int_proto, ext_proto, kTurnUdpIntAddr); |
| 477 } | 454 } |
| 478 TurnPort* CreateTurnPort(const SocketAddress& addr, | 455 TurnPort* CreateTurnPort(const SocketAddress& addr, |
| 479 PacketSocketFactory* socket_factory, | 456 PacketSocketFactory* socket_factory, |
| 480 ProtocolType int_proto, ProtocolType ext_proto, | 457 ProtocolType int_proto, ProtocolType ext_proto, |
| 481 const rtc::SocketAddress& server_addr) { | 458 const rtc::SocketAddress& server_addr) { |
| 482 TurnPort* port = TurnPort::Create(main_, socket_factory, &network_, | 459 return TurnPort::Create(main_, socket_factory, &network_, |
| 483 addr.ipaddr(), 0, 0, | 460 addr.ipaddr(), 0, 0, |
| 484 username_, password_, ProtocolAddress( | 461 username_, password_, ProtocolAddress( |
| 485 server_addr, PROTO_UDP), | 462 server_addr, PROTO_UDP), |
| 486 kRelayCredentials, 0, | 463 kRelayCredentials, 0, |
| 487 std::string()); | 464 std::string()); |
| 488 port->SetIceProtocolType(ice_protocol_); | |
| 489 return port; | |
| 490 } | 465 } |
| 491 RelayPort* CreateGturnPort(const SocketAddress& addr, | 466 RelayPort* CreateGturnPort(const SocketAddress& addr, |
| 492 ProtocolType int_proto, ProtocolType ext_proto) { | 467 ProtocolType int_proto, ProtocolType ext_proto) { |
| 493 RelayPort* port = CreateGturnPort(addr); | 468 RelayPort* port = CreateGturnPort(addr); |
| 494 SocketAddress addrs[] = | 469 SocketAddress addrs[] = |
| 495 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; | 470 { kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr }; |
| 496 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); | 471 port->AddServerAddress(ProtocolAddress(addrs[int_proto], int_proto)); |
| 497 return port; | 472 return port; |
| 498 } | 473 } |
| 499 RelayPort* CreateGturnPort(const SocketAddress& addr) { | 474 RelayPort* CreateGturnPort(const SocketAddress& addr) { |
| 500 RelayPort* port = RelayPort::Create(main_, &socket_factory_, &network_, | 475 // TODO(pthatcher): Remove GTURN. |
| 501 addr.ipaddr(), 0, 0, | 476 return RelayPort::Create(main_, &socket_factory_, &network_, |
| 502 username_, password_); | 477 addr.ipaddr(), 0, 0, |
| 478 username_, password_); |
| 503 // TODO: Add an external address for ext_proto, so that the | 479 // TODO: Add an external address for ext_proto, so that the |
| 504 // other side can connect to this port using a non-UDP protocol. | 480 // other side can connect to this port using a non-UDP protocol. |
| 505 port->SetIceProtocolType(ice_protocol_); | |
| 506 return port; | |
| 507 } | 481 } |
| 508 rtc::NATServer* CreateNatServer(const SocketAddress& addr, | 482 rtc::NATServer* CreateNatServer(const SocketAddress& addr, |
| 509 rtc::NATType type) { | 483 rtc::NATType type) { |
| 510 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); | 484 return new rtc::NATServer(type, ss_.get(), addr, addr, ss_.get(), addr); |
| 511 } | 485 } |
| 512 static const char* StunName(NATType type) { | 486 static const char* StunName(NATType type) { |
| 513 switch (type) { | 487 switch (type) { |
| 514 case NAT_OPEN_CONE: return "stun(open cone)"; | 488 case NAT_OPEN_CONE: return "stun(open cone)"; |
| 515 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; | 489 case NAT_ADDR_RESTRICTED: return "stun(addr restricted)"; |
| 516 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; | 490 case NAT_PORT_RESTRICTED: return "stun(port restricted)"; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 kTcpReconnectTimeout + kTimeout); | 625 kTcpReconnectTimeout + kTimeout); |
| 652 } | 626 } |
| 653 | 627 |
| 654 // Tear down and ensure that goes smoothly. | 628 // Tear down and ensure that goes smoothly. |
| 655 ch1.Stop(); | 629 ch1.Stop(); |
| 656 ch2.Stop(); | 630 ch2.Stop(); |
| 657 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); | 631 EXPECT_TRUE_WAIT(ch1.conn() == NULL, kTimeout); |
| 658 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); | 632 EXPECT_TRUE_WAIT(ch2.conn() == NULL, kTimeout); |
| 659 } | 633 } |
| 660 | 634 |
| 661 void SetIceProtocolType(cricket::IceProtocolType protocol) { | |
| 662 ice_protocol_ = protocol; | |
| 663 } | |
| 664 | |
| 665 IceMessage* CreateStunMessage(int type) { | 635 IceMessage* CreateStunMessage(int type) { |
| 666 IceMessage* msg = new IceMessage(); | 636 IceMessage* msg = new IceMessage(); |
| 667 msg->SetType(type); | 637 msg->SetType(type); |
| 668 msg->SetTransactionID("TESTTESTTEST"); | 638 msg->SetTransactionID("TESTTESTTEST"); |
| 669 return msg; | 639 return msg; |
| 670 } | 640 } |
| 671 IceMessage* CreateStunMessageWithUsername(int type, | 641 IceMessage* CreateStunMessageWithUsername(int type, |
| 672 const std::string& username) { | 642 const std::string& username) { |
| 673 IceMessage* msg = CreateStunMessage(type); | 643 IceMessage* msg = CreateStunMessage(type); |
| 674 msg->AddAttribute( | 644 msg->AddAttribute( |
| 675 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); | 645 new StunByteStringAttribute(STUN_ATTR_USERNAME, username)); |
| 676 return msg; | 646 return msg; |
| 677 } | 647 } |
| 678 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 648 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
| 679 const std::string& username, | 649 const std::string& username, |
| 680 const std::string& password) { | 650 const std::string& password) { |
| 681 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, | 651 TestPort* port = new TestPort(main_, "test", &socket_factory_, &network_, |
| 682 addr.ipaddr(), 0, 0, username, password); | 652 addr.ipaddr(), 0, 0, username, password); |
| 683 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); | 653 port->SignalRoleConflict.connect(this, &PortTest::OnRoleConflict); |
| 684 return port; | 654 return port; |
| 685 } | 655 } |
| 686 TestPort* CreateTestPort(const rtc::SocketAddress& addr, | 656 TestPort* CreateTestPort(const rtc::SocketAddress& addr, |
| 687 const std::string& username, | 657 const std::string& username, |
| 688 const std::string& password, | 658 const std::string& password, |
| 689 cricket::IceProtocolType type, | |
| 690 cricket::IceRole role, | 659 cricket::IceRole role, |
| 691 int tiebreaker) { | 660 int tiebreaker) { |
| 692 TestPort* port = CreateTestPort(addr, username, password); | 661 TestPort* port = CreateTestPort(addr, username, password); |
| 693 port->SetIceProtocolType(type); | |
| 694 port->SetIceRole(role); | 662 port->SetIceRole(role); |
| 695 port->SetIceTiebreaker(tiebreaker); | 663 port->SetIceTiebreaker(tiebreaker); |
| 696 return port; | 664 return port; |
| 697 } | 665 } |
| 698 | 666 |
| 699 void OnRoleConflict(PortInterface* port) { | 667 void OnRoleConflict(PortInterface* port) { |
| 700 role_conflict_ = true; | 668 role_conflict_ = true; |
| 701 } | 669 } |
| 702 bool role_conflict() const { return role_conflict_; } | 670 bool role_conflict() const { return role_conflict_; } |
| 703 | 671 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 725 rtc::scoped_ptr<rtc::NATServer> nat_server2_; | 693 rtc::scoped_ptr<rtc::NATServer> nat_server2_; |
| 726 rtc::NATSocketFactory nat_factory1_; | 694 rtc::NATSocketFactory nat_factory1_; |
| 727 rtc::NATSocketFactory nat_factory2_; | 695 rtc::NATSocketFactory nat_factory2_; |
| 728 rtc::BasicPacketSocketFactory nat_socket_factory1_; | 696 rtc::BasicPacketSocketFactory nat_socket_factory1_; |
| 729 rtc::BasicPacketSocketFactory nat_socket_factory2_; | 697 rtc::BasicPacketSocketFactory nat_socket_factory2_; |
| 730 scoped_ptr<TestStunServer> stun_server_; | 698 scoped_ptr<TestStunServer> stun_server_; |
| 731 TestTurnServer turn_server_; | 699 TestTurnServer turn_server_; |
| 732 TestRelayServer relay_server_; | 700 TestRelayServer relay_server_; |
| 733 std::string username_; | 701 std::string username_; |
| 734 std::string password_; | 702 std::string password_; |
| 735 cricket::IceProtocolType ice_protocol_; | |
| 736 bool role_conflict_; | 703 bool role_conflict_; |
| 737 bool destroyed_; | 704 bool destroyed_; |
| 738 }; | 705 }; |
| 739 | 706 |
| 740 void PortTest::TestConnectivity(const char* name1, Port* port1, | 707 void PortTest::TestConnectivity(const char* name1, Port* port1, |
| 741 const char* name2, Port* port2, | 708 const char* name2, Port* port2, |
| 742 bool accept, bool same_addr1, | 709 bool accept, bool same_addr1, |
| 743 bool same_addr2, bool possible) { | 710 bool same_addr2, bool possible) { |
| 744 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; | 711 LOG(LS_INFO) << "Test: " << name1 << " to " << name2 << ": "; |
| 745 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 712 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 } | 1140 } |
| 1174 | 1141 |
| 1175 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { | 1142 TEST_F(PortTest, TestSslTcpToSslTcpRelay) { |
| 1176 TestSslTcpToRelay(PROTO_SSLTCP); | 1143 TestSslTcpToRelay(PROTO_SSLTCP); |
| 1177 } | 1144 } |
| 1178 */ | 1145 */ |
| 1179 | 1146 |
| 1180 // This test case verifies standard ICE features in STUN messages. Currently it | 1147 // This test case verifies standard ICE features in STUN messages. Currently it |
| 1181 // verifies Message Integrity attribute in STUN messages and username in STUN | 1148 // verifies Message Integrity attribute in STUN messages and username in STUN |
| 1182 // binding request will have colon (":") between remote and local username. | 1149 // binding request will have colon (":") between remote and local username. |
| 1183 TEST_F(PortTest, TestLocalToLocalAsIce) { | 1150 TEST_F(PortTest, TestLocalToLocalStandard) { |
| 1184 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
| 1185 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 1151 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 1186 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1152 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1187 port1->SetIceTiebreaker(kTiebreaker1); | 1153 port1->SetIceTiebreaker(kTiebreaker1); |
| 1188 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port1->IceProtocol()); | |
| 1189 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 1154 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 1190 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1155 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1191 port2->SetIceTiebreaker(kTiebreaker2); | 1156 port2->SetIceTiebreaker(kTiebreaker2); |
| 1192 ASSERT_EQ(cricket::ICEPROTO_RFC5245, port2->IceProtocol()); | |
| 1193 // Same parameters as TestLocalToLocal above. | 1157 // Same parameters as TestLocalToLocal above. |
| 1194 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); | 1158 TestConnectivity("udp", port1, "udp", port2, true, true, true, true); |
| 1195 } | 1159 } |
| 1196 | 1160 |
| 1197 // This test is trying to validate a successful and failure scenario in a | 1161 // This test is trying to validate a successful and failure scenario in a |
| 1198 // loopback test when protocol is RFC5245. For success IceTiebreaker, username | 1162 // loopback test when protocol is RFC5245. For success IceTiebreaker, username |
| 1199 // should remain equal to the request generated by the port and role of port | 1163 // should remain equal to the request generated by the port and role of port |
| 1200 // must be in controlling. | 1164 // must be in controlling. |
| 1201 TEST_F(PortTest, TestLoopbackCallAsIce) { | 1165 TEST_F(PortTest, TestLoopbackCal) { |
| 1202 rtc::scoped_ptr<TestPort> lport( | 1166 rtc::scoped_ptr<TestPort> lport( |
| 1203 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1167 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1204 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1205 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1168 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1206 lport->SetIceTiebreaker(kTiebreaker1); | 1169 lport->SetIceTiebreaker(kTiebreaker1); |
| 1207 lport->PrepareAddress(); | 1170 lport->PrepareAddress(); |
| 1208 ASSERT_FALSE(lport->Candidates().empty()); | 1171 ASSERT_FALSE(lport->Candidates().empty()); |
| 1209 Connection* conn = lport->CreateConnection(lport->Candidates()[0], | 1172 Connection* conn = lport->CreateConnection(lport->Candidates()[0], |
| 1210 Port::ORIGIN_MESSAGE); | 1173 Port::ORIGIN_MESSAGE); |
| 1211 conn->Ping(0); | 1174 conn->Ping(0); |
| 1212 | 1175 |
| 1213 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1176 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1214 IceMessage* msg = lport->last_stun_msg(); | 1177 IceMessage* msg = lport->last_stun_msg(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 } | 1218 } |
| 1256 | 1219 |
| 1257 // This test verifies role conflict signal is received when there is | 1220 // This test verifies role conflict signal is received when there is |
| 1258 // conflict in the role. In this case both ports are in controlling and | 1221 // conflict in the role. In this case both ports are in controlling and |
| 1259 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower | 1222 // |rport| has higher tiebreaker value than |lport|. Since |lport| has lower |
| 1260 // value of tiebreaker, when it receives ping request from |rport| it will | 1223 // value of tiebreaker, when it receives ping request from |rport| it will |
| 1261 // send role conflict signal. | 1224 // send role conflict signal. |
| 1262 TEST_F(PortTest, TestIceRoleConflict) { | 1225 TEST_F(PortTest, TestIceRoleConflict) { |
| 1263 rtc::scoped_ptr<TestPort> lport( | 1226 rtc::scoped_ptr<TestPort> lport( |
| 1264 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1227 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1265 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1266 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1228 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1267 lport->SetIceTiebreaker(kTiebreaker1); | 1229 lport->SetIceTiebreaker(kTiebreaker1); |
| 1268 rtc::scoped_ptr<TestPort> rport( | 1230 rtc::scoped_ptr<TestPort> rport( |
| 1269 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1231 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1270 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1271 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1232 rport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1272 rport->SetIceTiebreaker(kTiebreaker2); | 1233 rport->SetIceTiebreaker(kTiebreaker2); |
| 1273 | 1234 |
| 1274 lport->PrepareAddress(); | 1235 lport->PrepareAddress(); |
| 1275 rport->PrepareAddress(); | 1236 rport->PrepareAddress(); |
| 1276 ASSERT_FALSE(lport->Candidates().empty()); | 1237 ASSERT_FALSE(lport->Candidates().empty()); |
| 1277 ASSERT_FALSE(rport->Candidates().empty()); | 1238 ASSERT_FALSE(rport->Candidates().empty()); |
| 1278 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1239 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
| 1279 Port::ORIGIN_MESSAGE); | 1240 Port::ORIGIN_MESSAGE); |
| 1280 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], | 1241 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 EXPECT_EQ(rtc::DSCP_CS7, dscp); | 1429 EXPECT_EQ(rtc::DSCP_CS7, dscp); |
| 1469 // This will verify correct value returned without the socket. | 1430 // This will verify correct value returned without the socket. |
| 1470 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( | 1431 rtc::scoped_ptr<TurnPort> turnport2(CreateTurnPort( |
| 1471 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 1432 kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
| 1472 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, | 1433 EXPECT_EQ(0, turnport2->SetOption(rtc::Socket::OPT_DSCP, |
| 1473 rtc::DSCP_CS6)); | 1434 rtc::DSCP_CS6)); |
| 1474 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); | 1435 EXPECT_EQ(0, turnport2->GetOption(rtc::Socket::OPT_DSCP, &dscp)); |
| 1475 EXPECT_EQ(rtc::DSCP_CS6, dscp); | 1436 EXPECT_EQ(rtc::DSCP_CS6, dscp); |
| 1476 } | 1437 } |
| 1477 | 1438 |
| 1478 // Test sending STUN messages in GICE format. | 1439 // Test sending STUN messages. |
| 1479 TEST_F(PortTest, TestSendStunMessageAsGice) { | 1440 TEST_F(PortTest, TestSendStunMessage) { |
| 1480 rtc::scoped_ptr<TestPort> lport( | 1441 rtc::scoped_ptr<TestPort> lport( |
| 1481 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1442 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1482 rtc::scoped_ptr<TestPort> rport( | 1443 rtc::scoped_ptr<TestPort> rport( |
| 1483 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1444 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1484 lport->SetIceProtocolType(ICEPROTO_GOOGLE); | |
| 1485 rport->SetIceProtocolType(ICEPROTO_GOOGLE); | |
| 1486 | |
| 1487 // Send a fake ping from lport to rport. | |
| 1488 lport->PrepareAddress(); | |
| 1489 rport->PrepareAddress(); | |
| 1490 ASSERT_FALSE(rport->Candidates().empty()); | |
| 1491 Connection* conn = lport->CreateConnection(rport->Candidates()[0], | |
| 1492 Port::ORIGIN_MESSAGE); | |
| 1493 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); | |
| 1494 conn->Ping(0); | |
| 1495 | |
| 1496 // Check that it's a proper BINDING-REQUEST. | |
| 1497 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | |
| 1498 IceMessage* msg = lport->last_stun_msg(); | |
| 1499 EXPECT_EQ(STUN_BINDING_REQUEST, msg->type()); | |
| 1500 EXPECT_FALSE(msg->IsLegacy()); | |
| 1501 const StunByteStringAttribute* username_attr = msg->GetByteString( | |
| 1502 STUN_ATTR_USERNAME); | |
| 1503 ASSERT_TRUE(username_attr != NULL); | |
| 1504 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
| 1505 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
| 1506 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
| 1507 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
| 1508 | |
| 1509 // Save a copy of the BINDING-REQUEST for use below. | |
| 1510 rtc::scoped_ptr<IceMessage> request(CopyStunMessage(msg)); | |
| 1511 | |
| 1512 // Respond with a BINDING-RESPONSE. | |
| 1513 rport->SendBindingResponse(request.get(), lport->Candidates()[0].address()); | |
| 1514 msg = rport->last_stun_msg(); | |
| 1515 ASSERT_TRUE(msg != NULL); | |
| 1516 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); | |
| 1517 EXPECT_FALSE(msg->IsLegacy()); | |
| 1518 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); | |
| 1519 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. | |
| 1520 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
| 1521 const StunAddressAttribute* addr_attr = msg->GetAddress( | |
| 1522 STUN_ATTR_MAPPED_ADDRESS); | |
| 1523 ASSERT_TRUE(addr_attr != NULL); | |
| 1524 EXPECT_EQ(lport->Candidates()[0].address(), addr_attr->GetAddress()); | |
| 1525 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_XOR_MAPPED_ADDRESS) == NULL); | |
| 1526 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
| 1527 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
| 1528 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
| 1529 | |
| 1530 // Respond with a BINDING-ERROR-RESPONSE. This wouldn't happen in real life, | |
| 1531 // but we can do it here. | |
| 1532 rport->SendBindingErrorResponse(request.get(), | |
| 1533 rport->Candidates()[0].address(), | |
| 1534 STUN_ERROR_SERVER_ERROR, | |
| 1535 STUN_ERROR_REASON_SERVER_ERROR); | |
| 1536 msg = rport->last_stun_msg(); | |
| 1537 ASSERT_TRUE(msg != NULL); | |
| 1538 EXPECT_EQ(STUN_BINDING_ERROR_RESPONSE, msg->type()); | |
| 1539 EXPECT_FALSE(msg->IsLegacy()); | |
| 1540 username_attr = msg->GetByteString(STUN_ATTR_USERNAME); | |
| 1541 ASSERT_TRUE(username_attr != NULL); // GICE has a username in the response. | |
| 1542 EXPECT_EQ("rfraglfrag", username_attr->GetString()); | |
| 1543 const StunErrorCodeAttribute* error_attr = msg->GetErrorCode(); | |
| 1544 ASSERT_TRUE(error_attr != NULL); | |
| 1545 // The GICE wire format for error codes is incorrect. | |
| 1546 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, error_attr->code()); | |
| 1547 EXPECT_EQ(STUN_ERROR_SERVER_ERROR / 256, error_attr->eclass()); | |
| 1548 EXPECT_EQ(STUN_ERROR_SERVER_ERROR % 256, error_attr->number()); | |
| 1549 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), error_attr->reason()); | |
| 1550 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_PRIORITY) == NULL); | |
| 1551 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) == NULL); | |
| 1552 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_FINGERPRINT) == NULL); | |
| 1553 } | |
| 1554 | |
| 1555 // Test sending STUN messages in ICE format. | |
| 1556 TEST_F(PortTest, TestSendStunMessageAsIce) { | |
| 1557 rtc::scoped_ptr<TestPort> lport( | |
| 1558 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | |
| 1559 rtc::scoped_ptr<TestPort> rport( | |
| 1560 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1561 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1562 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1445 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1563 lport->SetIceTiebreaker(kTiebreaker1); | 1446 lport->SetIceTiebreaker(kTiebreaker1); |
| 1564 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1565 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1447 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1566 rport->SetIceTiebreaker(kTiebreaker2); | 1448 rport->SetIceTiebreaker(kTiebreaker2); |
| 1567 | 1449 |
| 1568 // Send a fake ping from lport to rport. | 1450 // Send a fake ping from lport to rport. |
| 1569 lport->PrepareAddress(); | 1451 lport->PrepareAddress(); |
| 1570 rport->PrepareAddress(); | 1452 rport->PrepareAddress(); |
| 1571 ASSERT_FALSE(rport->Candidates().empty()); | 1453 ASSERT_FALSE(rport->Candidates().empty()); |
| 1572 Connection* lconn = lport->CreateConnection( | 1454 Connection* lconn = lport->CreateConnection( |
| 1573 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1455 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1574 Connection* rconn = rport->CreateConnection( | 1456 Connection* rconn = rport->CreateConnection( |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); | 1575 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); |
| 1694 ASSERT_TRUE(retransmit_attr != NULL); | 1576 ASSERT_TRUE(retransmit_attr != NULL); |
| 1695 EXPECT_EQ(2U, retransmit_attr->value()); | 1577 EXPECT_EQ(2U, retransmit_attr->value()); |
| 1696 } | 1578 } |
| 1697 | 1579 |
| 1698 TEST_F(PortTest, TestUseCandidateAttribute) { | 1580 TEST_F(PortTest, TestUseCandidateAttribute) { |
| 1699 rtc::scoped_ptr<TestPort> lport( | 1581 rtc::scoped_ptr<TestPort> lport( |
| 1700 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1582 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1701 rtc::scoped_ptr<TestPort> rport( | 1583 rtc::scoped_ptr<TestPort> rport( |
| 1702 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1584 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1703 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1704 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1585 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1705 lport->SetIceTiebreaker(kTiebreaker1); | 1586 lport->SetIceTiebreaker(kTiebreaker1); |
| 1706 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1707 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1587 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1708 rport->SetIceTiebreaker(kTiebreaker2); | 1588 rport->SetIceTiebreaker(kTiebreaker2); |
| 1709 | 1589 |
| 1710 // Send a fake ping from lport to rport. | 1590 // Send a fake ping from lport to rport. |
| 1711 lport->PrepareAddress(); | 1591 lport->PrepareAddress(); |
| 1712 rport->PrepareAddress(); | 1592 rport->PrepareAddress(); |
| 1713 ASSERT_FALSE(rport->Candidates().empty()); | 1593 ASSERT_FALSE(rport->Candidates().empty()); |
| 1714 Connection* lconn = lport->CreateConnection( | 1594 Connection* lconn = lport->CreateConnection( |
| 1715 rport->Candidates()[0], Port::ORIGIN_MESSAGE); | 1595 rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1716 lconn->Ping(0); | 1596 lconn->Ping(0); |
| 1717 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1597 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1718 IceMessage* msg = lport->last_stun_msg(); | 1598 IceMessage* msg = lport->last_stun_msg(); |
| 1719 const StunUInt64Attribute* ice_controlling_attr = | 1599 const StunUInt64Attribute* ice_controlling_attr = |
| 1720 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); | 1600 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); |
| 1721 ASSERT_TRUE(ice_controlling_attr != NULL); | 1601 ASSERT_TRUE(ice_controlling_attr != NULL); |
| 1722 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( | 1602 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( |
| 1723 STUN_ATTR_USE_CANDIDATE); | 1603 STUN_ATTR_USE_CANDIDATE); |
| 1724 ASSERT_TRUE(use_candidate_attr != NULL); | 1604 ASSERT_TRUE(use_candidate_attr != NULL); |
| 1725 } | 1605 } |
| 1726 | 1606 |
| 1727 // Test handling STUN messages in GICE format. | 1607 // Test handling STUN messages. |
| 1728 TEST_F(PortTest, TestHandleStunMessageAsGice) { | 1608 TEST_F(PortTest, TestHandleStunMessage) { |
| 1729 // Our port will act as the "remote" port. | 1609 // Our port will act as the "remote" port. |
| 1730 rtc::scoped_ptr<TestPort> port( | 1610 rtc::scoped_ptr<TestPort> port( |
| 1731 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1611 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1732 port->SetIceProtocolType(ICEPROTO_GOOGLE); | |
| 1733 | 1612 |
| 1734 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1613 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1735 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1614 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1736 rtc::SocketAddress addr(kLocalAddr1); | |
| 1737 std::string username; | |
| 1738 | |
| 1739 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
| 1740 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1741 "rfraglfrag")); | |
| 1742 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1743 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1744 out_msg.accept(), &username)); | |
| 1745 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. | |
| 1746 EXPECT_EQ("lfrag", username); | |
| 1747 | |
| 1748 // Add M-I; should be ignored and rest of message parsed normally. | |
| 1749 in_msg->AddMessageIntegrity("password"); | |
| 1750 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1751 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1752 out_msg.accept(), &username)); | |
| 1753 EXPECT_TRUE(out_msg.get() != NULL); | |
| 1754 EXPECT_EQ("lfrag", username); | |
| 1755 | |
| 1756 // BINDING-RESPONSE with username, as done in GICE. Should succeed. | |
| 1757 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_RESPONSE, | |
| 1758 "rfraglfrag")); | |
| 1759 in_msg->AddAttribute( | |
| 1760 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); | |
| 1761 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1762 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1763 out_msg.accept(), &username)); | |
| 1764 EXPECT_TRUE(out_msg.get() != NULL); | |
| 1765 EXPECT_EQ("", username); | |
| 1766 | |
| 1767 // BINDING-RESPONSE without username. Should be tolerated as well. | |
| 1768 in_msg.reset(CreateStunMessage(STUN_BINDING_RESPONSE)); | |
| 1769 in_msg->AddAttribute( | |
| 1770 new StunAddressAttribute(STUN_ATTR_MAPPED_ADDRESS, kLocalAddr2)); | |
| 1771 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1772 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1773 out_msg.accept(), &username)); | |
| 1774 EXPECT_TRUE(out_msg.get() != NULL); | |
| 1775 EXPECT_EQ("", username); | |
| 1776 | |
| 1777 // BINDING-ERROR-RESPONSE with username and error code. | |
| 1778 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_ERROR_RESPONSE, | |
| 1779 "rfraglfrag")); | |
| 1780 in_msg->AddAttribute(new StunErrorCodeAttribute(STUN_ATTR_ERROR_CODE, | |
| 1781 STUN_ERROR_SERVER_ERROR_AS_GICE, STUN_ERROR_REASON_SERVER_ERROR)); | |
| 1782 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1783 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1784 out_msg.accept(), &username)); | |
| 1785 ASSERT_TRUE(out_msg.get() != NULL); | |
| 1786 EXPECT_EQ("", username); | |
| 1787 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); | |
| 1788 // GetStunMessage doesn't unmunge the GICE error code (happens downstream). | |
| 1789 EXPECT_EQ(STUN_ERROR_SERVER_ERROR_AS_GICE, out_msg->GetErrorCode()->code()); | |
| 1790 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), | |
| 1791 out_msg->GetErrorCode()->reason()); | |
| 1792 } | |
| 1793 | |
| 1794 // Test handling STUN messages in ICE format. | |
| 1795 TEST_F(PortTest, TestHandleStunMessageAsIce) { | |
| 1796 // Our port will act as the "remote" port. | |
| 1797 rtc::scoped_ptr<TestPort> port( | |
| 1798 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1799 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1800 | |
| 1801 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
| 1802 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
| 1803 rtc::SocketAddress addr(kLocalAddr1); | 1615 rtc::SocketAddress addr(kLocalAddr1); |
| 1804 std::string username; | 1616 std::string username; |
| 1805 | 1617 |
| 1806 // BINDING-REQUEST from local to remote with valid ICE username, | 1618 // BINDING-REQUEST from local to remote with valid ICE username, |
| 1807 // MESSAGE-INTEGRITY, and FINGERPRINT. | 1619 // MESSAGE-INTEGRITY, and FINGERPRINT. |
| 1808 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1620 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 1809 "rfrag:lfrag")); | 1621 "rfrag:lfrag")); |
| 1810 in_msg->AddMessageIntegrity("rpass"); | 1622 in_msg->AddMessageIntegrity("rpass"); |
| 1811 in_msg->AddFingerprint(); | 1623 in_msg->AddFingerprint(); |
| 1812 WriteStunMessage(in_msg.get(), buf.get()); | 1624 WriteStunMessage(in_msg.get(), buf.get()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1836 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1648 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1837 out_msg.accept(), &username)); | 1649 out_msg.accept(), &username)); |
| 1838 EXPECT_TRUE(out_msg.get() != NULL); | 1650 EXPECT_TRUE(out_msg.get() != NULL); |
| 1839 EXPECT_EQ("", username); | 1651 EXPECT_EQ("", username); |
| 1840 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); | 1652 ASSERT_TRUE(out_msg->GetErrorCode() != NULL); |
| 1841 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); | 1653 EXPECT_EQ(STUN_ERROR_SERVER_ERROR, out_msg->GetErrorCode()->code()); |
| 1842 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), | 1654 EXPECT_EQ(std::string(STUN_ERROR_REASON_SERVER_ERROR), |
| 1843 out_msg->GetErrorCode()->reason()); | 1655 out_msg->GetErrorCode()->reason()); |
| 1844 } | 1656 } |
| 1845 | 1657 |
| 1846 // This test verifies port can handle ICE messages in Hybrid mode and switches | 1658 // Tests handling of ICE binding requests with missing or incorrect usernames. |
| 1847 // ICEPROTO_RFC5245 mode after successfully handling the message. | 1659 TEST_F(PortTest, TestHandleStunMessageBadUsername) { |
| 1848 TEST_F(PortTest, TestHandleStunMessageAsIceInHybridMode) { | |
| 1849 // Our port will act as the "remote" port. | |
| 1850 rtc::scoped_ptr<TestPort> port( | 1660 rtc::scoped_ptr<TestPort> port( |
| 1851 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1661 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1852 port->SetIceProtocolType(ICEPROTO_HYBRID); | |
| 1853 | 1662 |
| 1854 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1663 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 1855 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1664 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 1856 rtc::SocketAddress addr(kLocalAddr1); | |
| 1857 std::string username; | |
| 1858 | |
| 1859 // BINDING-REQUEST from local to remote with valid ICE username, | |
| 1860 // MESSAGE-INTEGRITY, and FINGERPRINT. | |
| 1861 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1862 "rfrag:lfrag")); | |
| 1863 in_msg->AddMessageIntegrity("rpass"); | |
| 1864 in_msg->AddFingerprint(); | |
| 1865 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1866 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1867 out_msg.accept(), &username)); | |
| 1868 EXPECT_TRUE(out_msg.get() != NULL); | |
| 1869 EXPECT_EQ("lfrag", username); | |
| 1870 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); | |
| 1871 } | |
| 1872 | |
| 1873 // This test verifies port can handle GICE messages in Hybrid mode and switches | |
| 1874 // ICEPROTO_GOOGLE mode after successfully handling the message. | |
| 1875 TEST_F(PortTest, TestHandleStunMessageAsGiceInHybridMode) { | |
| 1876 // Our port will act as the "remote" port. | |
| 1877 rtc::scoped_ptr<TestPort> port( | |
| 1878 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1879 port->SetIceProtocolType(ICEPROTO_HYBRID); | |
| 1880 | |
| 1881 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
| 1882 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
| 1883 rtc::SocketAddress addr(kLocalAddr1); | |
| 1884 std::string username; | |
| 1885 | |
| 1886 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
| 1887 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1888 "rfraglfrag")); | |
| 1889 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1890 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1891 out_msg.accept(), &username)); | |
| 1892 EXPECT_TRUE(out_msg.get() != NULL); // Succeeds, since this is GICE. | |
| 1893 EXPECT_EQ("lfrag", username); | |
| 1894 EXPECT_EQ(ICEPROTO_GOOGLE, port->IceProtocol()); | |
| 1895 } | |
| 1896 | |
| 1897 // Verify port is not switched out of RFC5245 mode if GICE message is received | |
| 1898 // in that mode. | |
| 1899 TEST_F(PortTest, TestHandleStunMessageAsGiceInIceMode) { | |
| 1900 // Our port will act as the "remote" port. | |
| 1901 rtc::scoped_ptr<TestPort> port( | |
| 1902 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1903 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1904 | |
| 1905 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
| 1906 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
| 1907 rtc::SocketAddress addr(kLocalAddr1); | |
| 1908 std::string username; | |
| 1909 | |
| 1910 // BINDING-REQUEST from local to remote with valid GICE username and no M-I. | |
| 1911 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1912 "rfraglfrag")); | |
| 1913 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1914 // Should fail as there is no MI and fingerprint. | |
| 1915 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1916 out_msg.accept(), &username)); | |
| 1917 EXPECT_EQ(ICEPROTO_RFC5245, port->IceProtocol()); | |
| 1918 } | |
| 1919 | |
| 1920 | |
| 1921 // Tests handling of GICE binding requests with missing or incorrect usernames. | |
| 1922 TEST_F(PortTest, TestHandleStunMessageAsGiceBadUsername) { | |
| 1923 rtc::scoped_ptr<TestPort> port( | |
| 1924 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1925 port->SetIceProtocolType(ICEPROTO_GOOGLE); | |
| 1926 | |
| 1927 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
| 1928 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
| 1929 rtc::SocketAddress addr(kLocalAddr1); | |
| 1930 std::string username; | |
| 1931 | |
| 1932 // BINDING-REQUEST with no username. | |
| 1933 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); | |
| 1934 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1935 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1936 out_msg.accept(), &username)); | |
| 1937 EXPECT_TRUE(out_msg.get() == NULL); | |
| 1938 EXPECT_EQ("", username); | |
| 1939 EXPECT_EQ(STUN_ERROR_BAD_REQUEST_AS_GICE, port->last_stun_error_code()); | |
| 1940 | |
| 1941 // BINDING-REQUEST with empty username. | |
| 1942 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "")); | |
| 1943 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1944 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1945 out_msg.accept(), &username)); | |
| 1946 EXPECT_TRUE(out_msg.get() == NULL); | |
| 1947 EXPECT_EQ("", username); | |
| 1948 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
| 1949 | |
| 1950 // BINDING-REQUEST with too-short username. | |
| 1951 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, "lfra")); | |
| 1952 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1953 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1954 out_msg.accept(), &username)); | |
| 1955 EXPECT_TRUE(out_msg.get() == NULL); | |
| 1956 EXPECT_EQ("", username); | |
| 1957 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
| 1958 | |
| 1959 // BINDING-REQUEST with reversed username. | |
| 1960 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1961 "lfragrfrag")); | |
| 1962 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1963 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1964 out_msg.accept(), &username)); | |
| 1965 EXPECT_TRUE(out_msg.get() == NULL); | |
| 1966 EXPECT_EQ("", username); | |
| 1967 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
| 1968 | |
| 1969 // BINDING-REQUEST with garbage username. | |
| 1970 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | |
| 1971 "abcdefgh")); | |
| 1972 WriteStunMessage(in_msg.get(), buf.get()); | |
| 1973 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | |
| 1974 out_msg.accept(), &username)); | |
| 1975 EXPECT_TRUE(out_msg.get() == NULL); | |
| 1976 EXPECT_EQ("", username); | |
| 1977 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED_AS_GICE, port->last_stun_error_code()); | |
| 1978 } | |
| 1979 | |
| 1980 // Tests handling of ICE binding requests with missing or incorrect usernames. | |
| 1981 TEST_F(PortTest, TestHandleStunMessageAsIceBadUsername) { | |
| 1982 rtc::scoped_ptr<TestPort> port( | |
| 1983 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | |
| 1984 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 1985 | |
| 1986 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | |
| 1987 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | |
| 1988 rtc::SocketAddress addr(kLocalAddr1); | 1665 rtc::SocketAddress addr(kLocalAddr1); |
| 1989 std::string username; | 1666 std::string username; |
| 1990 | 1667 |
| 1991 // BINDING-REQUEST with no username. | 1668 // BINDING-REQUEST with no username. |
| 1992 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); | 1669 in_msg.reset(CreateStunMessage(STUN_BINDING_REQUEST)); |
| 1993 in_msg->AddMessageIntegrity("rpass"); | 1670 in_msg->AddMessageIntegrity("rpass"); |
| 1994 in_msg->AddFingerprint(); | 1671 in_msg->AddFingerprint(); |
| 1995 WriteStunMessage(in_msg.get(), buf.get()); | 1672 WriteStunMessage(in_msg.get(), buf.get()); |
| 1996 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1673 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 1997 out_msg.accept(), &username)); | 1674 out_msg.accept(), &username)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2039 in_msg->AddMessageIntegrity("rpass"); | 1716 in_msg->AddMessageIntegrity("rpass"); |
| 2040 in_msg->AddFingerprint(); | 1717 in_msg->AddFingerprint(); |
| 2041 WriteStunMessage(in_msg.get(), buf.get()); | 1718 WriteStunMessage(in_msg.get(), buf.get()); |
| 2042 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1719 EXPECT_TRUE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2043 out_msg.accept(), &username)); | 1720 out_msg.accept(), &username)); |
| 2044 EXPECT_TRUE(out_msg.get() == NULL); | 1721 EXPECT_TRUE(out_msg.get() == NULL); |
| 2045 EXPECT_EQ("", username); | 1722 EXPECT_EQ("", username); |
| 2046 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 1723 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
| 2047 } | 1724 } |
| 2048 | 1725 |
| 2049 // Test handling STUN messages (as ICE) with missing or malformed M-I. | 1726 // Test handling STUN messages with missing or malformed M-I. |
| 2050 TEST_F(PortTest, TestHandleStunMessageAsIceBadMessageIntegrity) { | 1727 TEST_F(PortTest, TestHandleStunMessageBadMessageIntegrity) { |
| 2051 // Our port will act as the "remote" port. | 1728 // Our port will act as the "remote" port. |
| 2052 rtc::scoped_ptr<TestPort> port( | 1729 rtc::scoped_ptr<TestPort> port( |
| 2053 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1730 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2054 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 2055 | 1731 |
| 2056 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1732 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 2057 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1733 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 2058 rtc::SocketAddress addr(kLocalAddr1); | 1734 rtc::SocketAddress addr(kLocalAddr1); |
| 2059 std::string username; | 1735 std::string username; |
| 2060 | 1736 |
| 2061 // BINDING-REQUEST from local to remote with valid ICE username and | 1737 // BINDING-REQUEST from local to remote with valid ICE username and |
| 2062 // FINGERPRINT, but no MESSAGE-INTEGRITY. | 1738 // FINGERPRINT, but no MESSAGE-INTEGRITY. |
| 2063 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1739 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 2064 "rfrag:lfrag")); | 1740 "rfrag:lfrag")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2081 out_msg.accept(), &username)); | 1757 out_msg.accept(), &username)); |
| 2082 EXPECT_TRUE(out_msg.get() == NULL); | 1758 EXPECT_TRUE(out_msg.get() == NULL); |
| 2083 EXPECT_EQ("", username); | 1759 EXPECT_EQ("", username); |
| 2084 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); | 1760 EXPECT_EQ(STUN_ERROR_UNAUTHORIZED, port->last_stun_error_code()); |
| 2085 | 1761 |
| 2086 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked | 1762 // TODO: BINDING-RESPONSES and BINDING-ERROR-RESPONSES are checked |
| 2087 // by the Connection, not the Port, since they require the remote username. | 1763 // by the Connection, not the Port, since they require the remote username. |
| 2088 // Change this test to pass in data via Connection::OnReadPacket instead. | 1764 // Change this test to pass in data via Connection::OnReadPacket instead. |
| 2089 } | 1765 } |
| 2090 | 1766 |
| 2091 // Test handling STUN messages (as ICE) with missing or malformed FINGERPRINT. | 1767 // Test handling STUN messages with missing or malformed FINGERPRINT. |
| 2092 TEST_F(PortTest, TestHandleStunMessageAsIceBadFingerprint) { | 1768 TEST_F(PortTest, TestHandleStunMessageBadFingerprint) { |
| 2093 // Our port will act as the "remote" port. | 1769 // Our port will act as the "remote" port. |
| 2094 rtc::scoped_ptr<TestPort> port( | 1770 rtc::scoped_ptr<TestPort> port( |
| 2095 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1771 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2096 port->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 2097 | 1772 |
| 2098 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1773 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 2099 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1774 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 2100 rtc::SocketAddress addr(kLocalAddr1); | 1775 rtc::SocketAddress addr(kLocalAddr1); |
| 2101 std::string username; | 1776 std::string username; |
| 2102 | 1777 |
| 2103 // BINDING-REQUEST from local to remote with valid ICE username and | 1778 // BINDING-REQUEST from local to remote with valid ICE username and |
| 2104 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. | 1779 // MESSAGE-INTEGRITY, but no FINGERPRINT; GetStunMessage should fail. |
| 2105 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, | 1780 in_msg.reset(CreateStunMessageWithUsername(STUN_BINDING_REQUEST, |
| 2106 "rfrag:lfrag")); | 1781 "rfrag:lfrag")); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 | 1823 |
| 2149 // Now, add a fingerprint, but munge the message so it's not valid. | 1824 // Now, add a fingerprint, but munge the message so it's not valid. |
| 2150 in_msg->AddFingerprint(); | 1825 in_msg->AddFingerprint(); |
| 2151 in_msg->SetTransactionID("TESTTESTBADD"); | 1826 in_msg->SetTransactionID("TESTTESTBADD"); |
| 2152 WriteStunMessage(in_msg.get(), buf.get()); | 1827 WriteStunMessage(in_msg.get(), buf.get()); |
| 2153 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, | 1828 EXPECT_FALSE(port->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2154 out_msg.accept(), &username)); | 1829 out_msg.accept(), &username)); |
| 2155 EXPECT_EQ(0, port->last_stun_error_code()); | 1830 EXPECT_EQ(0, port->last_stun_error_code()); |
| 2156 } | 1831 } |
| 2157 | 1832 |
| 2158 // Test handling of STUN binding indication messages (as ICE). STUN binding | 1833 // Test handling of STUN binding indication messages . STUN binding |
| 2159 // indications are allowed only to the connection which is in read mode. | 1834 // indications are allowed only to the connection which is in read mode. |
| 2160 TEST_F(PortTest, TestHandleStunBindingIndication) { | 1835 TEST_F(PortTest, TestHandleStunBindingIndication) { |
| 2161 rtc::scoped_ptr<TestPort> lport( | 1836 rtc::scoped_ptr<TestPort> lport( |
| 2162 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); | 1837 CreateTestPort(kLocalAddr2, "lfrag", "lpass")); |
| 2163 lport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 2164 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1838 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2165 lport->SetIceTiebreaker(kTiebreaker1); | 1839 lport->SetIceTiebreaker(kTiebreaker1); |
| 2166 | 1840 |
| 2167 // Verifying encoding and decoding STUN indication message. | 1841 // Verifying encoding and decoding STUN indication message. |
| 2168 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1842 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
| 2169 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1843 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
| 2170 rtc::SocketAddress addr(kLocalAddr1); | 1844 rtc::SocketAddress addr(kLocalAddr1); |
| 2171 std::string username; | 1845 std::string username; |
| 2172 | 1846 |
| 2173 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); | 1847 in_msg.reset(CreateStunMessage(STUN_BINDING_INDICATION)); |
| 2174 in_msg->AddFingerprint(); | 1848 in_msg->AddFingerprint(); |
| 2175 WriteStunMessage(in_msg.get(), buf.get()); | 1849 WriteStunMessage(in_msg.get(), buf.get()); |
| 2176 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, | 1850 EXPECT_TRUE(lport->GetStunMessage(buf->Data(), buf->Length(), addr, |
| 2177 out_msg.accept(), &username)); | 1851 out_msg.accept(), &username)); |
| 2178 EXPECT_TRUE(out_msg.get() != NULL); | 1852 EXPECT_TRUE(out_msg.get() != NULL); |
| 2179 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); | 1853 EXPECT_EQ(out_msg->type(), STUN_BINDING_INDICATION); |
| 2180 EXPECT_EQ("", username); | 1854 EXPECT_EQ("", username); |
| 2181 | 1855 |
| 2182 // Verify connection can handle STUN indication and updates | 1856 // Verify connection can handle STUN indication and updates |
| 2183 // last_ping_received. | 1857 // last_ping_received. |
| 2184 rtc::scoped_ptr<TestPort> rport( | 1858 rtc::scoped_ptr<TestPort> rport( |
| 2185 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1859 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 2186 rport->SetIceProtocolType(ICEPROTO_RFC5245); | |
| 2187 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1860 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2188 rport->SetIceTiebreaker(kTiebreaker2); | 1861 rport->SetIceTiebreaker(kTiebreaker2); |
| 2189 | 1862 |
| 2190 lport->PrepareAddress(); | 1863 lport->PrepareAddress(); |
| 2191 rport->PrepareAddress(); | 1864 rport->PrepareAddress(); |
| 2192 ASSERT_FALSE(lport->Candidates().empty()); | 1865 ASSERT_FALSE(lport->Candidates().empty()); |
| 2193 ASSERT_FALSE(rport->Candidates().empty()); | 1866 ASSERT_FALSE(rport->Candidates().empty()); |
| 2194 | 1867 |
| 2195 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], | 1868 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
| 2196 Port::ORIGIN_MESSAGE); | 1869 Port::ORIGIN_MESSAGE); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2525 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); | 2198 ch1.conn()->UpdateState(CONNECTION_WRITE_TIMEOUT + 500u); |
| 2526 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); | 2199 EXPECT_EQ(Connection::STATE_WRITE_TIMEOUT, ch1.conn()->write_state()); |
| 2527 } | 2200 } |
| 2528 | 2201 |
| 2529 // This test verifies the connection setup between ICEMODE_FULL | 2202 // This test verifies the connection setup between ICEMODE_FULL |
| 2530 // and ICEMODE_LITE. | 2203 // and ICEMODE_LITE. |
| 2531 // In this test |ch1| behaves like FULL mode client and we have created | 2204 // In this test |ch1| behaves like FULL mode client and we have created |
| 2532 // port which responds to the ping message just like LITE client. | 2205 // port which responds to the ping message just like LITE client. |
| 2533 TEST_F(PortTest, TestIceLiteConnectivity) { | 2206 TEST_F(PortTest, TestIceLiteConnectivity) { |
| 2534 TestPort* ice_full_port = CreateTestPort( | 2207 TestPort* ice_full_port = CreateTestPort( |
| 2535 kLocalAddr1, "lfrag", "lpass", cricket::ICEPROTO_RFC5245, | 2208 kLocalAddr1, "lfrag", "lpass", |
| 2536 cricket::ICEROLE_CONTROLLING, kTiebreaker1); | 2209 cricket::ICEROLE_CONTROLLING, kTiebreaker1); |
| 2537 | 2210 |
| 2538 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( | 2211 rtc::scoped_ptr<TestPort> ice_lite_port(CreateTestPort( |
| 2539 kLocalAddr2, "rfrag", "rpass", cricket::ICEPROTO_RFC5245, | 2212 kLocalAddr2, "rfrag", "rpass", |
| 2540 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); | 2213 cricket::ICEROLE_CONTROLLED, kTiebreaker2)); |
| 2541 // Setup TestChannel. This behaves like FULL mode client. | 2214 // Setup TestChannel. This behaves like FULL mode client. |
| 2542 TestChannel ch1(ice_full_port, ice_lite_port.get()); | 2215 TestChannel ch1(ice_full_port, ice_lite_port.get()); |
| 2543 ch1.SetIceMode(ICEMODE_FULL); | 2216 ch1.SetIceMode(ICEMODE_FULL); |
| 2544 | 2217 |
| 2545 // Start gathering candidates. | 2218 // Start gathering candidates. |
| 2546 ch1.Start(); | 2219 ch1.Start(); |
| 2547 ice_lite_port->PrepareAddress(); | 2220 ice_lite_port->PrepareAddress(); |
| 2548 | 2221 |
| 2549 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); | 2222 ASSERT_EQ_WAIT(1, ch1.complete_count(), kTimeout); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2588 // Send ping. This must have USE_CANDIDATE_ATTR. | 2261 // Send ping. This must have USE_CANDIDATE_ATTR. |
| 2589 ch1.Ping(); | 2262 ch1.Ping(); |
| 2590 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); | 2263 ASSERT_TRUE_WAIT(ice_full_port->last_stun_msg() != NULL, 1000); |
| 2591 msg = ice_full_port->last_stun_msg(); | 2264 msg = ice_full_port->last_stun_msg(); |
| 2592 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); | 2265 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) != NULL); |
| 2593 ch1.Stop(); | 2266 ch1.Stop(); |
| 2594 } | 2267 } |
| 2595 | 2268 |
| 2596 // This test case verifies that the CONTROLLING port does not time out. | 2269 // This test case verifies that the CONTROLLING port does not time out. |
| 2597 TEST_F(PortTest, TestControllingNoTimeout) { | 2270 TEST_F(PortTest, TestControllingNoTimeout) { |
| 2598 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
| 2599 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2271 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2600 ConnectToSignalDestroyed(port1); | 2272 ConnectToSignalDestroyed(port1); |
| 2601 port1->set_timeout_delay(10); // milliseconds | 2273 port1->set_timeout_delay(10); // milliseconds |
| 2602 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2274 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2603 port1->SetIceTiebreaker(kTiebreaker1); | 2275 port1->SetIceTiebreaker(kTiebreaker1); |
| 2604 | 2276 |
| 2605 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2277 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2606 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2278 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2607 port2->SetIceTiebreaker(kTiebreaker2); | 2279 port2->SetIceTiebreaker(kTiebreaker2); |
| 2608 | 2280 |
| 2609 // Set up channels and ensure both ports will be deleted. | 2281 // Set up channels and ensure both ports will be deleted. |
| 2610 TestChannel ch1(port1, port2); | 2282 TestChannel ch1(port1, port2); |
| 2611 TestChannel ch2(port2, port1); | 2283 TestChannel ch2(port2, port1); |
| 2612 | 2284 |
| 2613 // Simulate a connection that succeeds, and then is destroyed. | 2285 // Simulate a connection that succeeds, and then is destroyed. |
| 2614 StartConnectAndStopChannels(&ch1, &ch2); | 2286 StartConnectAndStopChannels(&ch1, &ch2); |
| 2615 | 2287 |
| 2616 // After the connection is destroyed, the port should not be destroyed. | 2288 // After the connection is destroyed, the port should not be destroyed. |
| 2617 rtc::Thread::Current()->ProcessMessages(kTimeout); | 2289 rtc::Thread::Current()->ProcessMessages(kTimeout); |
| 2618 EXPECT_FALSE(destroyed()); | 2290 EXPECT_FALSE(destroyed()); |
| 2619 } | 2291 } |
| 2620 | 2292 |
| 2621 // This test case verifies that the CONTROLLED port does time out, but only | 2293 // This test case verifies that the CONTROLLED port does time out, but only |
| 2622 // after connectivity is lost. | 2294 // after connectivity is lost. |
| 2623 TEST_F(PortTest, TestControlledTimeout) { | 2295 TEST_F(PortTest, TestControlledTimeout) { |
| 2624 SetIceProtocolType(cricket::ICEPROTO_RFC5245); | |
| 2625 UDPPort* port1 = CreateUdpPort(kLocalAddr1); | 2296 UDPPort* port1 = CreateUdpPort(kLocalAddr1); |
| 2626 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2297 port1->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2627 port1->SetIceTiebreaker(kTiebreaker1); | 2298 port1->SetIceTiebreaker(kTiebreaker1); |
| 2628 | 2299 |
| 2629 UDPPort* port2 = CreateUdpPort(kLocalAddr2); | 2300 UDPPort* port2 = CreateUdpPort(kLocalAddr2); |
| 2630 ConnectToSignalDestroyed(port2); | 2301 ConnectToSignalDestroyed(port2); |
| 2631 port2->set_timeout_delay(10); // milliseconds | 2302 port2->set_timeout_delay(10); // milliseconds |
| 2632 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); | 2303 port2->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2633 port2->SetIceTiebreaker(kTiebreaker2); | 2304 port2->SetIceTiebreaker(kTiebreaker2); |
| 2634 | 2305 |
| 2635 // The connection must not be destroyed before a connection is attempted. | 2306 // The connection must not be destroyed before a connection is attempted. |
| 2636 EXPECT_FALSE(destroyed()); | 2307 EXPECT_FALSE(destroyed()); |
| 2637 | 2308 |
| 2638 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2309 port1->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2639 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 2310 port2->set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
| 2640 | 2311 |
| 2641 // Set up channels and ensure both ports will be deleted. | 2312 // Set up channels and ensure both ports will be deleted. |
| 2642 TestChannel ch1(port1, port2); | 2313 TestChannel ch1(port1, port2); |
| 2643 TestChannel ch2(port2, port1); | 2314 TestChannel ch2(port2, port1); |
| 2644 | 2315 |
| 2645 // Simulate a connection that succeeds, and then is destroyed. | 2316 // Simulate a connection that succeeds, and then is destroyed. |
| 2646 StartConnectAndStopChannels(&ch1, &ch2); | 2317 StartConnectAndStopChannels(&ch1, &ch2); |
| 2647 | 2318 |
| 2648 // The controlled port should be destroyed after 10 milliseconds. | 2319 // The controlled port should be destroyed after 10 milliseconds. |
| 2649 EXPECT_TRUE_WAIT(destroyed(), kTimeout); | 2320 EXPECT_TRUE_WAIT(destroyed(), kTimeout); |
| 2650 } | 2321 } |
| OLD | NEW |