| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 5 |
| 6 #include "base/base64.h" | 6 #include "base/base64.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 HitReport base_hp; | 81 HitReport base_hp; |
| 82 base_hp.malicious_url = GURL("http://malicious.url.com"); | 82 base_hp.malicious_url = GURL("http://malicious.url.com"); |
| 83 base_hp.page_url = GURL("http://page.url.com"); | 83 base_hp.page_url = GURL("http://page.url.com"); |
| 84 base_hp.referrer_url = GURL("http://referrer.url.com"); | 84 base_hp.referrer_url = GURL("http://referrer.url.com"); |
| 85 | 85 |
| 86 { | 86 { |
| 87 HitReport hp(base_hp); | 87 HitReport hp(base_hp); |
| 88 hp.threat_type = SB_THREAT_TYPE_URL_MALWARE; | 88 hp.threat_type = SB_THREAT_TYPE_URL_MALWARE; |
| 89 hp.threat_source = ThreatSource::LOCAL_PVER3; | 89 hp.threat_source = ThreatSource::LOCAL_PVER3; |
| 90 hp.is_subresource = true; | 90 hp.is_subresource = true; |
| 91 hp.is_extended_reporting = true; | 91 hp.extended_reporting_level = SBER_LEVEL_LEGACY; |
| 92 hp.is_metrics_reporting_active = true; | 92 hp.is_metrics_reporting_active = true; |
| 93 | 93 |
| 94 EXPECT_EQ( | 94 EXPECT_EQ( |
| 95 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 95 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 96 "pver=3.0" + | 96 "pver=3.0" + |
| 97 key_param_ + | 97 key_param_ + |
| 98 "&ext=1&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 98 "&ext=1&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 99 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 99 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 100 "url.com%2F&evtb=1&src=l3&m=1", | 100 "url.com%2F&evtb=1&src=l3&m=1", |
| 101 ping_manager()->SafeBrowsingHitUrl(hp).spec()); | 101 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 { | 104 { |
| 105 HitReport hp(base_hp); | 105 HitReport hp(base_hp); |
| 106 hp.threat_type = SB_THREAT_TYPE_URL_PHISHING; | 106 hp.threat_type = SB_THREAT_TYPE_URL_PHISHING; |
| 107 hp.threat_source = ThreatSource::DATA_SAVER; | 107 hp.threat_source = ThreatSource::DATA_SAVER; |
| 108 hp.is_subresource = false; | 108 hp.is_subresource = false; |
| 109 hp.is_extended_reporting = true; | 109 hp.extended_reporting_level = SBER_LEVEL_LEGACY; |
| 110 hp.is_metrics_reporting_active = true; | 110 hp.is_metrics_reporting_active = true; |
| 111 EXPECT_EQ( | 111 EXPECT_EQ( |
| 112 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 112 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 113 "pver=3.0" + | 113 "pver=3.0" + |
| 114 key_param_ + | 114 key_param_ + |
| 115 "&ext=1&evts=phishblhit&" | 115 "&ext=1&evts=phishblhit&" |
| 116 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 116 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 117 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 117 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 118 "url.com%2F&evtb=0&src=ds&m=1", | 118 "url.com%2F&evtb=0&src=ds&m=1", |
| 119 ping_manager()->SafeBrowsingHitUrl(hp).spec()); | 119 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 { | 122 { |
| 123 HitReport hp(base_hp); | 123 HitReport hp(base_hp); |
| 124 hp.threat_type = SB_THREAT_TYPE_URL_PHISHING; |
| 125 hp.threat_source = ThreatSource::DATA_SAVER; |
| 126 hp.is_subresource = false; |
| 127 hp.extended_reporting_level = SBER_LEVEL_SCOUT; |
| 128 hp.is_metrics_reporting_active = true; |
| 129 EXPECT_EQ( |
| 130 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 131 "pver=3.0" + |
| 132 key_param_ + |
| 133 "&ext=2&evts=phishblhit&" |
| 134 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 135 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 136 "url.com%2F&evtb=0&src=ds&m=1", |
| 137 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 138 } |
| 139 |
| 140 { |
| 141 HitReport hp(base_hp); |
| 124 hp.threat_type = SB_THREAT_TYPE_BINARY_MALWARE_URL; | 142 hp.threat_type = SB_THREAT_TYPE_BINARY_MALWARE_URL; |
| 125 hp.threat_source = ThreatSource::REMOTE; | 143 hp.threat_source = ThreatSource::REMOTE; |
| 126 hp.is_extended_reporting = false; | 144 hp.extended_reporting_level = SBER_LEVEL_OFF; |
| 127 hp.is_metrics_reporting_active = true; | 145 hp.is_metrics_reporting_active = true; |
| 128 hp.is_subresource = false; | 146 hp.is_subresource = false; |
| 129 EXPECT_EQ( | 147 EXPECT_EQ( |
| 130 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 148 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 131 "pver=3.0" + | 149 "pver=3.0" + |
| 132 key_param_ + | 150 key_param_ + |
| 133 "&ext=0&evts=binurlhit&" | 151 "&ext=0&evts=binurlhit&" |
| 134 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 152 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 135 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 153 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 136 "url.com%2F&evtb=0&src=rem&m=1", | 154 "url.com%2F&evtb=0&src=rem&m=1", |
| 137 ping_manager()->SafeBrowsingHitUrl(hp).spec()); | 155 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 138 } | 156 } |
| 139 | 157 |
| 140 { | 158 { |
| 141 HitReport hp(base_hp); | 159 HitReport hp(base_hp); |
| 142 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; | 160 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL; |
| 143 hp.threat_source = ThreatSource::LOCAL_PVER4; | 161 hp.threat_source = ThreatSource::LOCAL_PVER4; |
| 144 hp.is_extended_reporting = false; | 162 hp.extended_reporting_level = SBER_LEVEL_OFF; |
| 145 hp.is_metrics_reporting_active = false; | 163 hp.is_metrics_reporting_active = false; |
| 146 hp.is_subresource = false; | 164 hp.is_subresource = false; |
| 147 EXPECT_EQ( | 165 EXPECT_EQ( |
| 148 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 166 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 149 "pver=3.0" + | 167 "pver=3.0" + |
| 150 key_param_ + | 168 key_param_ + |
| 151 "&ext=0&evts=phishcsdhit&" | 169 "&ext=0&evts=phishcsdhit&" |
| 152 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 170 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 153 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 171 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 154 "url.com%2F&evtb=0&src=l4&m=0", | 172 "url.com%2F&evtb=0&src=l4&m=0", |
| 155 ping_manager()->SafeBrowsingHitUrl(hp).spec()); | 173 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 156 } | 174 } |
| 157 | 175 |
| 158 { | 176 { |
| 159 HitReport hp(base_hp); | 177 HitReport hp(base_hp); |
| 160 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; | 178 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 161 hp.threat_source = ThreatSource::LOCAL_PVER4; | 179 hp.threat_source = ThreatSource::LOCAL_PVER4; |
| 162 hp.is_extended_reporting = false; | 180 hp.extended_reporting_level = SBER_LEVEL_OFF; |
| 163 hp.is_metrics_reporting_active = false; | 181 hp.is_metrics_reporting_active = false; |
| 164 hp.is_subresource = true; | 182 hp.is_subresource = true; |
| 165 EXPECT_EQ( | 183 EXPECT_EQ( |
| 166 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 184 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 167 "pver=3.0" + | 185 "pver=3.0" + |
| 168 key_param_ + | 186 key_param_ + |
| 169 "&ext=0&evts=malcsdhit&" | 187 "&ext=0&evts=malcsdhit&" |
| 170 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 188 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 171 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 189 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| 172 "url.com%2F&evtb=1&src=l4&m=0", | 190 "url.com%2F&evtb=1&src=l4&m=0", |
| 173 ping_manager()->SafeBrowsingHitUrl(hp).spec()); | 191 ping_manager()->SafeBrowsingHitUrl(hp).spec()); |
| 174 } | 192 } |
| 175 | 193 |
| 176 // Same as above, but add population_id | 194 // Same as above, but add population_id |
| 177 { | 195 { |
| 178 HitReport hp(base_hp); | 196 HitReport hp(base_hp); |
| 179 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; | 197 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 180 hp.threat_source = ThreatSource::LOCAL_PVER4; | 198 hp.threat_source = ThreatSource::LOCAL_PVER4; |
| 181 hp.is_extended_reporting = false; | 199 hp.extended_reporting_level = SBER_LEVEL_OFF; |
| 182 hp.is_metrics_reporting_active = false; | 200 hp.is_metrics_reporting_active = false; |
| 183 hp.is_subresource = true; | 201 hp.is_subresource = true; |
| 184 hp.population_id = "foo bar"; | 202 hp.population_id = "foo bar"; |
| 185 EXPECT_EQ( | 203 EXPECT_EQ( |
| 186 "https://prefix.com/foo/report?client=unittest&appver=1.0&" | 204 "https://prefix.com/foo/report?client=unittest&appver=1.0&" |
| 187 "pver=3.0" + | 205 "pver=3.0" + |
| 188 key_param_ + | 206 key_param_ + |
| 189 "&ext=0&evts=malcsdhit&" | 207 "&ext=0&evts=malcsdhit&" |
| 190 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" | 208 "evtd=http%3A%2F%2Fmalicious.url.com%2F&" |
| 191 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." | 209 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer." |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 const std::string kHitReportPostData = "Hit Report POST Data"; | 277 const std::string kHitReportPostData = "Hit Report POST Data"; |
| 260 std::string encoded_post_data = ""; | 278 std::string encoded_post_data = ""; |
| 261 base::Base64Encode(kHitReportPostData, &encoded_post_data); | 279 base::Base64Encode(kHitReportPostData, &encoded_post_data); |
| 262 | 280 |
| 263 HitReport hp; | 281 HitReport hp; |
| 264 hp.malicious_url = GURL("http://malicious.url.com"); | 282 hp.malicious_url = GURL("http://malicious.url.com"); |
| 265 hp.page_url = GURL("http://page.url.com"); | 283 hp.page_url = GURL("http://page.url.com"); |
| 266 hp.referrer_url = GURL("http://referrer.url.com"); | 284 hp.referrer_url = GURL("http://referrer.url.com"); |
| 267 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; | 285 hp.threat_type = SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL; |
| 268 hp.threat_source = ThreatSource::LOCAL_PVER4; | 286 hp.threat_source = ThreatSource::LOCAL_PVER4; |
| 269 hp.is_extended_reporting = false; | 287 hp.extended_reporting_level = SBER_LEVEL_OFF; |
| 270 hp.is_metrics_reporting_active = false; | 288 hp.is_metrics_reporting_active = false; |
| 271 hp.is_subresource = true; | 289 hp.is_subresource = true; |
| 272 hp.population_id = "foo bar"; | 290 hp.population_id = "foo bar"; |
| 273 hp.post_data = kHitReportPostData; | 291 hp.post_data = kHitReportPostData; |
| 274 std::string expected_hit_report_url = ping_manager()->SafeBrowsingHitUrl(hp) | 292 std::string expected_hit_report_url = ping_manager()->SafeBrowsingHitUrl(hp) |
| 275 .spec(); | 293 .spec(); |
| 276 const int kRequestErrorCode = -321; | 294 const int kRequestErrorCode = -321; |
| 277 | 295 |
| 278 // Start the report. | 296 // Start the report. |
| 279 ping_manager()->ReportSafeBrowsingHit(hp); | 297 ping_manager()->ReportSafeBrowsingHit(hp); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 kReportURL); | 381 kReportURL); |
| 364 ping_manager->ReportInvalidCertificateChain("report"); | 382 ping_manager->ReportInvalidCertificateChain("report"); |
| 365 base::RunLoop().RunUntilIdle(); | 383 base::RunLoop().RunUntilIdle(); |
| 366 | 384 |
| 367 histograms.ExpectTotalCount(kFailureHistogramName, 1); | 385 histograms.ExpectTotalCount(kFailureHistogramName, 1); |
| 368 histograms.ExpectBucketCount(kFailureHistogramName, | 386 histograms.ExpectBucketCount(kFailureHistogramName, |
| 369 -net::ERR_CONNECTION_FAILED, 1); | 387 -net::ERR_CONNECTION_FAILED, 1); |
| 370 } | 388 } |
| 371 | 389 |
| 372 } // namespace safe_browsing | 390 } // namespace safe_browsing |
| OLD | NEW |