Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(880)

Side by Side Diff: chrome/browser/net/certificate_error_reporter_unittest.cc

Issue 1117173005: Include cert status in invalid certificate reports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/net/certificate_error_reporter.h" 5 #include "chrome/browser/net/certificate_error_reporter.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
19 #include "chrome/browser/net/cert_logger.pb.h" 19 #include "chrome/browser/net/cert_logger.pb.h"
20 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
21 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
22 #include "crypto/curve25519.h" 22 #include "crypto/curve25519.h"
23 #include "net/base/load_flags.h" 23 #include "net/base/load_flags.h"
24 #include "net/base/network_delegate_impl.h" 24 #include "net/base/network_delegate_impl.h"
25 #include "net/base/test_data_directory.h" 25 #include "net/base/test_data_directory.h"
26 #include "net/base/upload_bytes_element_reader.h" 26 #include "net/base/upload_bytes_element_reader.h"
27 #include "net/base/upload_data_stream.h" 27 #include "net/base/upload_data_stream.h"
28 #include "net/base/upload_element_reader.h" 28 #include "net/base/upload_element_reader.h"
29 #include "net/cert/cert_status_flags.h"
29 #include "net/test/cert_test_util.h" 30 #include "net/test/cert_test_util.h"
30 #include "net/test/url_request/url_request_failed_job.h" 31 #include "net/test/url_request/url_request_failed_job.h"
31 #include "net/test/url_request/url_request_mock_data_job.h" 32 #include "net/test/url_request/url_request_mock_data_job.h"
32 #include "net/test/url_request/url_request_mock_http_job.h" 33 #include "net/test/url_request/url_request_mock_http_job.h"
33 #include "net/url_request/url_request_filter.h" 34 #include "net/url_request/url_request_filter.h"
34 #include "net/url_request/url_request_test_util.h" 35 #include "net/url_request/url_request_test_util.h"
35 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
36 37
37 using chrome_browser_net::CertificateErrorReporter; 38 using chrome_browser_net::CertificateErrorReporter;
38 using content::BrowserThread; 39 using content::BrowserThread;
40 using net::CertStatus;
39 using net::CompletionCallback; 41 using net::CompletionCallback;
40 using net::SSLInfo; 42 using net::SSLInfo;
41 using net::NetworkDelegateImpl; 43 using net::NetworkDelegateImpl;
42 using net::TestURLRequestContext; 44 using net::TestURLRequestContext;
43 using net::URLRequest; 45 using net::URLRequest;
44 46
45 namespace { 47 namespace {
46 48
47 const char kHostname[] = "test.mail.google.com"; 49 const char kHostname[] = "test.mail.google.com";
48 const char kSecondRequestHostname[] = "test2.mail.google.com"; 50 const char kSecondRequestHostname[] = "test2.mail.google.com";
49 const char kDummyFailureLog[] = "dummy failure log"; 51 const char kDummyFailureLog[] = "dummy failure log";
50 const char kTestCertFilename[] = "test_mail_google_com.pem"; 52 const char kTestCertFilename[] = "test_mail_google_com.pem";
51 const uint32 kServerPublicKeyVersion = 1; 53 const uint32 kServerPublicKeyVersion = 1;
54 const CertStatus kCertStatus = net::CERT_STATUS_COMMON_NAME_INVALID;
52 55
53 SSLInfo GetTestSSLInfo() { 56 SSLInfo GetTestSSLInfo() {
54 SSLInfo info; 57 SSLInfo info;
55 info.cert = 58 info.cert =
56 net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename); 59 net::ImportCertFromFile(net::GetTestCertsDirectory(), kTestCertFilename);
57 info.is_issued_by_known_root = true; 60 info.is_issued_by_known_root = true;
61 info.cert_status = kCertStatus;
58 info.pinning_failure_log = kDummyFailureLog; 62 info.pinning_failure_log = kDummyFailureLog;
59 return info; 63 return info;
60 } 64 }
61 65
62 std::string GetPEMEncodedChain() { 66 std::string GetPEMEncodedChain() {
63 base::FilePath cert_path = 67 base::FilePath cert_path =
64 net::GetTestCertsDirectory().AppendASCII(kTestCertFilename); 68 net::GetTestCertsDirectory().AppendASCII(kTestCertFilename);
65 std::string cert_data; 69 std::string cert_data;
66 EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data)); 70 EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data));
67 return cert_data; 71 return cert_data;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 #else 122 #else
119 ASSERT_TRUE(uploaded_request.ParseFromString(upload_data)); 123 ASSERT_TRUE(uploaded_request.ParseFromString(upload_data));
120 #endif 124 #endif
121 125
122 EXPECT_EQ(1u, expect_hostnames->count(uploaded_request.hostname())); 126 EXPECT_EQ(1u, expect_hostnames->count(uploaded_request.hostname()));
123 expect_hostnames->erase(uploaded_request.hostname()); 127 expect_hostnames->erase(uploaded_request.hostname());
124 128
125 EXPECT_EQ(GetPEMEncodedChain(), uploaded_request.cert_chain()); 129 EXPECT_EQ(GetPEMEncodedChain(), uploaded_request.cert_chain());
126 EXPECT_EQ(1, uploaded_request.pin().size()); 130 EXPECT_EQ(1, uploaded_request.pin().size());
127 EXPECT_EQ(kDummyFailureLog, uploaded_request.pin().Get(0)); 131 EXPECT_EQ(kDummyFailureLog, uploaded_request.pin().Get(0));
132 EXPECT_EQ(kCertStatus, uploaded_request.cert_status());
128 } 133 }
129 134
130 // A network delegate that lets tests check that a certificate error 135 // A network delegate that lets tests check that a certificate error
131 // report was sent. It counts the number of requests and lets tests 136 // report was sent. It counts the number of requests and lets tests
132 // register a callback to run when the request is destroyed. It also 137 // register a callback to run when the request is destroyed. It also
133 // checks that the uploaded data is as expected (a report for 138 // checks that the uploaded data is as expected (a report for
134 // |kHostname| and |GetTestSSLInfo()|). 139 // |kHostname| and |GetTestSSLInfo()|).
135 class TestCertificateErrorReporterNetworkDelegate : public NetworkDelegateImpl { 140 class TestCertificateErrorReporterNetworkDelegate : public NetworkDelegateImpl {
136 public: 141 public:
137 TestCertificateErrorReporterNetworkDelegate() 142 TestCertificateErrorReporterNetworkDelegate()
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1); 386 GURL url = net::URLRequestMockDataJob::GetMockHttpsUrl("dummy data", 1);
382 CertificateErrorReporter reporter( 387 CertificateErrorReporter reporter(
383 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES); 388 context(), url, CertificateErrorReporter::DO_NOT_SEND_COOKIES);
384 389
385 network_delegate()->set_expect_cookies(false); 390 network_delegate()->set_expect_cookies(false);
386 SendReport(&reporter, network_delegate(), kHostname, url, 0, 391 SendReport(&reporter, network_delegate(), kHostname, url, 0,
387 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION); 392 CertificateErrorReporter::REPORT_TYPE_PINNING_VIOLATION);
388 } 393 }
389 394
390 } // namespace 395 } // namespace
OLDNEW
« chrome/browser/net/cert_logger.proto ('K') | « chrome/browser/net/certificate_error_reporter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698