OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/p2p/socket_host.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | |
11 #include "net/base/ip_endpoint.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 // Rtp message with invalid length. | |
16 static unsigned char kRtpMsgWithInvalidLength[] = { | |
17 0x94, 0x00, 0x00, 0x00, | |
18 0x00, 0x00, 0x00, 0x00, | |
19 0xAA, 0xBB, 0xCC, 0XDD, // SSRC | |
20 0xDD, 0xCC, 0xBB, 0xAA // Only 1 CSRC, but CC count is 4. | |
21 }; | |
22 | |
23 // Rtp message with single byte header extension, invalid extension length. | |
24 static unsigned char kRtpMessageWithInvalidExtnLength[] = { | |
Solis
2014/03/03 10:22:29
Stick to either Msg or Message.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Sticking to Msg
On 2014/03/03 10:22:29, Solis wro
| |
25 0x90, 0x00, 0x00, 0x00, | |
26 0x00, 0x00, 0x00, 0x00, | |
27 0x00, 0x00, 0x00, 0x00, | |
28 0xBE, 0xDE, 0x0A, 0x00 // Extn length - 0x0A00 | |
29 }; | |
30 | |
31 // Valid rtp Message with 2 byte header extension. | |
32 static unsigned char kRtpMsgWith2ByteExtnHeader[] = { | |
33 0x90, 0x00, 0x00, 0x00, | |
34 0x00, 0x00, 0x00, 0x00, | |
35 0xAA, 0xBB, 0xCC, 0XDD, // SSRC | |
36 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension | |
37 0x01, 0x00, 0x00, 0x00 | |
38 }; | |
39 | |
40 // Stun Indication message with Zero length | |
41 static unsigned char kTurnSendIndicationMsgWithNoAttributes[] = { | |
42 0x00, 0x16, 0x00, 0x00, // Zero length | |
43 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
44 '0', '1', '2', '3', // transaction id | |
45 '4', '5', '6', '7', | |
46 '8', '9', 'a', 'b', | |
47 }; | |
48 | |
49 // Stun Send Indication message with invalid length in stun header. | |
50 static unsigned char kTurnSendIndicationMsgWithInvalidLength[] = { | |
51 0x00, 0x16, 0xFF, 0x00, // length of 0xFF00 | |
52 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
53 '0', '1', '2', '3', // transaction id | |
54 '4', '5', '6', '7', | |
55 '8', '9', 'a', 'b', | |
56 }; | |
57 | |
58 // Stun Send Indication message with no DATA attribute in message. | |
59 static unsigned char kTurnSendIndicatinMsgWithNoDataAttribute[] = { | |
60 0x00, 0x16, 0x00, 0x08, // length of | |
61 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
62 '0', '1', '2', '3', // transaction id | |
63 '4', '5', '6', '7', | |
64 '8', '9', 'a', 'b', | |
65 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
66 0x00, 0x00, 0x00, 0x00 | |
67 }; | |
68 | |
69 // A valid STUN indication message with a valid RTP header in data attribute | |
70 // payload field and no extension bit set. | |
71 static unsigned char kTurnSendIndicationMsgWithoutRtpExtension[] = { | |
72 0x00, 0x16, 0x00, 0x18, // length of | |
73 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
74 '0', '1', '2', '3', // transaction id | |
75 '4', '5', '6', '7', | |
76 '8', '9', 'a', 'b', | |
77 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
78 0x00, 0x00, 0x00, 0x00, | |
79 0x00, 0x13, 0x00, 0x0C, // Data attribute. | |
80 0x80, 0x00, 0x00, 0x00, // RTP packet. | |
81 0x00, 0x00, 0x00, 0x00, | |
82 0x00, 0x00, 0x00, 0x00, | |
83 }; | |
84 | |
85 // A valid STUN indication message with a valid RTP header and a extension | |
86 // header. | |
87 static unsigned char kTurnSendIndicationMsgWithAbsSendTimeExtension[] = { | |
88 0x00, 0x16, 0x00, 0x20, // length of | |
89 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
90 '0', '1', '2', '3', // transaction id | |
91 '4', '5', '6', '7', | |
92 '8', '9', 'a', 'b', | |
93 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
94 0x00, 0x00, 0x00, 0x00, | |
95 0x00, 0x13, 0x00, 0x14, // Data attribute. | |
96 0x90, 0x00, 0x00, 0x00, // RTP packet. | |
97 0x00, 0x00, 0x00, 0x00, | |
98 0x00, 0x00, 0x00, 0x00, | |
99 0xBE, 0xDE, 0x00, 0x01, | |
100 0x32, 0xaa, 0xbb, 0xcc, | |
101 }; | |
102 | |
103 // A valid TURN channel header, but not RTP packet. | |
104 static unsigned char kTurnChannelMessageNoRtpPacket[] = { | |
105 0x40, 0x00, 0x00, 0x04, | |
106 0xaa, 0xbb, 0xcc, 0xdd, | |
107 }; | |
108 | |
109 // Turn ChannelMessage with zero length of payload. | |
110 static unsigned char kTurnChannelMessageWithZeroLength[] = { | |
111 0x40, 0x00, 0x00, 0x00 | |
112 }; | |
113 | |
114 // Turn ChannelMessage, wrapping a RTP packet without extension. | |
115 static unsigned char kTurnChannelMessageWithRtpPacket[] = { | |
116 0x40, 0x00, 0x00, 0x0C, | |
117 0x80, 0x00, 0x00, 0x00, // RTP packet. | |
118 0x00, 0x00, 0x00, 0x00, | |
119 0x00, 0x00, 0x00, 0x00, | |
120 }; | |
121 | |
122 // Turn ChannelMessage, wrapping a RTP packet with AbsSendTime Extension. | |
123 static unsigned char kTurnChannelMessageWithAbsSendTimeExtension[] = { | |
124 0x40, 0x00, 0x00, 0x14, | |
125 0x90, 0x00, 0x00, 0x00, // RTP packet. | |
126 0x00, 0x00, 0x00, 0x00, | |
127 0x00, 0x00, 0x00, 0x00, | |
128 0xBE, 0xDE, 0x00, 0x01, | |
129 0x32, 0xaa, 0xbb, 0xcc, | |
130 }; | |
131 | |
132 // RTP packet with single byte extension header of length 4 bytes. | |
133 // Extension id = 3 and length = 3 | |
134 static unsigned char kRtpPacketWithAbsSendTimeExtension[] = { | |
135 0x90, 0x00, 0x00, 0x00, | |
136 0x00, 0x00, 0x00, 0x00, | |
137 0x00, 0x00, 0x00, 0x00, | |
138 0xBE, 0xDE, 0x00, 0x01, | |
139 0x32, 0xaa, 0xbb, 0xcc, | |
140 }; | |
141 | |
142 namespace content { | |
143 | |
144 // This test verifies parsing of all invalid raw packets. | |
145 TEST(P2PSocketHostTest, TestInvalidRawRtpMessages) { | |
146 int start_pos = -1, rtp_length = -1; | |
147 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
148 reinterpret_cast<char*>(kRtpMsgWithInvalidLength), | |
149 sizeof(kRtpMsgWithInvalidLength), | |
150 &start_pos, &rtp_length)); | |
151 EXPECT_EQ(-1, start_pos); | |
152 EXPECT_EQ(-1, rtp_length); | |
153 | |
154 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
155 reinterpret_cast<char*>(kRtpMessageWithInvalidExtnLength), | |
156 sizeof(kRtpMessageWithInvalidExtnLength), | |
157 &start_pos, &rtp_length)); | |
158 EXPECT_EQ(-1, start_pos); | |
159 EXPECT_EQ(-1, rtp_length); | |
160 } | |
161 | |
162 // Verify invalid TURN send indication messages. Messages are proper STUN | |
163 // messages with incorrect values in attributes. | |
164 TEST(P2PSocketHostTest, TestInvalidTurnSendIndicationMessages) { | |
165 int start_pos = -1, rtp_length = -1; | |
166 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
167 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), | |
168 sizeof(kTurnSendIndicationMsgWithNoAttributes), | |
169 &start_pos, &rtp_length)); | |
170 EXPECT_EQ(-1, start_pos); | |
171 EXPECT_EQ(-1, rtp_length); | |
172 | |
173 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
174 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), | |
175 sizeof(kTurnSendIndicationMsgWithInvalidLength), | |
176 &start_pos, &rtp_length)); | |
177 EXPECT_EQ(-1, start_pos); | |
178 EXPECT_EQ(-1, rtp_length); | |
179 | |
180 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
181 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), | |
182 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), | |
183 &start_pos, &rtp_length)); | |
184 EXPECT_EQ(-1, start_pos); | |
185 EXPECT_EQ(-1, rtp_length); | |
186 | |
187 // Initializing out params to very large value. | |
Solis
2014/03/03 10:22:29
You should only need one test per message. Pick a
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
| |
188 start_pos = INT_MAX; | |
189 rtp_length = INT_MAX; | |
190 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
191 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), | |
192 sizeof(kTurnSendIndicationMsgWithNoAttributes), | |
193 &start_pos, &rtp_length)); | |
194 EXPECT_EQ(INT_MAX, start_pos); | |
195 EXPECT_EQ(INT_MAX, rtp_length); | |
196 | |
197 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
198 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), | |
199 sizeof(kTurnSendIndicationMsgWithInvalidLength), | |
200 &start_pos, &rtp_length)); | |
201 EXPECT_EQ(INT_MAX, start_pos); | |
202 EXPECT_EQ(INT_MAX, rtp_length); | |
203 | |
204 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
205 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), | |
206 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), | |
207 &start_pos, &rtp_length)); | |
208 EXPECT_EQ(INT_MAX, start_pos); | |
209 EXPECT_EQ(INT_MAX, rtp_length); | |
210 } | |
211 | |
212 // This test verifies incorrectly formed TURN channel messages. | |
213 TEST(P2PSocketHostTest, TestInvalidTurnChannelMessages) { | |
214 int start_pos = -1, rtp_length = -1; | |
215 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
216 reinterpret_cast<char*>(kTurnChannelMessageNoRtpPacket), | |
217 sizeof(kTurnChannelMessageNoRtpPacket), | |
218 &start_pos, &rtp_length)); | |
219 | |
Solis
2014/03/03 10:22:29
EXPECT_EQ(-1, ...) here as well
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
| |
220 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
221 reinterpret_cast<char*>(kTurnChannelMessageWithZeroLength), | |
222 sizeof(kTurnChannelMessageWithZeroLength), | |
223 &start_pos, &rtp_length)); | |
224 } | |
225 | |
226 // This test verifies parsing of a valid RTP packet which has 2byte header | |
227 // extension instead of a 1 byte header extension. | |
228 TEST(P2PSocketHostTest, TestValid2ByteExtnHdrRtpMessage) { | |
229 int start_pos = -1, rtp_length = -1; | |
230 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
231 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | |
232 sizeof(kRtpMsgWith2ByteExtnHeader), | |
233 &start_pos, &rtp_length)); | |
234 EXPECT_EQ(20, rtp_length); | |
235 EXPECT_EQ(0, start_pos); | |
236 } | |
237 | |
238 // This test verifies parsing of a valid RTP packet which has 1 byte header | |
239 // AbsSendTime extension in it. | |
240 TEST(P2PSocketHostTest, TestValidRtpPacketWithAbsSendTimeExtension) { | |
241 int start_pos = -1, rtp_length = -1; | |
242 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
243 reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), | |
Solis
2014/03/03 10:22:29
Why is this in a separate test case here, and anot
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
It was by mistake.
On 2014/03/03 10:22:29, Solis
| |
244 sizeof(kRtpPacketWithAbsSendTimeExtension), | |
245 &start_pos, &rtp_length)); | |
246 EXPECT_EQ(20, rtp_length); | |
247 EXPECT_EQ(0, start_pos); | |
248 } | |
249 | |
250 // This test verifies parsing of a valid TURN Send Indication messages. | |
251 TEST(P2PSocketHostTest, TestValidTurnSendIndicationMessages) { | |
252 int start_pos = -1, rtp_length = -1; | |
253 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
254 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | |
255 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), | |
256 &start_pos, &rtp_length)); | |
257 EXPECT_EQ(12, rtp_length); | |
258 EXPECT_EQ(32, start_pos); | |
259 | |
260 start_pos = -1, rtp_length = -1; | |
261 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
262 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), | |
263 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), | |
264 &start_pos, &rtp_length)); | |
265 EXPECT_EQ(20, rtp_length); | |
266 EXPECT_EQ(32, start_pos); | |
267 | |
268 // Initializing out params to very large value. | |
269 start_pos = INT_MAX, rtp_length = INT_MAX; | |
270 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
271 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | |
272 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), | |
273 &start_pos, &rtp_length)); | |
274 EXPECT_EQ(12, rtp_length); | |
275 EXPECT_EQ(32, start_pos); | |
276 | |
277 start_pos = INT_MAX, rtp_length = INT_MAX; | |
278 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
279 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), | |
280 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), | |
281 &start_pos, &rtp_length)); | |
282 EXPECT_EQ(20, rtp_length); | |
283 EXPECT_EQ(32, start_pos); | |
284 | |
285 start_pos = INT_MAX, rtp_length = INT_MAX; | |
286 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
287 reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), | |
288 sizeof(kRtpPacketWithAbsSendTimeExtension), | |
289 &start_pos, &rtp_length)); | |
290 EXPECT_EQ(20, rtp_length); | |
291 EXPECT_EQ(0, start_pos); | |
292 } | |
293 | |
294 // This test verifies parsing of valid TURN Channel Messages. | |
295 TEST(P2PSocketHostTest, TestValidTurnChannelMessages) { | |
296 int start_pos = -1, rtp_length = -1; | |
297 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
298 reinterpret_cast<char*>(kTurnChannelMessageWithRtpPacket), | |
299 sizeof(kTurnChannelMessageWithRtpPacket), &start_pos, &rtp_length)); | |
300 EXPECT_EQ(12, rtp_length); | |
301 EXPECT_EQ(4, start_pos); | |
302 | |
303 start_pos = -1, rtp_length = -1; | |
304 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | |
305 reinterpret_cast<char*>(kTurnChannelMessageWithAbsSendTimeExtension), | |
306 sizeof(kTurnChannelMessageWithAbsSendTimeExtension), | |
307 &start_pos, &rtp_length)); | |
308 EXPECT_EQ(20, rtp_length); | |
309 EXPECT_EQ(4, start_pos); | |
310 } | |
311 | |
312 // This test verifies seraching of RTP exension ID supplied as input in a | |
Solis
2014/03/03 10:22:29
spelling
it looks to me the comment is wrong btw.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
| |
313 // RTP packet. If it finds it will be update the the timestamp. | |
314 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { | |
315 EXPECT_FALSE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( | |
316 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | |
317 sizeof(kRtpMsgWith2ByteExtnHeader), 3)); | |
318 } | |
319 | |
320 // This test verifies updating AbsSendTime extension in a Turn Send Indication | |
321 // message. | |
322 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInTurnSendIndication) { | |
323 EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( | |
324 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | |
325 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), 3)); | |
326 | |
327 EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( | |
328 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), | |
329 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), 3)); | |
330 } | |
331 | |
332 // This test verifies updating AbsSendTime extension in a raw rtp message. | |
333 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInRtpPacket) { | |
334 EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( | |
335 reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), | |
336 sizeof(kRtpPacketWithAbsSendTimeExtension), 3)); | |
337 } | |
338 | |
339 } // namespace content | |
OLD | NEW |