| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 "net/ssl/ssl_config_service.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "testing/gmock/include/gmock/gmock.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace net { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class MockSSLConfigService : public SSLConfigService { | |
| 18 public: | |
| 19 explicit MockSSLConfigService(const SSLConfig& config) : config_(config) {} | |
| 20 | |
| 21 // SSLConfigService implementation | |
| 22 void GetSSLConfig(SSLConfig* config) override { *config = config_; } | |
| 23 | |
| 24 // Sets the SSLConfig to be returned by GetSSLConfig and processes any | |
| 25 // updates. | |
| 26 void SetSSLConfig(const SSLConfig& config) { | |
| 27 SSLConfig old_config = config_; | |
| 28 config_ = config; | |
| 29 ProcessConfigUpdate(old_config, config_); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 ~MockSSLConfigService() override {} | |
| 34 | |
| 35 SSLConfig config_; | |
| 36 }; | |
| 37 | |
| 38 class MockSSLConfigServiceObserver : public SSLConfigService::Observer { | |
| 39 public: | |
| 40 MockSSLConfigServiceObserver() {} | |
| 41 virtual ~MockSSLConfigServiceObserver() {} | |
| 42 | |
| 43 MOCK_METHOD0(OnSSLConfigChanged, void()); | |
| 44 }; | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 48 TEST(SSLConfigServiceTest, NoChangesWontNotifyObservers) { | |
| 49 SSLConfig initial_config; | |
| 50 initial_config.rev_checking_enabled = true; | |
| 51 initial_config.false_start_enabled = false; | |
| 52 initial_config.version_min = SSL_PROTOCOL_VERSION_SSL3; | |
| 53 initial_config.version_max = SSL_PROTOCOL_VERSION_TLS1_1; | |
| 54 | |
| 55 scoped_refptr<MockSSLConfigService> mock_service( | |
| 56 new MockSSLConfigService(initial_config)); | |
| 57 MockSSLConfigServiceObserver observer; | |
| 58 mock_service->AddObserver(&observer); | |
| 59 | |
| 60 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(0); | |
| 61 mock_service->SetSSLConfig(initial_config); | |
| 62 | |
| 63 mock_service->RemoveObserver(&observer); | |
| 64 } | |
| 65 | |
| 66 TEST(SSLConfigServiceTest, ConfigUpdatesNotifyObservers) { | |
| 67 SSLConfig initial_config; | |
| 68 initial_config.rev_checking_enabled = true; | |
| 69 initial_config.false_start_enabled = false; | |
| 70 initial_config.version_min = SSL_PROTOCOL_VERSION_SSL3; | |
| 71 initial_config.version_max = SSL_PROTOCOL_VERSION_TLS1_1; | |
| 72 | |
| 73 scoped_refptr<MockSSLConfigService> mock_service( | |
| 74 new MockSSLConfigService(initial_config)); | |
| 75 MockSSLConfigServiceObserver observer; | |
| 76 mock_service->AddObserver(&observer); | |
| 77 | |
| 78 // Test that the basic boolean preferences trigger updates. | |
| 79 initial_config.rev_checking_enabled = false; | |
| 80 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 81 mock_service->SetSSLConfig(initial_config); | |
| 82 | |
| 83 initial_config.false_start_enabled = true; | |
| 84 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 85 mock_service->SetSSLConfig(initial_config); | |
| 86 | |
| 87 // Test that changing the SSL version range triggers updates. | |
| 88 initial_config.version_min = SSL_PROTOCOL_VERSION_TLS1; | |
| 89 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 90 mock_service->SetSSLConfig(initial_config); | |
| 91 | |
| 92 initial_config.version_max = SSL_PROTOCOL_VERSION_SSL3; | |
| 93 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 94 mock_service->SetSSLConfig(initial_config); | |
| 95 | |
| 96 // Test that disabling certain cipher suites triggers an update. | |
| 97 std::vector<uint16> disabled_ciphers; | |
| 98 disabled_ciphers.push_back(0x0004u); | |
| 99 disabled_ciphers.push_back(0xBEEFu); | |
| 100 disabled_ciphers.push_back(0xDEADu); | |
| 101 initial_config.disabled_cipher_suites = disabled_ciphers; | |
| 102 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 103 mock_service->SetSSLConfig(initial_config); | |
| 104 | |
| 105 // Ensure that changing a disabled cipher suite, while still maintaining | |
| 106 // sorted order, triggers an update. | |
| 107 disabled_ciphers[1] = 0xCAFEu; | |
| 108 initial_config.disabled_cipher_suites = disabled_ciphers; | |
| 109 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 110 mock_service->SetSSLConfig(initial_config); | |
| 111 | |
| 112 // Ensure that removing a disabled cipher suite, while still keeping some | |
| 113 // cipher suites disabled, triggers an update. | |
| 114 disabled_ciphers.pop_back(); | |
| 115 initial_config.disabled_cipher_suites = disabled_ciphers; | |
| 116 EXPECT_CALL(observer, OnSSLConfigChanged()).Times(1); | |
| 117 mock_service->SetSSLConfig(initial_config); | |
| 118 | |
| 119 mock_service->RemoveObserver(&observer); | |
| 120 } | |
| 121 | |
| 122 } // namespace net | |
| OLD | NEW |