| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h" | 5 #include "components/proximity_auth/remote_device_life_cycle_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::string GetChannelBindingData() const override { return std::string(); } | 56 std::string GetChannelBindingData() const override { return std::string(); } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(StubSecureContext); | 59 DISALLOW_COPY_AND_ASSIGN(StubSecureContext); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class FakeConnectionFinder : public ConnectionFinder { | 62 class FakeConnectionFinder : public ConnectionFinder { |
| 63 public: | 63 public: |
| 64 FakeConnectionFinder(const RemoteDevice& remote_device) | 64 FakeConnectionFinder(const cryptauth::RemoteDevice& remote_device) |
| 65 : remote_device_(remote_device), connection_(nullptr) {} | 65 : remote_device_(remote_device), connection_(nullptr) {} |
| 66 ~FakeConnectionFinder() override {} | 66 ~FakeConnectionFinder() override {} |
| 67 | 67 |
| 68 void OnConnectionFound() { | 68 void OnConnectionFound() { |
| 69 ASSERT_FALSE(connection_callback_.is_null()); | 69 ASSERT_FALSE(connection_callback_.is_null()); |
| 70 std::unique_ptr<FakeConnection> scoped_connection_( | 70 std::unique_ptr<FakeConnection> scoped_connection_( |
| 71 new FakeConnection(remote_device_)); | 71 new FakeConnection(remote_device_)); |
| 72 connection_ = scoped_connection_.get(); | 72 connection_ = scoped_connection_.get(); |
| 73 connection_callback_.Run(std::move(scoped_connection_)); | 73 connection_callback_.Run(std::move(scoped_connection_)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 FakeConnection* connection() { return connection_; } | 76 FakeConnection* connection() { return connection_; } |
| 77 | 77 |
| 78 private: | 78 private: |
| 79 // ConnectionFinder: | 79 // ConnectionFinder: |
| 80 void Find(const ConnectionCallback& connection_callback) override { | 80 void Find(const ConnectionCallback& connection_callback) override { |
| 81 ASSERT_TRUE(connection_callback_.is_null()); | 81 ASSERT_TRUE(connection_callback_.is_null()); |
| 82 connection_callback_ = connection_callback; | 82 connection_callback_ = connection_callback; |
| 83 } | 83 } |
| 84 | 84 |
| 85 const RemoteDevice remote_device_; | 85 const cryptauth::RemoteDevice remote_device_; |
| 86 | 86 |
| 87 FakeConnection* connection_; | 87 FakeConnection* connection_; |
| 88 | 88 |
| 89 ConnectionCallback connection_callback_; | 89 ConnectionCallback connection_callback_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(FakeConnectionFinder); | 91 DISALLOW_COPY_AND_ASSIGN(FakeConnectionFinder); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class FakeAuthenticator : public Authenticator { | 94 class FakeAuthenticator : public Authenticator { |
| 95 public: | 95 public: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 120 Connection* connection_; | 120 Connection* connection_; |
| 121 | 121 |
| 122 AuthenticationCallback callback_; | 122 AuthenticationCallback callback_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); | 124 DISALLOW_COPY_AND_ASSIGN(FakeAuthenticator); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 // Subclass of RemoteDeviceLifeCycleImpl to make it testable. | 127 // Subclass of RemoteDeviceLifeCycleImpl to make it testable. |
| 128 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl { | 128 class TestableRemoteDeviceLifeCycleImpl : public RemoteDeviceLifeCycleImpl { |
| 129 public: | 129 public: |
| 130 TestableRemoteDeviceLifeCycleImpl(const RemoteDevice& remote_device) | 130 TestableRemoteDeviceLifeCycleImpl( |
| 131 const cryptauth::RemoteDevice& remote_device) |
| 131 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), | 132 : RemoteDeviceLifeCycleImpl(remote_device, nullptr), |
| 132 remote_device_(remote_device) {} | 133 remote_device_(remote_device) {} |
| 133 | 134 |
| 134 ~TestableRemoteDeviceLifeCycleImpl() override {} | 135 ~TestableRemoteDeviceLifeCycleImpl() override {} |
| 135 | 136 |
| 136 FakeConnectionFinder* connection_finder() { return connection_finder_; } | 137 FakeConnectionFinder* connection_finder() { return connection_finder_; } |
| 137 FakeAuthenticator* authenticator() { return authenticator_; } | 138 FakeAuthenticator* authenticator() { return authenticator_; } |
| 138 | 139 |
| 139 private: | 140 private: |
| 140 std::unique_ptr<ConnectionFinder> CreateConnectionFinder() override { | 141 std::unique_ptr<ConnectionFinder> CreateConnectionFinder() override { |
| 141 std::unique_ptr<FakeConnectionFinder> scoped_connection_finder( | 142 std::unique_ptr<FakeConnectionFinder> scoped_connection_finder( |
| 142 new FakeConnectionFinder(remote_device_)); | 143 new FakeConnectionFinder(remote_device_)); |
| 143 connection_finder_ = scoped_connection_finder.get(); | 144 connection_finder_ = scoped_connection_finder.get(); |
| 144 return std::move(scoped_connection_finder); | 145 return std::move(scoped_connection_finder); |
| 145 } | 146 } |
| 146 | 147 |
| 147 std::unique_ptr<Authenticator> CreateAuthenticator() override { | 148 std::unique_ptr<Authenticator> CreateAuthenticator() override { |
| 148 EXPECT_TRUE(connection_finder_); | 149 EXPECT_TRUE(connection_finder_); |
| 149 std::unique_ptr<FakeAuthenticator> scoped_authenticator( | 150 std::unique_ptr<FakeAuthenticator> scoped_authenticator( |
| 150 new FakeAuthenticator(connection_finder_->connection())); | 151 new FakeAuthenticator(connection_finder_->connection())); |
| 151 authenticator_ = scoped_authenticator.get(); | 152 authenticator_ = scoped_authenticator.get(); |
| 152 return std::move(scoped_authenticator); | 153 return std::move(scoped_authenticator); |
| 153 } | 154 } |
| 154 | 155 |
| 155 const RemoteDevice remote_device_; | 156 const cryptauth::RemoteDevice remote_device_; |
| 156 FakeConnectionFinder* connection_finder_; | 157 FakeConnectionFinder* connection_finder_; |
| 157 FakeAuthenticator* authenticator_; | 158 FakeAuthenticator* authenticator_; |
| 158 | 159 |
| 159 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); | 160 DISALLOW_COPY_AND_ASSIGN(TestableRemoteDeviceLifeCycleImpl); |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 } // namespace | 163 } // namespace |
| 163 | 164 |
| 164 class ProximityAuthRemoteDeviceLifeCycleImplTest | 165 class ProximityAuthRemoteDeviceLifeCycleImplTest |
| 165 : public testing::Test, | 166 : public testing::Test, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 233 |
| 233 TestableRemoteDeviceLifeCycleImpl life_cycle_; | 234 TestableRemoteDeviceLifeCycleImpl life_cycle_; |
| 234 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 235 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 235 base::ThreadTaskRunnerHandle thread_task_runner_handle_; | 236 base::ThreadTaskRunnerHandle thread_task_runner_handle_; |
| 236 | 237 |
| 237 private: | 238 private: |
| 238 DISALLOW_COPY_AND_ASSIGN(ProximityAuthRemoteDeviceLifeCycleImplTest); | 239 DISALLOW_COPY_AND_ASSIGN(ProximityAuthRemoteDeviceLifeCycleImplTest); |
| 239 }; | 240 }; |
| 240 | 241 |
| 241 TEST_F(ProximityAuthRemoteDeviceLifeCycleImplTest, GetRemoteDevice) { | 242 TEST_F(ProximityAuthRemoteDeviceLifeCycleImplTest, GetRemoteDevice) { |
| 242 RemoteDevice expected_remote_device = CreateClassicRemoteDeviceForTest(); | 243 cryptauth::RemoteDevice expected_remote_device = |
| 243 RemoteDevice remote_device = life_cycle_.GetRemoteDevice(); | 244 CreateClassicRemoteDeviceForTest(); |
| 245 cryptauth::RemoteDevice remote_device = life_cycle_.GetRemoteDevice(); |
| 244 EXPECT_EQ(expected_remote_device.user_id, remote_device.user_id); | 246 EXPECT_EQ(expected_remote_device.user_id, remote_device.user_id); |
| 245 EXPECT_EQ(expected_remote_device.name, remote_device.name); | 247 EXPECT_EQ(expected_remote_device.name, remote_device.name); |
| 246 EXPECT_EQ(expected_remote_device.public_key, remote_device.public_key); | 248 EXPECT_EQ(expected_remote_device.public_key, remote_device.public_key); |
| 247 EXPECT_EQ(expected_remote_device.bluetooth_address, | 249 EXPECT_EQ(expected_remote_device.bluetooth_address, |
| 248 remote_device.bluetooth_address); | 250 remote_device.bluetooth_address); |
| 249 EXPECT_EQ(expected_remote_device.persistent_symmetric_key, | 251 EXPECT_EQ(expected_remote_device.persistent_symmetric_key, |
| 250 remote_device.persistent_symmetric_key); | 252 remote_device.persistent_symmetric_key); |
| 251 } | 253 } |
| 252 | 254 |
| 253 TEST_F(ProximityAuthRemoteDeviceLifeCycleImplTest, AuthenticateAndDisconnect) { | 255 TEST_F(ProximityAuthRemoteDeviceLifeCycleImplTest, AuthenticateAndDisconnect) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 309 |
| 308 // Authentication succeeds on second pass. | 310 // Authentication succeeds on second pass. |
| 309 Connection* connection = OnConnectionFound(); | 311 Connection* connection = OnConnectionFound(); |
| 310 Authenticate(Authenticator::Result::SUCCESS); | 312 Authenticate(Authenticator::Result::SUCCESS); |
| 311 EXPECT_TRUE(life_cycle_.GetMessenger()); | 313 EXPECT_TRUE(life_cycle_.GetMessenger()); |
| 312 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); | 314 EXPECT_CALL(*this, OnLifeCycleStateChanged(_, _)); |
| 313 connection->Disconnect(); | 315 connection->Disconnect(); |
| 314 } | 316 } |
| 315 | 317 |
| 316 } // namespace proximity_auth | 318 } // namespace proximity_auth |
| OLD | NEW |