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");
46 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
47 "pver=3.0" + key_param_
+
48 "&evts=malblhit&evtd=http%3A%2F%2Fmalicious.url.com%2F&"
49 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
51 pm
.SafeBrowsingHitUrl(
52 malicious_url
, page_url
, referrer_url
,
53 true, SB_THREAT_TYPE_URL_MALWARE
).spec());
55 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
56 "pver=3.0" + key_param_
+ "&evts=phishblhit&"
57 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
58 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
60 pm
.SafeBrowsingHitUrl(
61 malicious_url
, page_url
, referrer_url
,
62 false, SB_THREAT_TYPE_URL_PHISHING
).spec());
64 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
65 "pver=3.0" + key_param_
+ "&evts=binurlhit&"
66 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
67 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
69 pm
.SafeBrowsingHitUrl(
70 malicious_url
, page_url
, referrer_url
,
71 false, SB_THREAT_TYPE_BINARY_MALWARE_URL
).spec());
73 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
74 "pver=3.0" + key_param_
+ "&evts=phishcsdhit&"
75 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
76 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
78 pm
.SafeBrowsingHitUrl(
79 malicious_url
, page_url
, referrer_url
,
80 false, SB_THREAT_TYPE_CLIENT_SIDE_PHISHING_URL
).spec());
82 EXPECT_EQ("https://prefix.com/foo/report?client=unittest&appver=1.0&"
83 "pver=3.0" + key_param_
+ "&evts=malcsdhit&"
84 "evtd=http%3A%2F%2Fmalicious.url.com%2F&"
85 "evtr=http%3A%2F%2Fpage.url.com%2F&evhr=http%3A%2F%2Freferrer."
87 pm
.SafeBrowsingHitUrl(
88 malicious_url
, page_url
, referrer_url
,
89 true, SB_THREAT_TYPE_CLIENT_SIDE_MALWARE_URL
).spec());
92 TEST_F(SafeBrowsingPingManagerTest
, TestMalwareDetailsUrl
) {
93 SafeBrowsingProtocolConfig config
;
94 config
.client_name
= kClient
;
95 config
.url_prefix
= kUrlPrefix
;
96 SafeBrowsingPingManager
pm(NULL
, config
);
98 pm
.version_
= kAppVer
;
99 EXPECT_EQ("https://prefix.com/foo/clientreport/malware?"
100 "client=unittest&appver=1.0&pver=1.0" + key_param_
,
101 pm
.MalwareDetailsUrl().spec());