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

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 parent CL Created 5 years, 3 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 basic cache interactions.
35 TEST_F(CertVerificationCacheTest, Basic) {
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 // Insert first cert.
44 cache_.set(GetCert(kCertFileName1), kHostName1, kValue1);
45
46 // Cache miss because hostname/cert mismatch.
47 EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
48 EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
49 EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
50 EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), "", &value));
51
52 // Cahe hit.
53 EXPECT_TRUE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
54 EXPECT_EQ(kValue1, value);
55
56 // Insert second cert.
57 cache_.set(GetCert(kCertFileName2), kHostName2, kValue2);
58
59 // Cache miss because hostname/cert mismatch.
60 EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
61 EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
62
63 // Cahe hits.
64 EXPECT_TRUE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
65 EXPECT_EQ(kValue1, value);
66 EXPECT_TRUE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
67 EXPECT_EQ(kValue2, value);
68
69 // Clear cache.
70 cache_.reset();
71
72 // Cache miss because it is empty.
73 EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
74 EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
75 EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
76 EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698