Peter Qiu | c0beca5 | 2015-09-03 11:25:46 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2013 The Android Open Source Project |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 16 | |
Ben Chan | 8760251 | 2014-11-07 20:50:05 -0800 | [diff] [blame] | 17 | #include "shill/ethernet/ethernet.h" |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 18 | |
| 19 | #include <netinet/ether.h> |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 20 | #include <linux/if.h> // NOLINT - Needs definitions from netinet/ether.h |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 21 | #include <linux/sockios.h> |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 22 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 23 | #include <memory> |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 24 | #include <utility> |
| 25 | #include <vector> |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 26 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 27 | #include <base/memory/ref_counted.h> |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 28 | |
Peter Qiu | 675d0b0 | 2015-06-03 13:08:09 -0700 | [diff] [blame] | 29 | #include "shill/dhcp/mock_dhcp_config.h" |
| 30 | #include "shill/dhcp/mock_dhcp_provider.h" |
Ben Chan | 8760251 | 2014-11-07 20:50:05 -0800 | [diff] [blame] | 31 | #include "shill/ethernet/mock_ethernet_service.h" |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 32 | #include "shill/mock_device_info.h" |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 33 | #include "shill/mock_event_dispatcher.h" |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 34 | #include "shill/mock_log.h" |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 35 | #include "shill/mock_manager.h" |
| 36 | #include "shill/mock_metrics.h" |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 37 | #include "shill/mock_service.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 38 | #include "shill/net/mock_rtnl_handler.h" |
| 39 | #include "shill/net/mock_sockets.h" |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 40 | #include "shill/nice_mock_control.h" |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 41 | #include "shill/testing.h" |
| 42 | |
| 43 | #if !defined(DISABLE_WIRED_8021X) |
| 44 | #include "shill/ethernet/mock_ethernet_eap_provider.h" |
| 45 | #include "shill/mock_eap_credentials.h" |
| 46 | #include "shill/mock_eap_listener.h" |
Ben Chan | da69ecf | 2014-11-19 07:44:42 -0800 | [diff] [blame] | 47 | #include "shill/supplicant/mock_supplicant_interface_proxy.h" |
| 48 | #include "shill/supplicant/mock_supplicant_process_proxy.h" |
| 49 | #include "shill/supplicant/wpa_supplicant.h" |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 50 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 51 | |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 52 | using std::pair; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 53 | using std::string; |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 54 | using std::vector; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 55 | using testing::_; |
| 56 | using testing::AnyNumber; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 57 | using testing::EndsWith; |
Gaurav Shah | 25ee250 | 2013-04-08 17:55:01 -0700 | [diff] [blame] | 58 | using testing::Eq; |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 59 | using testing::InSequence; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 60 | using testing::Mock; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 61 | using testing::NiceMock; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 62 | using testing::Return; |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 63 | using testing::ReturnRef; |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 64 | using testing::SetArgumentPointee; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 65 | using testing::StrEq; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 66 | using testing::StrictMock; |
| 67 | |
| 68 | namespace shill { |
| 69 | |
| 70 | class EthernetTest : public testing::Test { |
| 71 | public: |
| 72 | EthernetTest() |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 73 | : metrics_(nullptr), |
mukesh agrawal | bad1c10 | 2015-09-18 16:15:08 -0700 | [diff] [blame] | 74 | manager_(&control_interface_, nullptr, &metrics_), |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 75 | device_info_(&control_interface_, &dispatcher_, &metrics_, &manager_), |
| 76 | ethernet_(new Ethernet(&control_interface_, |
| 77 | &dispatcher_, |
| 78 | &metrics_, |
| 79 | &manager_, |
| 80 | kDeviceName, |
| 81 | kDeviceAddress, |
| 82 | kInterfaceIndex)), |
| 83 | dhcp_config_(new MockDHCPConfig(&control_interface_, |
| 84 | kDeviceName)), |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 85 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 86 | eap_listener_(new MockEapListener()), |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 87 | mock_eap_service_(new MockService(&control_interface_, |
| 88 | &dispatcher_, |
| 89 | &metrics_, |
| 90 | &manager_)), |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 91 | supplicant_interface_proxy_( |
| 92 | new NiceMock<MockSupplicantInterfaceProxy>()), |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 93 | supplicant_process_proxy_(new NiceMock<MockSupplicantProcessProxy>()), |
| 94 | #endif // DISABLE_WIRED_8021X |
| 95 | mock_sockets_(new StrictMock<MockSockets>()), |
| 96 | mock_service_(new MockEthernetService( |
| 97 | &control_interface_, &metrics_, |
| 98 | ethernet_->weak_ptr_factory_.GetWeakPtr())) {} |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 99 | ~EthernetTest() override {} |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 100 | |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 101 | void SetUp() override { |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 102 | ethernet_->rtnl_handler_ = &rtnl_handler_; |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 103 | ethernet_->sockets_.reset(mock_sockets_); // Transfers ownership. |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 104 | |
| 105 | ethernet_->set_dhcp_provider(&dhcp_provider_); |
| 106 | ON_CALL(manager_, device_info()).WillByDefault(Return(&device_info_)); |
| 107 | EXPECT_CALL(manager_, UpdateEnabledTechnologies()).Times(AnyNumber()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 108 | |
| 109 | #if !defined(DISABLE_WIRED_8021X) |
| 110 | ethernet_->eap_listener_.reset(eap_listener_); // Transfers ownership. |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 111 | EXPECT_CALL(manager_, ethernet_eap_provider()) |
| 112 | .WillRepeatedly(Return(ðernet_eap_provider_)); |
| 113 | ethernet_eap_provider_.set_service(mock_eap_service_); |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 114 | // Transfers ownership. |
| 115 | ethernet_->supplicant_process_proxy_.reset(supplicant_process_proxy_); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 116 | #endif // DISABLE_WIRED_8021X |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 117 | |
| 118 | ON_CALL(*mock_service_, technology()) |
| 119 | .WillByDefault(Return(Technology::kEthernet)); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 122 | void TearDown() override { |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 123 | #if !defined(DISABLE_WIRED_8021X) |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 124 | ethernet_eap_provider_.set_service(nullptr); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 125 | ethernet_->eap_listener_.reset(); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 126 | #endif // DISABLE_WIRED_8021X |
| 127 | ethernet_->set_dhcp_provider(nullptr); |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 128 | ethernet_->sockets_.reset(); |
Paul Stewart | b6addef | 2014-08-29 14:41:59 -0700 | [diff] [blame] | 129 | Mock::VerifyAndClearExpectations(&manager_); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 130 | ethernet_->Stop(nullptr, EnabledStateChangedCallback()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | protected: |
| 134 | static const char kDeviceName[]; |
| 135 | static const char kDeviceAddress[]; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 136 | static const char kInterfacePath[]; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 137 | static const int kInterfaceIndex; |
| 138 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 139 | bool GetLinkUp() { return ethernet_->link_up_; } |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 140 | void SetLinkUp(bool link_up) { ethernet_->link_up_ = link_up; } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 141 | const ServiceRefPtr& GetSelectedService() { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 142 | return ethernet_->selected_service(); |
| 143 | } |
| 144 | ServiceRefPtr GetService() { return ethernet_->service_; } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 145 | void SetService(const EthernetServiceRefPtr& service) { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 146 | ethernet_->service_ = service; |
| 147 | } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 148 | const PropertyStore& GetStore() { return ethernet_->store(); } |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 149 | void StartEthernet() { |
| 150 | EXPECT_CALL(rtnl_handler_, |
| 151 | SetInterfaceFlags(kInterfaceIndex, IFF_UP, IFF_UP)); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 152 | ethernet_->Start(nullptr, EnabledStateChangedCallback()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 153 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 154 | |
| 155 | #if !defined(DISABLE_WIRED_8021X) |
| 156 | bool GetIsEapAuthenticated() { return ethernet_->is_eap_authenticated_; } |
| 157 | void SetIsEapAuthenticated(bool is_eap_authenticated) { |
| 158 | ethernet_->is_eap_authenticated_ = is_eap_authenticated; |
| 159 | } |
| 160 | bool GetIsEapDetected() { return ethernet_->is_eap_detected_; } |
| 161 | void SetIsEapDetected(bool is_eap_detected) { |
| 162 | ethernet_->is_eap_detected_ = is_eap_detected; |
| 163 | } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 164 | const SupplicantInterfaceProxyInterface* GetSupplicantInterfaceProxy() { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 165 | return ethernet_->supplicant_interface_proxy_.get(); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 166 | } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 167 | const string& GetSupplicantInterfacePath() { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 168 | return ethernet_->supplicant_interface_path_; |
| 169 | } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 170 | const string& GetSupplicantNetworkPath() { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 171 | return ethernet_->supplicant_network_path_; |
| 172 | } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 173 | void SetSupplicantNetworkPath(const string& network_path) { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 174 | ethernet_->supplicant_network_path_ = network_path; |
| 175 | } |
| 176 | bool InvokeStartSupplicant() { |
| 177 | return ethernet_->StartSupplicant(); |
| 178 | } |
| 179 | void InvokeStopSupplicant() { |
| 180 | return ethernet_->StopSupplicant(); |
| 181 | } |
| 182 | bool InvokeStartEapAuthentication() { |
| 183 | return ethernet_->StartEapAuthentication(); |
| 184 | } |
| 185 | void StartSupplicant() { |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 186 | MockSupplicantInterfaceProxy* interface_proxy = |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 187 | ExpectCreateSupplicantInterfaceProxy(); |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 188 | EXPECT_CALL(*supplicant_process_proxy_, CreateInterface(_, _)) |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 189 | .WillOnce(DoAll(SetArgumentPointee<1>(string(kInterfacePath)), |
| 190 | Return(true))); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 191 | EXPECT_TRUE(InvokeStartSupplicant()); |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 192 | EXPECT_EQ(interface_proxy, GetSupplicantInterfaceProxy()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 193 | EXPECT_EQ(kInterfacePath, GetSupplicantInterfacePath()); |
| 194 | } |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 195 | void TriggerOnEapDetected() { ethernet_->OnEapDetected(); } |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 196 | void TriggerCertification(const string& subject, uint32_t depth) { |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 197 | ethernet_->CertificationTask(subject, depth); |
| 198 | } |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 199 | void TriggerTryEapAuthentication() { |
| 200 | ethernet_->TryEapAuthenticationTask(); |
| 201 | } |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 202 | |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 203 | MockSupplicantInterfaceProxy* ExpectCreateSupplicantInterfaceProxy() { |
Peter Qiu | 608ec29 | 2015-07-30 15:46:16 -0700 | [diff] [blame] | 204 | EXPECT_CALL(control_interface_, |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 205 | CreateSupplicantInterfaceProxy(_, kInterfacePath)) |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 206 | .WillOnce(ReturnAndReleasePointee(&supplicant_interface_proxy_)); |
| 207 | return supplicant_interface_proxy_.get(); |
| 208 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 209 | #endif // DISABLE_WIRED_8021X |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 210 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 211 | StrictMock<MockEventDispatcher> dispatcher_; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 212 | NiceMockControl control_interface_; |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 213 | NiceMock<MockMetrics> metrics_; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 214 | MockManager manager_; |
| 215 | MockDeviceInfo device_info_; |
| 216 | EthernetRefPtr ethernet_; |
| 217 | MockDHCPProvider dhcp_provider_; |
| 218 | scoped_refptr<MockDHCPConfig> dhcp_config_; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 219 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 220 | #if !defined(DISABLE_WIRED_8021X) |
| 221 | MockEthernetEapProvider ethernet_eap_provider_; |
| 222 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 223 | // Owned by Ethernet instance, but tracked here for expectations. |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 224 | MockEapListener* eap_listener_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 225 | |
| 226 | scoped_refptr<MockService> mock_eap_service_; |
| 227 | std::unique_ptr<MockSupplicantInterfaceProxy> supplicant_interface_proxy_; |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 228 | MockSupplicantProcessProxy* supplicant_process_proxy_; |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 229 | #endif // DISABLE_WIRED_8021X |
| 230 | |
| 231 | // Owned by Ethernet instance, but tracked here for expectations. |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 232 | MockSockets* mock_sockets_; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 233 | |
| 234 | MockRTNLHandler rtnl_handler_; |
| 235 | scoped_refptr<MockEthernetService> mock_service_; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | // static |
| 239 | const char EthernetTest::kDeviceName[] = "eth0"; |
| 240 | const char EthernetTest::kDeviceAddress[] = "000102030405"; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 241 | const char EthernetTest::kInterfacePath[] = "/interface/path"; |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 242 | const int EthernetTest::kInterfaceIndex = 123; |
| 243 | |
| 244 | TEST_F(EthernetTest, Construct) { |
| 245 | EXPECT_FALSE(GetLinkUp()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 246 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 247 | EXPECT_FALSE(GetIsEapAuthenticated()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 248 | EXPECT_FALSE(GetIsEapDetected()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 249 | EXPECT_TRUE(GetStore().Contains(kEapAuthenticationCompletedProperty)); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 250 | EXPECT_TRUE(GetStore().Contains(kEapAuthenticatorDetectedProperty)); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 251 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 252 | EXPECT_NE(nullptr, GetService().get()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST_F(EthernetTest, StartStop) { |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 256 | Service* service = GetService().get(); |
| 257 | EXPECT_CALL(manager_, RegisterService(Eq(service))); |
Gaurav Shah | 25ee250 | 2013-04-08 17:55:01 -0700 | [diff] [blame] | 258 | StartEthernet(); |
| 259 | |
Gaurav Shah | 25ee250 | 2013-04-08 17:55:01 -0700 | [diff] [blame] | 260 | EXPECT_CALL(manager_, DeregisterService(Eq(service))); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 261 | ethernet_->Stop(nullptr, EnabledStateChangedCallback()); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 262 | |
| 263 | // Ethernet device retains its service. |
| 264 | EXPECT_NE(nullptr, GetService()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | TEST_F(EthernetTest, LinkEvent) { |
| 268 | StartEthernet(); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 269 | SetService(mock_service_); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 270 | |
| 271 | // Link-down event while already down. |
| 272 | EXPECT_CALL(manager_, DeregisterService(_)).Times(0); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 273 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 274 | EXPECT_CALL(*eap_listener_, Start()).Times(0); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 275 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 276 | ethernet_->LinkEvent(0, IFF_LOWER_UP); |
| 277 | EXPECT_FALSE(GetLinkUp()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 278 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 279 | EXPECT_FALSE(GetIsEapDetected()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 280 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 281 | Mock::VerifyAndClearExpectations(&manager_); |
| 282 | |
| 283 | // Link-up event while down. |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 284 | int kFakeFd = 789; |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 285 | EXPECT_CALL(manager_, UpdateService(IsRefPtrTo(mock_service_))); |
| 286 | EXPECT_CALL(*mock_service_, OnVisibilityChanged()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 287 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 288 | EXPECT_CALL(*eap_listener_, Start()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 289 | #endif // DISABLE_WIRED_8021X |
mukesh agrawal | 8bda796 | 2014-04-01 17:09:35 -0700 | [diff] [blame] | 290 | EXPECT_CALL(*mock_sockets_, Socket(_, _, _)).WillOnce(Return(kFakeFd)); |
| 291 | EXPECT_CALL(*mock_sockets_, Ioctl(kFakeFd, SIOCETHTOOL, _)); |
| 292 | EXPECT_CALL(*mock_sockets_, Close(kFakeFd)); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 293 | ethernet_->LinkEvent(IFF_LOWER_UP, 0); |
| 294 | EXPECT_TRUE(GetLinkUp()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 295 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 296 | EXPECT_FALSE(GetIsEapDetected()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 297 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 298 | Mock::VerifyAndClearExpectations(&manager_); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 299 | Mock::VerifyAndClearExpectations(mock_service_.get()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 300 | |
| 301 | // Link-up event while already up. |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 302 | EXPECT_CALL(manager_, UpdateService(_)).Times(0); |
| 303 | EXPECT_CALL(*mock_service_, OnVisibilityChanged()).Times(0); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 304 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 305 | EXPECT_CALL(*eap_listener_, Start()).Times(0); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 306 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 307 | ethernet_->LinkEvent(IFF_LOWER_UP, 0); |
| 308 | EXPECT_TRUE(GetLinkUp()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 309 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 310 | EXPECT_FALSE(GetIsEapDetected()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 311 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 312 | Mock::VerifyAndClearExpectations(&manager_); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 313 | Mock::VerifyAndClearExpectations(mock_service_.get()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 314 | |
| 315 | // Link-down event while up. |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 316 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 317 | SetIsEapDetected(true); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 318 | // This is done in SetUp, but we have to reestablish this after calling |
| 319 | // VerifyAndClearExpectations() above. |
| 320 | EXPECT_CALL(manager_, ethernet_eap_provider()) |
| 321 | .WillRepeatedly(Return(ðernet_eap_provider_)); |
| 322 | EXPECT_CALL(ethernet_eap_provider_, |
| 323 | ClearCredentialChangeCallback(ethernet_.get())); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 324 | EXPECT_CALL(*eap_listener_, Stop()); |
| 325 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 326 | EXPECT_CALL(manager_, UpdateService(IsRefPtrTo(GetService().get()))); |
| 327 | EXPECT_CALL(*mock_service_, OnVisibilityChanged()); |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 328 | ethernet_->LinkEvent(0, IFF_LOWER_UP); |
| 329 | EXPECT_FALSE(GetLinkUp()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 330 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 331 | EXPECT_FALSE(GetIsEapDetected()); |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 332 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 333 | |
| 334 | // Restore this expectation during shutdown. |
| 335 | EXPECT_CALL(manager_, UpdateEnabledTechnologies()).Times(AnyNumber()); |
| 336 | } |
| 337 | |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 338 | TEST_F(EthernetTest, ConnectToLinkDown) { |
| 339 | StartEthernet(); |
| 340 | SetService(mock_service_); |
| 341 | SetLinkUp(false); |
| 342 | EXPECT_EQ(nullptr, GetSelectedService().get()); |
Peter Qiu | 8e0151e | 2015-06-04 09:41:47 -0700 | [diff] [blame] | 343 | EXPECT_CALL(dhcp_provider_, CreateIPv4Config(_, _, _, _)).Times(0); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 344 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).Times(0); |
| 345 | EXPECT_CALL(dispatcher_, PostTask(_)).Times(0); |
| 346 | EXPECT_CALL(*mock_service_, SetState(_)).Times(0); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 347 | ethernet_->ConnectTo(mock_service_.get()); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 348 | EXPECT_EQ(nullptr, GetSelectedService().get()); |
| 349 | } |
| 350 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 351 | TEST_F(EthernetTest, ConnectToFailure) { |
| 352 | StartEthernet(); |
| 353 | SetService(mock_service_); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 354 | SetLinkUp(true); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 355 | EXPECT_EQ(nullptr, GetSelectedService().get()); |
Peter Qiu | 8e0151e | 2015-06-04 09:41:47 -0700 | [diff] [blame] | 356 | EXPECT_CALL(dhcp_provider_, CreateIPv4Config(_, _, _, _)). |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 357 | WillOnce(Return(dhcp_config_)); |
| 358 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).WillOnce(Return(false)); |
| 359 | EXPECT_CALL(dispatcher_, PostTask(_)); // Posts ConfigureStaticIPTask. |
Paul Stewart | dded007 | 2013-10-24 12:38:54 -0700 | [diff] [blame] | 360 | EXPECT_CALL(*mock_service_, SetState(Service::kStateFailure)); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 361 | ethernet_->ConnectTo(mock_service_.get()); |
Paul Stewart | dded007 | 2013-10-24 12:38:54 -0700 | [diff] [blame] | 362 | EXPECT_EQ(mock_service_, GetSelectedService().get()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | TEST_F(EthernetTest, ConnectToSuccess) { |
| 366 | StartEthernet(); |
| 367 | SetService(mock_service_); |
Paul Stewart | 3de88a0 | 2014-12-05 07:55:14 -0800 | [diff] [blame] | 368 | SetLinkUp(true); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 369 | EXPECT_EQ(nullptr, GetSelectedService().get()); |
Peter Qiu | 8e0151e | 2015-06-04 09:41:47 -0700 | [diff] [blame] | 370 | EXPECT_CALL(dhcp_provider_, CreateIPv4Config(_, _, _, _)). |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 371 | WillOnce(Return(dhcp_config_)); |
| 372 | EXPECT_CALL(*dhcp_config_.get(), RequestIP()).WillOnce(Return(true)); |
| 373 | EXPECT_CALL(dispatcher_, PostTask(_)); // Posts ConfigureStaticIPTask. |
| 374 | EXPECT_CALL(*mock_service_, SetState(Service::kStateConfiguring)); |
| 375 | ethernet_->ConnectTo(mock_service_.get()); |
| 376 | EXPECT_EQ(GetService().get(), GetSelectedService().get()); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 377 | Mock::VerifyAndClearExpectations(mock_service_.get()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 378 | |
| 379 | EXPECT_CALL(*mock_service_, SetState(Service::kStateIdle)); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 380 | ethernet_->DisconnectFrom(mock_service_.get()); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 381 | EXPECT_EQ(nullptr, GetSelectedService().get()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 384 | #if !defined(DISABLE_WIRED_8021X) |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 385 | TEST_F(EthernetTest, OnEapDetected) { |
| 386 | EXPECT_FALSE(GetIsEapDetected()); |
| 387 | EXPECT_CALL(*eap_listener_, Stop()); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 388 | EXPECT_CALL(ethernet_eap_provider_, |
| 389 | SetCredentialChangeCallback(ethernet_.get(), _)); |
| 390 | EXPECT_CALL(dispatcher_, PostTask(_)); // Posts TryEapAuthenticationTask. |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 391 | TriggerOnEapDetected(); |
| 392 | EXPECT_TRUE(GetIsEapDetected()); |
| 393 | } |
| 394 | |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 395 | TEST_F(EthernetTest, TryEapAuthenticationNotConnectableNotAuthenticated) { |
| 396 | SetService(mock_service_); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 397 | EXPECT_CALL(*mock_eap_service_, Is8021xConnectable()).WillOnce(Return(false)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 398 | NiceScopedMockLog log; |
| 399 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 400 | EndsWith("EAP Service lacks 802.1X credentials; " |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 401 | "not doing EAP authentication."))); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 402 | TriggerTryEapAuthentication(); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 403 | SetService(nullptr); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | TEST_F(EthernetTest, TryEapAuthenticationNotConnectableAuthenticated) { |
| 407 | SetService(mock_service_); |
| 408 | SetIsEapAuthenticated(true); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 409 | EXPECT_CALL(*mock_eap_service_, Is8021xConnectable()).WillOnce(Return(false)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 410 | NiceScopedMockLog log; |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 411 | EXPECT_CALL(log, Log(_, _, _)).Times(AnyNumber()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 412 | EXPECT_CALL(log, Log(logging::LOG_INFO, _, |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 413 | EndsWith("EAP Service lost 802.1X credentials; " |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 414 | "terminating EAP authentication."))); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 415 | TriggerTryEapAuthentication(); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 416 | EXPECT_FALSE(GetIsEapAuthenticated()); |
| 417 | } |
| 418 | |
| 419 | TEST_F(EthernetTest, TryEapAuthenticationEapNotDetected) { |
| 420 | SetService(mock_service_); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 421 | EXPECT_CALL(*mock_eap_service_, Is8021xConnectable()).WillOnce(Return(true)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 422 | NiceScopedMockLog log; |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 423 | EXPECT_CALL(log, Log(logging::LOG_WARNING, _, |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 424 | EndsWith("EAP authenticator not detected; " |
| 425 | "not doing EAP authentication."))); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 426 | TriggerTryEapAuthentication(); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | TEST_F(EthernetTest, StartSupplicant) { |
| 430 | // Save the mock proxy pointers before the Ethernet instance accepts it. |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 431 | MockSupplicantInterfaceProxy* interface_proxy = |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 432 | supplicant_interface_proxy_.get(); |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 433 | MockSupplicantProcessProxy* process_proxy = supplicant_process_proxy_; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 434 | |
| 435 | StartSupplicant(); |
| 436 | |
| 437 | // Starting it again should not invoke another call to create an interface. |
| 438 | Mock::VerifyAndClearExpectations(process_proxy); |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 439 | EXPECT_CALL(*process_proxy, CreateInterface(_, _)).Times(0); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 440 | EXPECT_TRUE(InvokeStartSupplicant()); |
| 441 | |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 442 | // Also, the mock pointers should remain; if the MockProxyFactory was |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 443 | // invoked again, they would be nullptr. |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 444 | EXPECT_EQ(interface_proxy, GetSupplicantInterfaceProxy()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 445 | EXPECT_EQ(kInterfacePath, GetSupplicantInterfacePath()); |
| 446 | } |
| 447 | |
| 448 | TEST_F(EthernetTest, StartSupplicantWithInterfaceExistsException) { |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 449 | MockSupplicantProcessProxy* process_proxy = supplicant_process_proxy_; |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 450 | MockSupplicantInterfaceProxy* interface_proxy = |
Ben Chan | a55469d | 2014-01-27 16:35:29 -0800 | [diff] [blame] | 451 | ExpectCreateSupplicantInterfaceProxy(); |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 452 | EXPECT_CALL(*process_proxy, CreateInterface(_, _)).WillOnce(Return(false)); |
| 453 | EXPECT_CALL(*process_proxy, GetInterface(kDeviceName, _)) |
| 454 | .WillOnce( |
| 455 | DoAll(SetArgumentPointee<1>(string(kInterfacePath)), Return(true))); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 456 | EXPECT_TRUE(InvokeStartSupplicant()); |
| 457 | EXPECT_EQ(interface_proxy, GetSupplicantInterfaceProxy()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 458 | EXPECT_EQ(kInterfacePath, GetSupplicantInterfacePath()); |
| 459 | } |
| 460 | |
| 461 | TEST_F(EthernetTest, StartSupplicantWithUnknownException) { |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 462 | MockSupplicantProcessProxy* process_proxy = supplicant_process_proxy_; |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 463 | EXPECT_CALL(*process_proxy, CreateInterface(_, _)).WillOnce(Return(false)); |
| 464 | EXPECT_CALL(*process_proxy, GetInterface(kDeviceName, _)) |
| 465 | .WillOnce(Return(false)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 466 | EXPECT_FALSE(InvokeStartSupplicant()); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 467 | EXPECT_EQ(nullptr, GetSupplicantInterfaceProxy()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 468 | EXPECT_EQ("", GetSupplicantInterfacePath()); |
| 469 | } |
| 470 | |
| 471 | TEST_F(EthernetTest, StartEapAuthentication) { |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 472 | MockSupplicantInterfaceProxy* interface_proxy = |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 473 | supplicant_interface_proxy_.get(); |
| 474 | |
| 475 | StartSupplicant(); |
| 476 | SetService(mock_service_); |
| 477 | |
| 478 | EXPECT_CALL(*mock_service_, ClearEAPCertification()); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 479 | MockEapCredentials mock_eap_credentials; |
| 480 | EXPECT_CALL(*mock_eap_service_, eap()) |
| 481 | .WillOnce(Return(&mock_eap_credentials)); |
Paul Stewart | c350e68 | 2014-06-19 15:44:30 -0700 | [diff] [blame] | 482 | EXPECT_CALL(mock_eap_credentials, PopulateSupplicantProperties(_, _)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 483 | EXPECT_CALL(*interface_proxy, RemoveNetwork(_)).Times(0); |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 484 | EXPECT_CALL(*interface_proxy, AddNetwork(_, _)) |
| 485 | .WillOnce(Return(false)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 486 | EXPECT_CALL(*interface_proxy, SelectNetwork(_)).Times(0); |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 487 | EXPECT_CALL(*interface_proxy, EAPLogon()).Times(0); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 488 | EXPECT_FALSE(InvokeStartEapAuthentication()); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 489 | Mock::VerifyAndClearExpectations(mock_service_.get()); |
| 490 | Mock::VerifyAndClearExpectations(mock_eap_service_.get()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 491 | Mock::VerifyAndClearExpectations(interface_proxy); |
| 492 | EXPECT_EQ("", GetSupplicantNetworkPath()); |
| 493 | |
| 494 | EXPECT_CALL(*mock_service_, ClearEAPCertification()); |
| 495 | EXPECT_CALL(*interface_proxy, RemoveNetwork(_)).Times(0); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 496 | EXPECT_CALL(*mock_eap_service_, eap()) |
| 497 | .WillOnce(Return(&mock_eap_credentials)); |
Paul Stewart | c350e68 | 2014-06-19 15:44:30 -0700 | [diff] [blame] | 498 | EXPECT_CALL(mock_eap_credentials, PopulateSupplicantProperties(_, _)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 499 | const char kFirstNetworkPath[] = "/network/first-path"; |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 500 | EXPECT_CALL(*interface_proxy, AddNetwork(_, _)) |
| 501 | .WillOnce( |
| 502 | DoAll(SetArgumentPointee<1>(string(kFirstNetworkPath)), |
| 503 | Return(true))); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 504 | EXPECT_CALL(*interface_proxy, SelectNetwork(StrEq(kFirstNetworkPath))); |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 505 | EXPECT_CALL(*interface_proxy, EAPLogon()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 506 | EXPECT_TRUE(InvokeStartEapAuthentication()); |
Alex Vakulenko | 0951ccb | 2014-12-10 12:52:31 -0800 | [diff] [blame] | 507 | Mock::VerifyAndClearExpectations(mock_service_.get()); |
| 508 | Mock::VerifyAndClearExpectations(mock_eap_service_.get()); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 509 | Mock::VerifyAndClearExpectations(&mock_eap_credentials); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 510 | Mock::VerifyAndClearExpectations(interface_proxy); |
| 511 | EXPECT_EQ(kFirstNetworkPath, GetSupplicantNetworkPath()); |
| 512 | |
| 513 | EXPECT_CALL(*mock_service_, ClearEAPCertification()); |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 514 | EXPECT_CALL(*interface_proxy, RemoveNetwork(StrEq(kFirstNetworkPath))) |
| 515 | .WillOnce(Return(true)); |
Paul Stewart | 35eff13 | 2013-04-12 12:08:40 -0700 | [diff] [blame] | 516 | EXPECT_CALL(*mock_eap_service_, eap()) |
| 517 | .WillOnce(Return(&mock_eap_credentials)); |
Paul Stewart | c350e68 | 2014-06-19 15:44:30 -0700 | [diff] [blame] | 518 | EXPECT_CALL(mock_eap_credentials, PopulateSupplicantProperties(_, _)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 519 | const char kSecondNetworkPath[] = "/network/second-path"; |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 520 | EXPECT_CALL(*interface_proxy, AddNetwork(_, _)) |
| 521 | .WillOnce( |
| 522 | DoAll(SetArgumentPointee<1>(string(kSecondNetworkPath)), |
| 523 | Return(true))); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 524 | EXPECT_CALL(*interface_proxy, SelectNetwork(StrEq(kSecondNetworkPath))); |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 525 | EXPECT_CALL(*interface_proxy, EAPLogon()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 526 | EXPECT_TRUE(InvokeStartEapAuthentication()); |
| 527 | EXPECT_EQ(kSecondNetworkPath, GetSupplicantNetworkPath()); |
| 528 | } |
| 529 | |
| 530 | TEST_F(EthernetTest, StopSupplicant) { |
Peter Qiu | e5fe58d | 2015-08-12 15:21:56 -0700 | [diff] [blame] | 531 | MockSupplicantProcessProxy* process_proxy = supplicant_process_proxy_; |
Paul Stewart | 7e779d8 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 532 | MockSupplicantInterfaceProxy* interface_proxy = |
Paul Stewart | be9abfd | 2013-04-22 12:18:48 -0700 | [diff] [blame] | 533 | supplicant_interface_proxy_.get(); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 534 | StartSupplicant(); |
| 535 | SetIsEapAuthenticated(true); |
| 536 | SetSupplicantNetworkPath("/network/1"); |
Peter Qiu | fc52363 | 2015-07-14 14:13:41 -0700 | [diff] [blame] | 537 | EXPECT_CALL(*interface_proxy, EAPLogoff()).WillOnce(Return(true)); |
| 538 | EXPECT_CALL(*process_proxy, RemoveInterface(StrEq(kInterfacePath))) |
| 539 | .WillOnce(Return(true)); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 540 | InvokeStopSupplicant(); |
Ben Chan | f8a2ce1 | 2014-09-30 14:42:59 -0700 | [diff] [blame] | 541 | EXPECT_EQ(nullptr, GetSupplicantInterfaceProxy()); |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 542 | EXPECT_EQ("", GetSupplicantInterfacePath()); |
| 543 | EXPECT_EQ("", GetSupplicantNetworkPath()); |
| 544 | EXPECT_FALSE(GetIsEapAuthenticated()); |
| 545 | } |
| 546 | |
| 547 | TEST_F(EthernetTest, Certification) { |
| 548 | const string kSubjectName("subject-name"); |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 549 | const uint32_t kDepth = 123; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 550 | // Should not crash due to no service_. |
| 551 | TriggerCertification(kSubjectName, kDepth); |
| 552 | EXPECT_CALL(*mock_service_, AddEAPCertification(kSubjectName, kDepth)); |
| 553 | SetService(mock_service_); |
| 554 | TriggerCertification(kSubjectName, kDepth); |
| 555 | } |
Peter Qiu | 1a72f54 | 2015-04-14 16:31:36 -0700 | [diff] [blame] | 556 | #endif // DISABLE_WIRED_8021X |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 557 | |
Garret Kelly | 65a5672 | 2015-02-03 14:48:25 -0500 | [diff] [blame] | 558 | #if !defined(DISABLE_PPPOE) |
| 559 | |
| 560 | MATCHER_P(TechnologyEq, technology, "") { |
| 561 | return arg->technology() == technology; |
| 562 | } |
| 563 | |
| 564 | TEST_F(EthernetTest, TogglePPPoE) { |
| 565 | SetService(mock_service_); |
| 566 | |
| 567 | EXPECT_CALL(*mock_service_, technology()) |
| 568 | .WillRepeatedly(Return(Technology::kEthernet)); |
| 569 | EXPECT_CALL(*mock_service_, Disconnect(_, _)); |
| 570 | |
| 571 | InSequence sequence; |
| 572 | EXPECT_CALL(manager_, DeregisterService(Eq(mock_service_))); |
| 573 | EXPECT_CALL(manager_, RegisterService(TechnologyEq(Technology::kPPPoE))); |
| 574 | EXPECT_CALL(manager_, DeregisterService(TechnologyEq(Technology::kPPPoE))); |
| 575 | EXPECT_CALL(manager_, RegisterService(_)); |
| 576 | |
| 577 | const vector<pair<bool, Technology::Identifier>> transitions = { |
| 578 | {false, Technology::kEthernet}, |
| 579 | {true, Technology::kPPPoE}, |
| 580 | {false, Technology::kEthernet}, |
| 581 | }; |
| 582 | for (const auto transition : transitions) { |
| 583 | Error error; |
| 584 | ethernet_->mutable_store()->SetBoolProperty( |
| 585 | kPPPoEProperty, transition.first, &error); |
| 586 | EXPECT_TRUE(error.IsSuccess()); |
| 587 | EXPECT_EQ(GetService()->technology(), transition.second); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | #else |
| 592 | |
| 593 | TEST_F(EthernetTest, PPPoEDisabled) { |
| 594 | Error error; |
| 595 | ethernet_->mutable_store()->SetBoolProperty(kPPPoEProperty, true, &error); |
| 596 | EXPECT_FALSE(error.IsSuccess()); |
| 597 | } |
| 598 | |
| 599 | #endif // DISABLE_PPPOE |
| 600 | |
Paul Stewart | ced3ad7 | 2013-04-03 13:39:25 -0700 | [diff] [blame] | 601 | } // namespace shill |