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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 msg.Write(&buf); | 44 msg.Write(&buf); |
45 Send(buf.Data(), static_cast<int>(buf.Length())); | 45 Send(buf.Data(), static_cast<int>(buf.Length())); |
46 } | 46 } |
47 void Send(const char* buf, int len) { | 47 void Send(const char* buf, int len) { |
48 client_->SendTo(buf, len, server_addr); | 48 client_->SendTo(buf, len, server_addr); |
49 } | 49 } |
50 bool ReceiveFails() { | 50 bool ReceiveFails() { |
51 return(client_->CheckNoPacket()); | 51 return(client_->CheckNoPacket()); |
52 } | 52 } |
53 StunMessage* Receive() { | 53 StunMessage* Receive() { |
54 StunMessage* msg = NULL; | 54 StunMessage* msg = nullptr; |
55 rtc::TestClient::Packet* packet = | 55 rtc::TestClient::Packet* packet = |
56 client_->NextPacket(rtc::TestClient::kTimeoutMs); | 56 client_->NextPacket(rtc::TestClient::kTimeoutMs); |
57 if (packet) { | 57 if (packet) { |
58 rtc::ByteBufferReader buf(packet->buf, packet->size); | 58 rtc::ByteBufferReader buf(packet->buf, packet->size); |
59 msg = new StunMessage(); | 59 msg = new StunMessage(); |
60 msg->Read(&buf); | 60 msg->Read(&buf); |
61 delete packet; | 61 delete packet; |
62 } | 62 } |
63 return msg; | 63 return msg; |
64 } | 64 } |
(...skipping 10 matching lines...) Expand all Loading... |
75 #if !defined(THREAD_SANITIZER) | 75 #if !defined(THREAD_SANITIZER) |
76 | 76 |
77 TEST_F(StunServerTest, TestGood) { | 77 TEST_F(StunServerTest, TestGood) { |
78 StunMessage req; | 78 StunMessage req; |
79 std::string transaction_id = "0123456789ab"; | 79 std::string transaction_id = "0123456789ab"; |
80 req.SetType(STUN_BINDING_REQUEST); | 80 req.SetType(STUN_BINDING_REQUEST); |
81 req.SetTransactionID(transaction_id); | 81 req.SetTransactionID(transaction_id); |
82 Send(req); | 82 Send(req); |
83 | 83 |
84 StunMessage* msg = Receive(); | 84 StunMessage* msg = Receive(); |
85 ASSERT_TRUE(msg != NULL); | 85 ASSERT_TRUE(msg != nullptr); |
86 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); | 86 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); |
87 EXPECT_EQ(req.transaction_id(), msg->transaction_id()); | 87 EXPECT_EQ(req.transaction_id(), msg->transaction_id()); |
88 | 88 |
89 const StunAddressAttribute* mapped_addr = | 89 const StunAddressAttribute* mapped_addr = |
90 msg->GetAddress(STUN_ATTR_MAPPED_ADDRESS); | 90 msg->GetAddress(STUN_ATTR_MAPPED_ADDRESS); |
91 EXPECT_TRUE(mapped_addr != NULL); | 91 EXPECT_TRUE(mapped_addr != nullptr); |
92 EXPECT_EQ(1, mapped_addr->family()); | 92 EXPECT_EQ(1, mapped_addr->family()); |
93 EXPECT_EQ(client_addr.port(), mapped_addr->port()); | 93 EXPECT_EQ(client_addr.port(), mapped_addr->port()); |
94 if (mapped_addr->ipaddr() != client_addr.ipaddr()) { | 94 if (mapped_addr->ipaddr() != client_addr.ipaddr()) { |
95 LOG(LS_WARNING) << "Warning: mapped IP (" | 95 LOG(LS_WARNING) << "Warning: mapped IP (" |
96 << mapped_addr->ipaddr() | 96 << mapped_addr->ipaddr() |
97 << ") != local IP (" << client_addr.ipaddr() | 97 << ") != local IP (" << client_addr.ipaddr() |
98 << ")"; | 98 << ")"; |
99 } | 99 } |
100 | 100 |
101 delete msg; | 101 delete msg; |
102 } | 102 } |
103 | 103 |
104 #endif // if !defined(THREAD_SANITIZER) | 104 #endif // if !defined(THREAD_SANITIZER) |
105 | 105 |
106 TEST_F(StunServerTest, TestBad) { | 106 TEST_F(StunServerTest, TestBad) { |
107 const char* bad = "this is a completely nonsensical message whose only " | 107 const char* bad = "this is a completely nonsensical message whose only " |
108 "purpose is to make the parser go 'ack'. it doesn't " | 108 "purpose is to make the parser go 'ack'. it doesn't " |
109 "look anything like a normal stun message"; | 109 "look anything like a normal stun message"; |
110 Send(bad, static_cast<int>(strlen(bad))); | 110 Send(bad, static_cast<int>(strlen(bad))); |
111 | 111 |
112 ASSERT_TRUE(ReceiveFails()); | 112 ASSERT_TRUE(ReceiveFails()); |
113 } | 113 } |
OLD | NEW |