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
3 // found in the LICENSE file.
6 #include "base/logging.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/time/time.h"
9 #include "chrome/browser/safe_browsing/ping_manager.h"
10 #include "google_apis/google_api_keys.h"
11 #include "net/base/escape.h"
12 #include "testing/gtest/include/gtest/gtest.h"
15 using base::TimeDelta
;
17 static const char kUrlPrefix
[] = "https://prefix.com/foo";
18 static const char kClient
[] = "unittest";
19 static const char kAppVer
[] = "1.0";
21 class SafeBrowsingPingManagerTest
: public testing::Test
{
23 std::string key_param_
;
25 void SetUp() override
{
26 std::string key
= google_apis::GetAPIKey();
28 key_param_
= base::StringPrintf(
30 net::EscapeQueryParamValue(key
, true).c_str());
35 TEST_F(SafeBrowsingPingManagerTest
, TestSafeBrowsingHitUrl
) {
36 SafeBrowsingProtocolConfig config
;
37 config
.client_name
= kClient
;
38 config
.url_prefix
= kUrlPrefix
;
39 SafeBrowsingPingManager
pm(NULL
, config
);
41 pm
.version_
= kAppVer
;
43 GURL
malicious_url("http://malicious.url.com");
44 GURL
page_url("http://page.url.com");
45 GURL
referrer_url("http://referrer.url.com");
47 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
50 "&ext=1&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&"
51 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
53 pm
.SafeBrowsingHitUrl(malicious_url
, page_url
, referrer_url
, true,
54 SB_THREAT_TYPE_URL_MALWARE
, true).spec());
57 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
60 "&ext=1&evts=phishblhit&"
61 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
62 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
64 pm
.SafeBrowsingHitUrl(malicious_url
, page_url
, referrer_url
, false,
65 SB_THREAT_TYPE_URL_PHISHING
, true).spec());
68 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
71 "&ext=0&evts=binurlhit&"
72 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
73 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
75 pm
.SafeBrowsingHitUrl(malicious_url
, page_url
, referrer_url
, false,
76 SB_THREAT_TYPE_BINARY_MALWARE_URL
, false).spec());
79 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
82 "&ext=0&evts=phishcsdhit&"
83 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
84 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
86 pm
.SafeBrowsingHitUrl(malicious_url
, page_url
, referrer_url
, false,
87 SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL
,
91 "https://prefix.com/foo/report?client=unittest&appver=1.0&"
94 "&ext=0&evts=malcsdhit&"
95 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
96 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
98 pm
.SafeBrowsingHitUrl(malicious_url
, page_url
, referrer_url
, true,
99 SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL
,
103 TEST_F(SafeBrowsingPingManagerTest
, TestMalwareDetailsUrl
) {
104 SafeBrowsingProtocolConfig config
;
105 config
.client_name
= kClient
;
106 config
.url_prefix
= kUrlPrefix
;
107 SafeBrowsingPingManager
pm(NULL
, config
);
109 pm
.version_
= kAppVer
;
110 EXPECT_EQ("https://prefix.com/foo/clientreport/malware?"
111 "client=unittest&appver=1.0&pver=1.0" + key_param_
,
112 pm
.MalwareDetailsUrl().spec());