Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(784)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_tamper_detect_unittest.cc

Issue 338483002: Chrome Participated Tamper Detect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Bolian's comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 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 <string.h>
6 #include <algorithm>
7 #include <vector>
8
9 #include "base/base64.h"
10 #include "base/md5.h"
11
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_tamper_de tect.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 std::string GetEncoded(std::string input) {
16 base::MD5Context context;
17 base::MD5Init(&context);
18 base::MD5Update(&context, input);
19 base::MD5Digest new_digest;
20 base::MD5Final(&new_digest, &context);
bolian 2014/06/27 00:49:02 use GetMD5 in your cc file.
21
22 std::string temp = std::string((char*)new_digest.a, 16);
23 std::string ret;
24 base::Base64Encode(temp, &ret);
25 return ret;
26 }
27
28 namespace {
29
30 void HeadersToRaw(std::string* headers) {
31 std::replace(headers->begin(), headers->end(), '\n', '\0');
32 if (!headers->empty())
33 *headers += '\0';
34 }
35
36 struct TestCase {
37 const char* raw_header;
bolian 2014/06/27 02:16:58 s/const char*/std::string/ ?
xingx 2014/06/27 16:34:38 Done.
38 std::string received_fingerprint;
39 bool expected_result;
bolian 2014/06/27 02:16:58 the var name is not clear, whether you expect tamp
xingx 2014/06/27 16:34:38 Done.
40 };
41
42 class DataReductionProxyTamperDetectTest : public testing::Test {
43 };
44
45 void TestFingerprintCommon(const TestCase& test, int fingerprintNumber) {
46 std::string raw_headers(test.raw_header);
47 HeadersToRaw(&raw_headers);
48 scoped_refptr<net::HttpResponseHeaders> headers(
49 new net::HttpResponseHeaders(raw_headers));
50
51 typedef bool (*CheckHeader)(const std::string,
52 const net::HttpResponseHeaders*);
53
54 CheckHeader checkFuncs[] = {&data_reduction_proxy::CheckHeaderChromeProxy,
bolian 2014/06/27 02:16:58 this table should be outside the func.
xingx 2014/06/27 16:34:37 Done.
55 &data_reduction_proxy::CheckHeaderVia,
56 &data_reduction_proxy::CheckHeaderOtherHeaders,
57 &data_reduction_proxy::CheckHeaderContentLength};
58
59 EXPECT_EQ(test.expected_result, checkFuncs[fingerprintNumber](
bolian 2014/06/27 00:49:02 use enum instead of int for func index.
xingx 2014/06/27 16:34:37 Done.
60 test.received_fingerprint, headers));
61 }
62
63 void TestParsingCommon(const std::string fp) {
64 std::string raw_headers(fp);
65 HeadersToRaw(&raw_headers);
66 scoped_refptr<net::HttpResponseHeaders> headers(
67 new net::HttpResponseHeaders(raw_headers));
68
69 data_reduction_proxy::CheckResponseFingerprint(headers, false);
70 }
71
72 TEST(DataReductionProxyTamperDetectTest, ChromeProxy) {
73 TestCase test[] = {
74 // check sorting values and decoding
75 {
76 "HTTP/1.1 202 Accepted \n"
bolian 2014/06/27 02:16:58 why 202?
77 "Chrome-Proxy: aut=aauutthh,fp=123,bbbypas=0,aaxxx=xxx,bbbloc=1\n",
bolian 2014/06/27 02:16:58 Either 1) Make it real. replace 123 with the valu
78
79 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
80 false,
81 },
82
83 // check sorting
84 {
85 "HTTP/1.1 202 Accepted \n"
86 "Chrome-Proxy: a,b,c,d,e,3,2,1,fp=1231\n",
87
88 "1,2,3,a,b,c,d,e,",
89 false,
90 },
91
92 // check no Chrome-Proxy header case (should not happen)
93 {
94 "HTTP/1.1 202 Accepted \n"
95 "Content-Length: 12345\n",
96
97 "",
98 false,
99 },
100
101 // check empty Chrome-Proxy header case (should not happen)
102 {
103 "HTTP/1.1 202 Accepted \n"
104 "Chrome-Proxy: \n",
105
106 ",",
107 false,
108 },
109
110 // check empty Chrome-Proxy header case
111 {
112 "HTTP/1.1 202 Accepted \n"
113 "Chrome-Proxy: fp=xyz\n",
114
115 "",
116 false,
117 },
118
119 // check empty Chrome-Proxy header case, with extra ","
120 {
121 "HTTP/1.1 202 Accepted \n"
122 "Chrome-Proxy: fp=abcde , \n",
123
124 "",
125 false,
126 },
127
128 // check empty Chrome-Proxy header, different fingerprint
129 {
130 "HTTP/1.1 202 Accepted \n"
131 "Chrome-Proxy: fp=xyz\n",
132
133 ",",
134 true,
135 },
136
137 // check regular Chrome-Proxy header, different fingerprint
138 {
139 "HTTP/1.1 202 Accepted \n"
140 "Chrome-Proxy: aut=aauutthh,bbbypas=2,aaxxx=xxx,bbbloc=1\n",
141
142 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
143 true,
144 },
145
146 // check regular Chrome-Proxy header, different fingerprint
147 {
148 "HTTP/1.1 202 Accepted \n"
149 "Chrome-Proxy: a,aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n",
150
151 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
152 true,
153 },
154
155 // check regular Chrome-Proxy header, with extra " "
156 {
157 "HTTP/1.1 202 Accepted \n"
158 "Chrome-Proxy: aut=aauutthh , bbbypas=0 , aaxxx=xxx"
159 " ,bbbloc=1 \n",
160
161 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
162 false
163 },
164
165 // check regular Chrome-Proxy header, with extra lines and " "
166 {
167 "HTTP/1.1 202 Accepted \n"
168 "Chrome-Proxy: aut=aauutthh , bbbypas=0 , bbbloc=1 \n"
169 "Chrome-Proxy: aaxxx=xxx \n",
170
171 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
172 false
173 },
174
175 // check Chrome-Proxy header with multiple lines
176 {
177 "HTTP/1.1 202 Accepted \n"
178 "Chrome-Proxy: aaxxx=xxx \n"
179 "Chrome-Proxy: aut=aauutthh\n"
180 "Chrome-Proxy: bbbypas=0\n"
181 "Chrome-Proxy:bbbloc=1 \n",
182
183 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
184 false
185 },
186
187 // check Chrome-Proxy header with multiple lines, at different position
188 // of the entire header
189 {
190 "HTTP/1.1 202 Accepted \n"
191 "Chrome-Proxy: aaxxx=xxx \n"
192 "Chrome-Proxy: aut=aauutthh\n"
193 "Content-Type: 1\n"
194 "Cache-Control: 2\n"
195 "ETag: 3\n"
196 "Chrome-Proxy: bbbypas=0\n"
197 "Connection: 4\n"
198 "Expires: 5\n"
199 "Chrome-Proxy: bbbloc=1\n"
200 "Via: \n"
201 "Content-Length: 12345\n",
202
203 "aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
204 false
205 },
206
207 // check Chrome-Proxy header with multiple same values
208 {
209 "HTTP/1.1 202 Accepted \n"
210 "Chrome-Proxy: aaxxx=xxx \n"
211 "Chrome-Proxy: aut=aauutthh\n"
212 "Content-Type: 1\n"
213 "Cache-Control: 2\n"
214 "ETag: 3\n"
215 "Chrome-Proxy: bbbypas=0\n"
216 "Connection: 4\n"
217 "Expires: 5\n"
218 "Chrome-Proxy: bbbloc=1, fp=123 \n"
219 "Chrome-Proxy: aaxxx=xxx \n"
220 "Via: \n"
221 "Content-Length: 12345\n",
222
223 "aaxxx=xxx,aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
224 false
225 },
226
227 // check Chrome-Proxy header with multiple same values,
228 // but different fingerprint
229 {
230 "HTTP/1.1 202 Accepted \n"
231 "Chrome-Proxy: aaxxx=xxx \n"
232 "Chrome-Proxy: aaxxx=xxx \n"
233 "Chrome-Proxy: aut=aauutthh\n"
234 "Content-Type: 1\n"
235 "Cache-Control: 2\n"
236 "ETag: 3\n"
237 "Chrome-Proxy: bbbypas=0\n"
238 "Connection: 4\n"
239 "Expires: 5\n"
240 "Chrome-Proxy: bbbloc=1\n"
241 "Chrome-Proxy: aaxxx=xxx \n"
242 "Via: \n"
243 "Content-Length: 12345\n",
244
245 "aaxxx=xxx,aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
246 true,
247 },
248
249 // check Chrome-Proxy header with multiple lines,
250 // but different fingerprint
251 {
252 "HTTP/1.1 202 Accepted \n"
253 "Content-Type: 1\n"
254 "Cache-Control: 2\n"
255 "ETag: 3\n"
256 "Chrome-Proxy: bbbypas=0\n"
257 "Connection: 4\n"
258 "Expires: 5\n"
259 "Chrome-Proxy: bbbloc=1\n"
260 "Chrome-Proxy: aaxxx=xxx \n"
261 "Via: \n"
262 "Content-Length: 12345\n",
263
264 "aaxxx=xxx,aaxxx=xxx,aut=aauutthh,bbbloc=1,bbbypas=0,",
265 true,
266 },
267
268 // check regular Chrome-Proxy header, but received fingerprint is empty
269 {
270 "HTTP/1.1 202 Accepted \n"
271 "Chrome-Proxy: aaxxx=xxx \n"
272 "Chrome-Proxy: aaxxx=xxx \n"
273 "Chrome-Proxy: aut=aauutthh\n"
274 "Content-Type: 1\n"
275 "Cache-Control: 2\n"
276 "ETag: 3\n"
277 "Chrome-Proxy: bbbypas=0\n"
278 "Connection: 4\n"
279 "Expires: 5\n"
280 "Chrome-Proxy: bbbloc=1\n"
281 "Chrome-Proxy: aaxxx=xxx \n"
282 "Via: \n"
283 "Content-Length: 12345\n",
284
285 "",
286 true,
287 },
288
289 };
290
291 for (size_t i=0; i<ARRAYSIZE_UNSAFE(test); ++i) {
292 test[i].received_fingerprint =
bolian 2014/06/27 02:16:58 don't rewrite the test field. Rename the field and
293 GetEncoded(test[i].received_fingerprint);
294 TestFingerprintCommon(test[i], 0);
295 LOG(WARNING) << "f1 " <<i;
296 }
297 }
298
299 TEST(DataReductionProxyTamperDetectTest, Via) {
300 TestCase test[] = {
301 // check regular case, where Chrome Proxy occurs at the last
302 {
303 "HTTP/1.1 202 Accepted \n"
304 "Via: a, b, c, Chrome Proxy\n",
bolian 2014/06/27 02:16:58 use the actual data reduction proxy via header val
305
306 "0",
307 false
308 },
309
310 // check when there is extra middlebox
311 // between data-reduction-proxy and phone
312 {
313 "HTTP/1.1 202 Accepted \n"
314 "Via: a, b, c, Chrome Proxy, xyz\n",
315
316 "0",
317 true,
318 },
319
320 // emtpy Via header, even no Chrome Proxy tag
321 {
322 "HTTP/1.1 202 Accepted \n"
323 "Via: \n",
324
325 "0",
326 false,
327 },
328
329 // only Chrome Proxy tag occurs in Via header
330 {
331 "HTTP/1.1 202 Accepted \n"
332 "Via: Chrome \n",
333
334 "0",
335 false
336 },
337
338 // there are " ", i.e., empty value after Chrome Proxy tag
339 // should not count as extra middleboxes
340 {
341 "HTTP/1.1 202 Accepted \n"
342 "Via: Chrome , , \n",
343
344 "0",
345 false
346 },
347
348 // special case when there is no Via header
349 {
350 "HTTP/1.1 202 Accepted \n",
351
352 "0",
353 false
354 },
355 };
356
357 for (size_t i=0; i<ARRAYSIZE_UNSAFE(test); ++i) {
358 TestFingerprintCommon(test[i], 1);
359 LOG(WARNING) << "Xing "<<i;
360 }
361 }
362
363 TEST(DataReductionProxyTamperDetectTest, OtherHeaders) {
364 TestCase test[] = {
365 // regular case, with correct fingerprint
366 {
367 "HTTP/1.1 202 Accepted \n"
368 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
369 "Content-Type: 1\n"
370 "Cache-Control: 2\n"
371 "ETag: 3\n"
372 "Connection: 4\n"
373 "Expires: 5\n"
374 "Via: \n"
375 "Content-Length: 12345\n",
376
377 "1,;2,;3,;4,;5,;:content-type:cache-control:etag:connection:expires",
378 false
379 },
380
381 // regular case, with correct fingerprint
382 {
383 "HTTP/1.1 202 Accepted \n"
384 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
385 "Content-Type: aaa1\n"
386 "Cache-Control: aaa2\n"
387 "ETag: aaa3\n"
388 "Connection: aaa4\n"
389 "Expires: aaa5\n"
390 "Via: \n"
391 "Content-Length: 12345\n",
392
393 "aaa1,;aaa2,;aaa3,;aaa4,;aaa5,;:content-type:cache-control:"
394 "etag:connection:expires",
395 false
396 },
397
398 // regular case, one header is with multiple values
399 {
400 "HTTP/1.1 202 Accepted \n"
401 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
402 "Content-Type: aaa1, bbb1, ccc1\n"
403 "Cache-Control: aaa2\n"
404 "ETag: aaa3\n"
405 "Connection: aaa4\n"
406 "Expires: aaa5\n"
407 "Via: \n"
408 "Content-Length: 12345\n",
409
410 "aaa1,bbb1,ccc1,;aaa2,;aaa3,;aaa4,;aaa5,;:"
411 "content-type:cache-control:etag:connection:expires",
412 false
413 },
414
415 // regular case, one header has multiple lines
416 {
417 "HTTP/1.1 202 Accepted \n"
418 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
419 "Content-Type: aaa1, ccc1\n"
420 "Content-Type: xxx1, bbb1, ccc1\n"
421 "Cache-Control: aaa2\n"
422 "ETag: aaa3\n"
423 "Connection: aaa4\n"
424 "Expires: aaa5\n"
425 "Via: \n"
426 "Content-Length: 12345\n",
427
428 "aaa1,bbb1,ccc1,ccc1,xxx1,;aaa2,;aaa3,;aaa4,;aaa5,;:"
429 "content-type:cache-control:etag:connection:expires",
430 false
431 },
432
433 // regular case, one header has multiple lines,
434 // and such multiple lines occur at different positions
435 {
436 "HTTP/1.1 202 Accepted \n"
437 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
438 "Content-Type: aaa1, ccc1\n"
439 "Cache-Control: aaa2\n"
440 "ETag: aaa3\n"
441 "Content-Type: xxx1, bbb1, ccc1\n"
442 "Connection: aaa4\n"
443 "Expires: aaa5\n"
444 "Via: \n"
445 "Content-Length: 12345\n",
446
447 "aaa1,bbb1,ccc1,ccc1,xxx1,;aaa2,;aaa3,;aaa4,;aaa5,;"
448 ":content-type:cache-control:etag:connection:expires",
449 false
450 },
451
452 // regular case, more than one header have multiple lines,
453 // and such multiple lines occur at different positions
454 {
455 "HTTP/1.1 202 Accepted \n"
456 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
457 "Content-Type: aaa1, ccc1\n"
458 "Cache-Control: ccc2 , bbb2\n"
459 "ETag: aaa3\n"
460 "Content-Type: xxx1, bbb1, ccc1\n"
461 "Connection: aaa4\n"
462 "Cache-Control: aaa2 \n"
463 "Expires: aaa5\n"
464 "Via: \n"
465 "Content-Length: 12345\n",
466
467 "aaa1,bbb1,ccc1,ccc1,xxx1,;aaa2,bbb2,ccc2,;aaa3,;aaa4,;aaa5,;:"
468 "content-type:cache-control:etag:connection:expires",
469 false
470 },
471
472 // regular case, response header does not have one header we need
473 // for fingerprint (expires)
474 {
475 "HTTP/1.1 202 Accepted \n"
476 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
477 "Content-Type: aaa1, ccc1\n"
478 "Cache-Control: ccc2 , bbb2\n"
479 "ETag: aaa3\n"
480 "Content-Type: xxx1, bbb1, ccc1\n"
481 "Connection: aaa4\n"
482 "Cache-Control: aaa2 \n"
483 "Via: \n"
484 "Content-Length: 12345\n",
485
486 "aaa1,bbb1,ccc1,ccc1,xxx1,;aaa2,bbb2,ccc2,;aaa3,;aaa4,;;:"
487 "content-type:cache-control:etag:connection:expires",
488 false
489 },
490
491 // regular case, response header does not have more than one header
492 // we need for fingerprint (content-type, expires)
493 {
494 "HTTP/1.1 202 Accepted \n"
495 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
496 "Cache-Control: ccc2 , bbb2\n"
497 "ETag: aaa3\n"
498 "Connection: aaa4\n"
499 "Cache-Control: aaa2 \n"
500 "Via: \n"
501 "Content-Length: 12345\n",
502
503 ";aaa2,bbb2,ccc2,;aaa3,;aaa4,;;:content-type:cache-control:"
504 "etag:connection:expires",
505 false
506 },
507
508 // regular case, all the headers we need for fingerprint are missing
509 {
510 "HTTP/1.1 202 Accepted \n"
511 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
512 "Via: \n"
513 "Content-Length: 12345\n",
514
515 ";;;;;:content-type:cache-control:etag:connection:expires",
516 false
517 },
518
519 // regular case, but differ to received fingerprint
520 {
521 "HTTP/1.1 202 Accepted \n"
522 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
523 "Content-Type: aaa1, ccc1\n"
524 "Cache-Control: ccc2 , bbb2\n"
525 "ETag: etag\n"
526 "Content-Type: xxx1, bbb1, ccc1\n"
527 "Connection: aaa4\n"
528 "Cache-Control: aaa2 \n"
529 "Via: \n"
530 "Content-Length: 12345\n",
531
532 "aaa1,bbb1,ccc1,ccc1,xxx1,;aaa2,bbb2,ccc2,;aaa3,;aaa4,;;:"
533 "content-type:cache-control:etag:connection:expires",
534 true,
535 },
536
537 // special case, headers are not missing but some of them are empty
538 {
539 "HTTP/1.1 202 Accepted \n"
540 "Content-Type: \n"
541 "Cache-Control: \n"
542 "ETag: \n"
543 "Connection: \n"
544 "Expires: 5\n"
545 "Via: \n"
546 "Content-Length: 12345\n",
547
548 ",;,;,;,;5,;:content-type:cache-control:etag:connection:expires",
549 false
550 },
551
552 // special case, some headers do not exist, some are of empty value.
553 // check delimiter "," and ";" work correctly.
554 {
555 "HTTP/1.1 202 Accepted \n"
556 "Cache-Control: \n"
557 "Connection: \n"
558 "Expires: 5\n"
559 "Via: \n"
560 "Content-Length: 12345\n",
561
562 ";,;;,;5,;:content-type:cache-control:etag:connection:expires",
563 false
564 },
565
566 // special case, check if we don't check any header, i.e.,
567 // header list is empty
568 {
569 "HTTP/1.1 202 Accepted \n"
570 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
571 "Content-Type: 1\n"
572 "Cache-Control: 2\n"
573 "ETag: 3\n"
574 "Connection: 4\n"
575 "Expires: 5\n"
576 "Via: \n"
577 "Content-Length: 12345\n",
578
579 "",
580 false
581 },
582
583 // special case, we only want to check one header, which does not
584 // exist in received header
585 {
586 "HTTP/1.1 202 Accepted \n"
587 "Chrome-Proxy: aut=aauutthh,bbbypas=0,aaxxx=xxx,bbbloc=1\n"
588 "Content-Type: 1\n"
589 "Cache-Control: 2\n"
590 "ETag: 3\n"
591 "Connection: 4\n"
592 "Expires: 5\n"
593 "Via: \n"
594 "Content-Length: 12345\n",
595
596 ";:non_exist_header",
597 false
598 },
599
600 // there is only one header in our header list
601 {
602 "HTTP/1.1 202 Accepted \n"
603 "Cache-Control: \n"
604 "Connection: \n"
605 "Expires: 5\n"
606 "Via: \n"
607 "Content-Length: 12345\n",
608
609 ";:content-type",
610 false
611 },
612
613 // special case, if base64 decoding fails
614 {
615 "HTTP/1.1 202 Accepted \n"
616 "Cache-Control: \n"
617 "Connection: \n"
618 "Expires: 5\n"
619 "Via: \n"
620 "Content-Length: 12345\n",
621
622 ";:content-type",
623 false
624 },
625
626 // special case, if base64 decoding fails
627 {
628 "HTTP/1.1 202 Accepted \n"
629 "Cache-Control: \n"
630 "Connection: \n"
631 "Expires: 5\n"
632 "Via: \n"
633 "Content-Length: 12345\n",
634
635 "abcde:content-type:cache-control:etag:connection:expires",
636 false
637 },
638 };
639
640 for (size_t i=0; i<ARRAYSIZE_UNSAFE(test); ++i) {
641 if (i >= ARRAYSIZE_UNSAFE(test) - 2)
642 {
643 TestFingerprintCommon(test[i], 2);
644 continue;
645 }
646 size_t delimiter_pos = test[i].received_fingerprint.find(":");
647 std::string hash, rest;
648 if (delimiter_pos == std::string::npos)
649 {
650 delimiter_pos = test[i].received_fingerprint.size();
651 rest = "";
652 }
653 else
654 rest = test[i].received_fingerprint.substr(
655 delimiter_pos,
656 test[i].received_fingerprint.size() - delimiter_pos);
657 hash = test[i].received_fingerprint.substr(0, delimiter_pos);
658 test[i].received_fingerprint = GetEncoded(hash) + rest;
659
660 TestFingerprintCommon(test[i], 2);
661 }
662 }
663
664 TEST(DataReductionProxyTamperDetectTest, ContentLength) {
665 TestCase test[] = {
666 // regular case, content-length is the same
667 {
668 "HTTP/1.1 202 Accepted \n"
669 "Content-Type: 1\n"
670 "Content-Length: 12345\n",
671
672 "12345",
673 false,
674 },
675
676 // regular case, content-length is not the same
677 // also check if retrieved content-type is correct
678 {
679 "HTTP/1.1 202 Accepted \n"
680 "Content-Type: text/html; charset=ISO-8859-4\n"
681 "Content-Length: 12345\n",
682
683 "125",
684 true,
685 },
686
687 // special case, data reduction proxy does not sent content-length
688 // i.e., content-length at data reduction proxy side is missing
689 {
690 "HTTP/1.1 202 Accepted \n"
691 "Content-Type: text/javascript\n"
692 "Content-Length: 12345\n",
693
694 "",
695 false,
696 },
697
698 // special case, content-length are missing at both end
699 // i.e., both data reduction proxy and chrome
700 {
701 "HTTP/1.1 202 Accepted \n"
702 "Content-Type: 1\n",
703
704 "",
705 false,
706 },
707
708 // special case, check when content-length is 0
709 {
710 "HTTP/1.1 202 Accepted \n"
711 "Content-Type: application/x-javascript\n"
712 "Content-Length: 0\n",
713
714 "0",
715 false,
716 },
717
718 // special case, check when data reduction proxy side's
719 // content-length is empty (header exist, but value is empty)
720 {
721 "HTTP/1.1 202 Accepted \n"
722 "Content-Type: application/x-javascript\n"
723 "Content-Length: 123\n",
724
725 ",",
726 false,
727 },
728
729 // when content-length is different, check whether it recognizes image.
730 {
731 "HTTP/1.1 202 Accepted \n"
732 "Content-Type: image/gif \n"
733 "Content-Length: 123\n",
734
735 "0",
736 true,
737 },
738
739 // when content-length is different, check whether it recognizes JS
740 {
741 "HTTP/1.1 202 Accepted \n"
742 "Content-Type: application/x-javascript \n"
743 "Content-Length: 0\n",
744
745 "120",
746 true,
747 },
748
749 // when content-length is different, check whether it recognizes JS
750 {
751 "HTTP/1.1 202 Accepted \n"
752 "Content-Type: text/javascript \n"
753 "Content-Length: 123\n",
754
755 "0",
756 true,
757 },
758
759 // when content-length is different, check whether it recognizes CSS
760 {
761 "HTTP/1.1 202 Accepted \n"
762 "Content-Type: text/css\n"
763 "Content-Length: 111\n",
764
765 "0",
766 true,
767 },
768
769 // when content-length is different (chrome side is missing),
770 // check whether it recognizes JS.
771 // (if phone side's content-length has been removed, shall we report?
772 // current implementation: not reporting.)
773 {
774 "HTTP/1.1 202 Accepted \n"
775 "Content-Type: application/javascript \n",
776
777 "123",
778 false,
779 },
780
781 };
782
783 for (size_t i=0; i<ARRAYSIZE_UNSAFE(test); ++i) {
784 TestFingerprintCommon(test[i], 3);
785 }
786 }
787
788 TEST(DataReductionProxyTamperDetectTest, Parsing) {
789 std::string test[] = {
790 // check normal case
791 "Chrome-Proxy: f1:f1&f2:f2&f3:f3&f4:f4\n",
792 "Chrome-Proxy: fp=aa|bb|cc|dd\n",
793 // check special case if there are more delimiters
794 "Chrome-Proxy: fp=||||||||\n",
795 "Chrome-Proxy: fp=a|a|a|a|a|a|a|\n",
796 // check if there is no Chrome-Proxy header
797 "Content-Type: text/css\n",
798 // check if there is less delimiters
799 "Chrome-Proxy: fp= a | b | cde \n",
800 "Chrome-Proxy: a=1, b=2, c=5",
801 };
802
803 for (size_t i=0; i<ARRAYSIZE_UNSAFE(test); ++i) {
804 TestParsingCommon(test[i]);
805 }
806 }
807
808 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698