OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/safe_browsing/malware_details.h" | 10 #include "chrome/browser/safe_browsing/malware_details.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 static const char* kLandingData = "<iframe src='http://www.malware.com'>"; | 49 static const char* kLandingData = "<iframe src='http://www.malware.com'>"; |
50 | 50 |
51 using safe_browsing::ClientMalwareReportRequest; | 51 using safe_browsing::ClientMalwareReportRequest; |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 void WriteHeaders(disk_cache::Entry* entry, const std::string headers) { | 55 void WriteHeaders(disk_cache::Entry* entry, const std::string headers) { |
56 net::HttpResponseInfo responseinfo; | 56 net::HttpResponseInfo responseinfo; |
57 std::string raw_headers = net::HttpUtil::AssembleRawHeaders( | 57 std::string raw_headers = net::HttpUtil::AssembleRawHeaders( |
58 headers.c_str(), headers.size()); | 58 headers.c_str(), headers.size()); |
| 59 responseinfo.socket_address = net::HostPortPair("1.2.3.4", 80); |
59 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); | 60 responseinfo.headers = new net::HttpResponseHeaders(raw_headers); |
60 | 61 |
61 Pickle pickle; | 62 Pickle pickle; |
62 responseinfo.Persist(&pickle, false, false); | 63 responseinfo.Persist(&pickle, false, false); |
63 | 64 |
64 scoped_refptr<net::WrappedIOBuffer> buf(new net::WrappedIOBuffer( | 65 scoped_refptr<net::WrappedIOBuffer> buf(new net::WrappedIOBuffer( |
65 reinterpret_cast<const char*>(pickle.data()))); | 66 reinterpret_cast<const char*>(pickle.data()))); |
66 int len = static_cast<int>(pickle.size()); | 67 int len = static_cast<int>(pickle.size()); |
67 | 68 |
68 TestCompletionCallback cb; | 69 TestCompletionCallback cb; |
(...skipping 20 matching lines...) Expand all Loading... |
89 disk_cache::Entry* entry; | 90 disk_cache::Entry* entry; |
90 int rv = cache->CreateEntry(key, &entry, &cb); | 91 int rv = cache->CreateEntry(key, &entry, &cb); |
91 rv = cb.GetResult(rv); | 92 rv = cb.GetResult(rv); |
92 if (rv != net::OK) { | 93 if (rv != net::OK) { |
93 rv = cache->OpenEntry(key, &entry, &cb); | 94 rv = cache->OpenEntry(key, &entry, &cb); |
94 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 95 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
95 } | 96 } |
96 | 97 |
97 WriteHeaders(entry, headers); | 98 WriteHeaders(entry, headers); |
98 WriteData(entry, data); | 99 WriteData(entry, data); |
99 | |
100 entry->Close(); | 100 entry->Close(); |
101 } | 101 } |
102 | 102 |
103 void FillCache(net::URLRequestContext* context) { | 103 void FillCache(net::URLRequestContext* context) { |
104 TestCompletionCallback cb; | 104 TestCompletionCallback cb; |
105 disk_cache::Backend* cache; | 105 disk_cache::Backend* cache; |
106 int rv = | 106 int rv = |
107 context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); | 107 context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); |
108 ASSERT_EQ(net::OK, cb.GetResult(rv)); | 108 ASSERT_EQ(net::OK, cb.GetResult(rv)); |
109 | 109 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 EXPECT_EQ(expected->response().headers(i).value(), | 269 EXPECT_EQ(expected->response().headers(i).value(), |
270 resource->response().headers(i).value()); | 270 resource->response().headers(i).value()); |
271 } | 271 } |
272 | 272 |
273 EXPECT_EQ(expected->response().body(), resource->response().body()); | 273 EXPECT_EQ(expected->response().body(), resource->response().body()); |
274 EXPECT_EQ(expected->response().bodylength(), | 274 EXPECT_EQ(expected->response().bodylength(), |
275 resource->response().bodylength()); | 275 resource->response().bodylength()); |
276 EXPECT_EQ(expected->response().bodydigest(), | 276 EXPECT_EQ(expected->response().bodydigest(), |
277 resource->response().bodydigest()); | 277 resource->response().bodydigest()); |
278 } | 278 } |
| 279 |
| 280 // Verify IP:port pair |
| 281 EXPECT_EQ(expected->response().remote_ip(), |
| 282 resource->response().remote_ip()); |
279 } | 283 } |
280 | 284 |
281 BrowserThread ui_thread_; | 285 BrowserThread ui_thread_; |
282 BrowserThread io_thread_; | 286 BrowserThread io_thread_; |
283 scoped_refptr<MockSafeBrowsingService> sb_service_; | 287 scoped_refptr<MockSafeBrowsingService> sb_service_; |
284 }; | 288 }; |
285 | 289 |
286 // Tests creating a simple malware report. | 290 // Tests creating a simple malware report. |
287 TEST_F(MalwareDetailsTest, MalwareSubResource) { | 291 TEST_F(MalwareDetailsTest, MalwareSubResource) { |
288 // Start a load. | 292 // Start a load. |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 pb_header->set_value("text/html"); | 531 pb_header->set_value("text/html"); |
528 pb_header = pb_response->add_headers(); | 532 pb_header = pb_response->add_headers(); |
529 pb_header->set_name("Content-Length"); | 533 pb_header->set_name("Content-Length"); |
530 pb_header->set_value("1024"); | 534 pb_header->set_value("1024"); |
531 pb_header = pb_response->add_headers(); | 535 pb_header = pb_response->add_headers(); |
532 pb_header->set_name("Set-Cookie"); | 536 pb_header->set_name("Set-Cookie"); |
533 pb_header->set_value(""); // The cookie is dropped. | 537 pb_header->set_value(""); // The cookie is dropped. |
534 pb_response->set_body(kLandingData); | 538 pb_response->set_body(kLandingData); |
535 pb_response->set_bodylength(37); | 539 pb_response->set_bodylength(37); |
536 pb_response->set_bodydigest("9ca97475598a79bc1e8fc9bd6c72cd35"); | 540 pb_response->set_bodydigest("9ca97475598a79bc1e8fc9bd6c72cd35"); |
| 541 pb_response->set_remote_ip("1.2.3.4:80"); |
537 | 542 |
538 pb_resource = expected.add_resources(); | 543 pb_resource = expected.add_resources(); |
539 pb_resource->set_id(1); | 544 pb_resource->set_id(1); |
540 pb_resource->set_url(kMalwareURL); | 545 pb_resource->set_url(kMalwareURL); |
541 pb_response = pb_resource->mutable_response(); | 546 pb_response = pb_resource->mutable_response(); |
542 pb_response->mutable_firstline()->set_code(200); | 547 pb_response->mutable_firstline()->set_code(200); |
543 pb_header = pb_response->add_headers(); | 548 pb_header = pb_response->add_headers(); |
544 pb_header->set_name("Content-Type"); | 549 pb_header->set_name("Content-Type"); |
545 pb_header->set_value("image/jpeg"); | 550 pb_header->set_value("image/jpeg"); |
546 pb_response->set_body(kMalwareData); | 551 pb_response->set_body(kMalwareData); |
547 pb_response->set_bodylength(10); | 552 pb_response->set_bodylength(10); |
548 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); | 553 pb_response->set_bodydigest("581373551c43d4cf33bfb3b26838ff95"); |
| 554 pb_response->set_remote_ip("1.2.3.4:80"); |
549 expected.set_complete(true); | 555 expected.set_complete(true); |
550 | 556 |
551 VerifyResults(actual, expected); | 557 VerifyResults(actual, expected); |
552 } | 558 } |
553 | 559 |
554 // Tests the interaction with the HTTP cache (where the cache is empty). | 560 // Tests the interaction with the HTTP cache (where the cache is empty). |
555 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { | 561 TEST_F(MalwareDetailsTest, HTTPCacheNoEntries) { |
556 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED); | 562 controller().LoadURL(GURL(kLandingURL), GURL(), PageTransition::TYPED); |
557 | 563 |
558 SafeBrowsingService::UnsafeResource resource; | 564 SafeBrowsingService::UnsafeResource resource; |
(...skipping 26 matching lines...) Expand all Loading... |
585 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); | 591 ClientMalwareReportRequest::Resource* pb_resource = expected.add_resources(); |
586 pb_resource->set_id(0); | 592 pb_resource->set_id(0); |
587 pb_resource->set_url(kLandingURL); | 593 pb_resource->set_url(kLandingURL); |
588 pb_resource = expected.add_resources(); | 594 pb_resource = expected.add_resources(); |
589 pb_resource->set_id(1); | 595 pb_resource->set_id(1); |
590 pb_resource->set_url(kMalwareURL); | 596 pb_resource->set_url(kMalwareURL); |
591 expected.set_complete(true); | 597 expected.set_complete(true); |
592 | 598 |
593 VerifyResults(actual, expected); | 599 VerifyResults(actual, expected); |
594 } | 600 } |
OLD | NEW |