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

Side by Side Diff: ios/web/net/cert_verification_cache_unittest.cc

Issue 1357773002: WKWebView: Implemented recoverable SSL interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_coloring
Patch Set: Merged with origin/master Created 5 years, 2 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
(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 "ios/web/net/cert_verification_cache.h"
6
7 #include "net/base/test_data_directory.h"
8 #include "net/test/cert_test_util.h"
9 #include "testing/platform_test.h"
10
11 namespace {
12 // Test cert filenames.
13 const char kCertFileName1[] = "ok_cert.pem";
14 const char kCertFileName2[] = "expired_cert.pem";
15 // Test hostnames.
16 const char kHostName1[] = "www.example.com";
17 const char kHostName2[] = "www.chromium.org";
18 // Test values.
19 const int kValue1 = 5;
20 const int kValue2 = 6;
21 } // namespace
22
23 // Test fixture to test CertVerificationCache class.
24 class CertVerificationCacheTest : public PlatformTest {
25 protected:
26 // Loads cert with the given |file_name|.
27 scoped_refptr<net::X509Certificate> GetCert(const std::string& file_name) {
28 return net::ImportCertFromFile(net::GetTestCertsDirectory(), file_name);
29 }
30
31 web::CertVerificationCache<int> cache_;
32 };
33
34 // Tests retrieving from empty cache.
35 TEST_F(CertVerificationCacheTest, EmptyCache) {
36 // Cache miss because it is empty.
37 int value;
38 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName1, &value));
39 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName2, &value));
40 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName1, &value));
41 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName2, &value));
42 }
43
44 // Tests Get-Set cache operations.
45 TEST_F(CertVerificationCacheTest, TestReadingWriting) {
46 // Insert first cert.
47 cache_.Set(GetCert(kCertFileName1), kHostName1, kValue1);
48
49 // Cache miss because hostname/cert mismatch.
50 int value;
51 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName2, &value));
52 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName1, &value));
53 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName2, &value));
54 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), "", &value));
55
56 // Cahe hit.
57 EXPECT_TRUE(cache_.Get(GetCert(kCertFileName1), kHostName1, &value));
58 EXPECT_EQ(kValue1, value);
59
60 // Insert second cert.
61 cache_.Set(GetCert(kCertFileName2), kHostName2, kValue2);
62
63 // Cache miss because hostname/cert mismatch.
64 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName2, &value));
65 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName1, &value));
66
67 // Cahe hits.
68 EXPECT_TRUE(cache_.Get(GetCert(kCertFileName1), kHostName1, &value));
69 EXPECT_EQ(kValue1, value);
70 EXPECT_TRUE(cache_.Get(GetCert(kCertFileName2), kHostName2, &value));
71 EXPECT_EQ(kValue2, value);
72 }
73
74 // Tests resetting the cache.
75 TEST_F(CertVerificationCacheTest, Reset) {
76 cache_.Set(GetCert(kCertFileName1), kHostName1, kValue1);
77 cache_.Set(GetCert(kCertFileName2), kHostName2, kValue2);
78
79 cache_.reset();
80
81 // Cache miss because it is empty.
82 int value;
83 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName1, &value));
84 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName1), kHostName2, &value));
85 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName1, &value));
86 EXPECT_FALSE(cache_.Get(GetCert(kCertFileName2), kHostName2, &value));
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698