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

Unified Diff: chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc

Issue 1211933005: Initial (partial) implementation of HPKP violation reporting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style fixes, comments Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc
diff --git a/chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc b/chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc
index 79ae4280eec9eab95d4b901f8e56095fb5ea2ff4..f2a2a608e64680401544610c8d8a4ddbf98b0333 100644
--- a/chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc
+++ b/chrome/browser/ssl/chrome_fraudulent_certificate_reporter_unittest.cc
@@ -19,6 +19,8 @@
#include "net/base/request_priority.h"
#include "net/base/test_data_directory.h"
#include "net/cert/x509_certificate.h"
+#include "net/http/certificate_report_sender.h"
+#include "net/http/certificate_report_sender_impl.h"
#include "net/http/transport_security_state.h"
#include "net/ssl/ssl_info.h"
#include "net/test/cert_test_util.h"
@@ -34,6 +36,11 @@ using net::SSLInfo;
namespace {
+const uint32 kServerPublicKeyVersion = 1;
+const uint8 kServerPublicKey[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
// Builds an SSLInfo from an invalid cert chain. In this case, the cert is
// expired; what matters is that the cert would not pass even a normal
// sanity check. We test that we DO NOT send a fraudulent certificate report
@@ -116,15 +123,35 @@ class NotSendingTestReporter : public TestReporter {
}
};
+class MockCertificateReportSender : public net::CertificateReportSenderImpl {
+ public:
+ MockCertificateReportSender(
+ net::URLRequestContext* request_context,
+ net::CertificateReportSender::CookiesPreference cookies_preference)
+ : net::CertificateReportSenderImpl(request_context, cookies_preference) {}
+
+ private:
+ scoped_ptr<net::URLRequest> CreateURLRequest(
+ net::URLRequestContext* context,
+ const GURL& report_uri) override {
+ return context->CreateRequest(GURL(std::string()), net::DEFAULT_PRIORITY,
+ NULL);
+ }
+};
+
// A CertificateErrorReporter that uses a MockURLRequest, but is
// otherwise normal: reports are constructed and sent in the usual way.
class MockReporter : public CertificateErrorReporter {
public:
explicit MockReporter(net::URLRequestContext* request_context)
: CertificateErrorReporter(
- request_context,
GURL("http://example.com"),
- CertificateErrorReporter::DO_NOT_SEND_COOKIES) {}
+ kServerPublicKey,
+ kServerPublicKeyVersion,
+ scoped_ptr<net::CertificateReportSender>(
+ new MockCertificateReportSender(
+ request_context,
+ net::CertificateReportSender::DO_NOT_SEND_COOKIES))) {}
void SendReport(ReportType type,
const std::string& serialized_report) override {
@@ -132,13 +159,6 @@ class MockReporter : public CertificateErrorReporter {
EXPECT_FALSE(serialized_report.empty());
CertificateErrorReporter::SendReport(type, serialized_report);
}
-
- private:
- scoped_ptr<net::URLRequest> CreateURLRequest(
- net::URLRequestContext* context) override {
- return context->CreateRequest(GURL(std::string()), net::DEFAULT_PRIORITY,
- NULL);
- }
};
static void DoReportIsSent() {

Powered by Google App Engine
This is Rietveld 408576698