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

Unified Diff: ios/web/net/cert_policy_unittest.cc

Issue 986743003: Upstream (most of) ios/web/public (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix namespace comment Created 5 years, 9 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
« no previous file with comments | « ios/web/net/cert_policy.cc ('k') | ios/web/net/certificate_policy_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/net/cert_policy_unittest.cc
diff --git a/ios/web/net/cert_policy_unittest.cc b/ios/web/net/cert_policy_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..47d2f25b2ac6d1e2f5e7e07d8d2389ac01296745
--- /dev/null
+++ b/ios/web/net/cert_policy_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/public/cert_policy.h"
+
+#include "base/memory/ref_counted.h"
+#include "net/cert/x509_certificate.h"
+#include "net/test/test_certificate_data.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace web {
+
+TEST(CertPolicyTest, Policy) {
+ scoped_refptr<net::X509Certificate> google_cert(
+ net::X509Certificate::CreateFromBytes(
+ reinterpret_cast<const char*>(google_der), sizeof(google_der)));
+
+ scoped_refptr<net::X509Certificate> webkit_cert(
+ net::X509Certificate::CreateFromBytes(
+ reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
+
+ CertPolicy policy;
+
+ // To begin with, everything should be unknown.
+ EXPECT_EQ(CertPolicy::UNKNOWN,
+ policy.Check(google_cert.get(), net::CERT_STATUS_DATE_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(webkit_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+
+ // Test adding one certificate with one error.
+ policy.Allow(google_cert.get(), net::CERT_STATUS_DATE_INVALID);
+ EXPECT_EQ(CertPolicy::ALLOWED,
+ policy.Check(google_cert.get(), net::CERT_STATUS_DATE_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(google_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+ EXPECT_EQ(CertPolicy::UNKNOWN,
+ policy.Check(google_cert.get(),
+ net::CERT_STATUS_DATE_INVALID |
+ net::CERT_STATUS_COMMON_NAME_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(webkit_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+
+ // Test saving the same certificate with a new error.
+ policy.Allow(google_cert.get(), net::CERT_STATUS_AUTHORITY_INVALID);
+ EXPECT_EQ(CertPolicy::UNKNOWN,
+ policy.Check(google_cert.get(), net::CERT_STATUS_DATE_INVALID));
+ EXPECT_EQ(
+ CertPolicy::ALLOWED,
+ policy.Check(google_cert.get(), net::CERT_STATUS_AUTHORITY_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(webkit_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+
+ // Test adding one certificate with two errors.
+ policy.Allow(
+ google_cert.get(),
+ net::CERT_STATUS_DATE_INVALID | net::CERT_STATUS_AUTHORITY_INVALID);
+ EXPECT_EQ(CertPolicy::ALLOWED,
+ policy.Check(google_cert.get(), net::CERT_STATUS_DATE_INVALID));
+ EXPECT_EQ(
+ CertPolicy::ALLOWED,
+ policy.Check(google_cert.get(), net::CERT_STATUS_AUTHORITY_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(google_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+ EXPECT_EQ(
+ CertPolicy::UNKNOWN,
+ policy.Check(webkit_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID));
+}
+
+} // namespace web
« no previous file with comments | « ios/web/net/cert_policy.cc ('k') | ios/web/net/certificate_policy_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698