| 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 24 matching lines...) Expand all Loading... |
| 35 "purpose is to make the parser go 'ack'. it doesn't " | 35 "purpose is to make the parser go 'ack'. it doesn't " |
| 36 "look anything like a normal stun message"; | 36 "look anything like a normal stun message"; |
| 37 static const char* msg1 = "spamspamspamspamspamspamspambakedbeansspam"; | 37 static const char* msg1 = "spamspamspamspamspamspamspambakedbeansspam"; |
| 38 static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce..."; | 38 static const char* msg2 = "Lobster Thermidor a Crevette with a mornay sauce..."; |
| 39 | 39 |
| 40 class RelayServerTest : public testing::Test { | 40 class RelayServerTest : public testing::Test { |
| 41 public: | 41 public: |
| 42 RelayServerTest() | 42 RelayServerTest() |
| 43 : pss_(new rtc::PhysicalSocketServer), | 43 : pss_(new rtc::PhysicalSocketServer), |
| 44 ss_(new rtc::VirtualSocketServer(pss_.get())), | 44 ss_(new rtc::VirtualSocketServer(pss_.get())), |
| 45 ss_scope_(ss_.get()), | 45 thread_(ss_.get()), |
| 46 username_(rtc::CreateRandomString(12)), | 46 username_(rtc::CreateRandomString(12)), |
| 47 password_(rtc::CreateRandomString(12)) {} | 47 password_(rtc::CreateRandomString(12)) {} |
| 48 | 48 |
| 49 protected: | 49 protected: |
| 50 virtual void SetUp() { | 50 virtual void SetUp() { |
| 51 server_.reset(new RelayServer(rtc::Thread::Current())); | 51 server_.reset(new RelayServer(rtc::Thread::Current())); |
| 52 | 52 |
| 53 server_->AddInternalSocket( | 53 server_->AddInternalSocket( |
| 54 rtc::AsyncUDPSocket::Create(ss_.get(), server_int_addr)); | 54 rtc::AsyncUDPSocket::Create(ss_.get(), server_int_addr)); |
| 55 server_->AddExternalSocket( | 55 server_->AddExternalSocket( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 161 } |
| 162 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { | 162 static void AddDestinationAttr(StunMessage* msg, const SocketAddress& addr) { |
| 163 auto attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | 163 auto attr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
| 164 attr->SetIP(addr.ipaddr()); | 164 attr->SetIP(addr.ipaddr()); |
| 165 attr->SetPort(addr.port()); | 165 attr->SetPort(addr.port()); |
| 166 msg->AddAttribute(std::move(attr)); | 166 msg->AddAttribute(std::move(attr)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 169 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 170 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 170 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
| 171 rtc::SocketServerScope ss_scope_; | 171 rtc::AutoSocketServerThread thread_; |
| 172 std::unique_ptr<RelayServer> server_; | 172 std::unique_ptr<RelayServer> server_; |
| 173 std::unique_ptr<rtc::TestClient> client1_; | 173 std::unique_ptr<rtc::TestClient> client1_; |
| 174 std::unique_ptr<rtc::TestClient> client2_; | 174 std::unique_ptr<rtc::TestClient> client2_; |
| 175 std::string username_; | 175 std::string username_; |
| 176 std::string password_; | 176 std::string password_; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 // Send a complete nonsense message and verify that it is eaten. | 179 // Send a complete nonsense message and verify that it is eaten. |
| 180 TEST_F(RelayServerTest, TestBadRequest) { | 180 TEST_F(RelayServerTest, TestBadRequest) { |
| 181 SendRaw1(bad, static_cast<int>(strlen(bad))); | 181 SendRaw1(bad, static_cast<int>(strlen(bad))); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 const StunErrorCodeAttribute* err = res->GetErrorCode(); | 507 const StunErrorCodeAttribute* err = res->GetErrorCode(); |
| 508 ASSERT_TRUE(err != NULL); | 508 ASSERT_TRUE(err != NULL); |
| 509 EXPECT_EQ(6, err->eclass()); | 509 EXPECT_EQ(6, err->eclass()); |
| 510 EXPECT_EQ(0, err->number()); | 510 EXPECT_EQ(0, err->number()); |
| 511 EXPECT_EQ("Operation Not Supported", err->reason()); | 511 EXPECT_EQ("Operation Not Supported", err->reason()); |
| 512 | 512 |
| 513 // Also verify that traffic from the external client is ignored. | 513 // Also verify that traffic from the external client is ignored. |
| 514 SendRaw2(msg2, static_cast<int>(strlen(msg2))); | 514 SendRaw2(msg2, static_cast<int>(strlen(msg2))); |
| 515 EXPECT_TRUE(ReceiveRaw1().empty()); | 515 EXPECT_TRUE(ReceiveRaw1().empty()); |
| 516 } | 516 } |
| OLD | NEW |