OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 "chrome/browser/net/chrome_certificate_reporter.h" | |
6 | |
7 #include "base/files/file_util.h" | |
8 #include "chrome/browser/net/cert_logger.pb.h" | |
9 #include "content/public/test/test_browser_thread.h" | |
10 #include "net/base/test_data_directory.h" | |
11 #include "net/test/cert_test_util.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 using content::BrowserThread; | |
15 using net::SSLInfo; | |
16 | |
17 namespace chrome_browser_net { | |
18 | |
19 const std::string kHostname = "test.mail.google.com"; | |
20 | |
21 static SSLInfo GetSSLInfo() { | |
22 SSLInfo info; | |
23 info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(), | |
24 "test_mail_google_com.pem"); | |
25 info.is_issued_by_known_root = true; | |
26 info.pinning_failure_log = "dummy failure log"; | |
27 return info; | |
28 } | |
29 | |
30 static std::string GetPEMEncodedChain() { | |
31 base::FilePath cert_path = | |
32 net::GetTestCertsDirectory().AppendASCII("test_mail_google_com.pem"); | |
33 std::string cert_data; | |
34 EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data)); | |
35 return cert_data; | |
36 } | |
37 | |
38 class TestReporter : public ChromeCertificateReporter { | |
39 public: | |
40 explicit TestReporter(net::URLRequestContext* request_context) | |
41 : ChromeCertificateReporter(request_context, "") {} | |
42 static void BuildReport(const std::string& hostname, | |
43 const net::SSLInfo& ssl_info, | |
44 CertLoggerRequest& out_request) { | |
45 ChromeCertificateReporter::BuildReport(hostname, ssl_info, out_request); | |
46 } | |
47 }; | |
48 | |
49 // Test that a built report has the correct data. | |
50 TEST(ChromeCertificateReporterTest, ReportIsBuiltCorrectly) { | |
51 SSLInfo info = GetSSLInfo(); | |
52 CertLoggerRequest request; | |
53 TestReporter::BuildReport(kHostname, info, request); | |
54 | |
55 EXPECT_EQ(request.hostname(), kHostname); | |
56 EXPECT_EQ(request.cert_chain(), GetPEMEncodedChain()); | |
57 EXPECT_EQ(request.pin().size(), 1); | |
58 EXPECT_EQ(request.pin().Get(0), "dummy failure log"); | |
59 } | |
60 | |
estark
2015/03/04 17:33:49
I want to add another test here that tests that th
Ryan Sleevi
2015/03/06 19:32:31
Testing the data is as expected is testing the imp
| |
61 } // namespace chrome_browser_net | |
OLD | NEW |