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

Side by Side Diff: components/cryptauth/remote_device_loader_unittest.cc

Issue 2859053003: [EasyUnlock] Add beacon_seeds to RemoteDevice. (Closed)
Patch Set: fixes Created 3 years, 7 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
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/cryptauth/remote_device_loader.h" 5 #include "components/cryptauth/remote_device_loader.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 11 matching lines...) Expand all
22 const char kDeviceNamePrefix[] = "device"; 22 const char kDeviceNamePrefix[] = "device";
23 const char kPublicKeyPrefix[] = "pk"; 23 const char kPublicKeyPrefix[] = "pk";
24 const char kBluetoothAddressPrefix[] = "11:22:33:44:55:0"; 24 const char kBluetoothAddressPrefix[] = "11:22:33:44:55:0";
25 25
26 // The id of the user who the remote devices belong to. 26 // The id of the user who the remote devices belong to.
27 const char kUserId[] = "example@gmail.com"; 27 const char kUserId[] = "example@gmail.com";
28 28
29 // The public key of the user's local device. 29 // The public key of the user's local device.
30 const char kUserPublicKey[] = "User public key"; 30 const char kUserPublicKey[] = "User public key";
31 31
32 // BeaconSeed values.
33 const int64_t kBeaconSeedStartTimeMs = 1000;
34 const int64_t kBeaconSeedEndTimeMs = 2000;
35 const char kBeaconSeedData[] = "Beacon Seed Data";
36
32 // Creates and returns an ExternalDeviceInfo proto with the fields appended with 37 // Creates and returns an ExternalDeviceInfo proto with the fields appended with
33 // |suffix|. 38 // |suffix|.
34 cryptauth::ExternalDeviceInfo CreateDeviceInfo(const std::string& suffix) { 39 cryptauth::ExternalDeviceInfo CreateDeviceInfo(const std::string& suffix) {
35 cryptauth::ExternalDeviceInfo device_info; 40 cryptauth::ExternalDeviceInfo device_info;
36 device_info.set_friendly_device_name(std::string(kDeviceNamePrefix) + suffix); 41 device_info.set_friendly_device_name(std::string(kDeviceNamePrefix) + suffix);
37 device_info.set_public_key(std::string(kPublicKeyPrefix) + suffix); 42 device_info.set_public_key(std::string(kPublicKeyPrefix) + suffix);
38 device_info.set_bluetooth_address(std::string(kBluetoothAddressPrefix) + 43 device_info.set_bluetooth_address(std::string(kBluetoothAddressPrefix) +
39 suffix); 44 suffix);
45 device_info.add_beacon_seeds();
46 BeaconSeed* beacon_seed = device_info.mutable_beacon_seeds(0);
47 beacon_seed->set_start_time_millis(kBeaconSeedStartTimeMs);
48 beacon_seed->set_end_time_millis(kBeaconSeedEndTimeMs);
49 beacon_seed->set_data(kBeaconSeedData);
40 return device_info; 50 return device_info;
41 } 51 }
42 52
43 } // namespace 53 } // namespace
44 54
45 class CryptAuthRemoteDeviceLoaderTest : public testing::Test { 55 class CryptAuthRemoteDeviceLoaderTest : public testing::Test {
46 public: 56 public:
47 CryptAuthRemoteDeviceLoaderTest() 57 CryptAuthRemoteDeviceLoaderTest()
48 : secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()), 58 : secure_message_delegate_(new cryptauth::FakeSecureMessageDelegate()),
49 user_private_key_(secure_message_delegate_->GetPrivateKeyForPublicKey( 59 user_private_key_(secure_message_delegate_->GetPrivateKeyForPublicKey(
(...skipping 25 matching lines...) Expand all
75 }; 85 };
76 86
77 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadZeroDevices) { 87 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadZeroDevices) {
78 std::vector<cryptauth::ExternalDeviceInfo> device_infos; 88 std::vector<cryptauth::ExternalDeviceInfo> device_infos;
79 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, 89 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
80 std::move(secure_message_delegate_)); 90 std::move(secure_message_delegate_));
81 91
82 std::vector<cryptauth::RemoteDevice> result; 92 std::vector<cryptauth::RemoteDevice> result;
83 EXPECT_CALL(*this, LoadCompleted()); 93 EXPECT_CALL(*this, LoadCompleted());
84 loader.Load( 94 loader.Load(
85 base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, 95 false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
86 base::Unretained(this))); 96 base::Unretained(this)));
87 97
88 EXPECT_EQ(0u, remote_devices_.size()); 98 EXPECT_EQ(0u, remote_devices_.size());
89 } 99 }
90 100
101 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithBeaconSeeds) {
102 std::vector<cryptauth::ExternalDeviceInfo> device_infos(
103 1, CreateDeviceInfo("0"));
104 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
105 std::move(secure_message_delegate_));
106
107 std::vector<cryptauth::RemoteDevice> result;
108 EXPECT_CALL(*this, LoadCompleted());
109 loader.Load(
110 true, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
111 base::Unretained(this)));
112
113 EXPECT_EQ(1u, remote_devices_.size());
114 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty());
115 EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name);
116 EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
117 ASSERT_EQ(1u, remote_devices_[0].beacon_seeds.size());
118
119 const BeaconSeed& beacon_seed = remote_devices_[0].beacon_seeds[0];
120 EXPECT_EQ(kBeaconSeedData, beacon_seed.data());
121 EXPECT_EQ(kBeaconSeedStartTimeMs, beacon_seed.start_time_millis());
122 EXPECT_EQ(kBeaconSeedEndTimeMs, beacon_seed.end_time_millis());
123 }
124
91 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithAddress) { 125 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithAddress) {
92 std::vector<cryptauth::ExternalDeviceInfo> device_infos(1, 126 std::vector<cryptauth::ExternalDeviceInfo> device_infos(1,
93 CreateDeviceInfo("0")); 127 CreateDeviceInfo("0"));
94 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, 128 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
95 std::move(secure_message_delegate_)); 129 std::move(secure_message_delegate_));
96 130
97 std::vector<cryptauth::RemoteDevice> result; 131 std::vector<cryptauth::RemoteDevice> result;
98 EXPECT_CALL(*this, LoadCompleted()); 132 EXPECT_CALL(*this, LoadCompleted());
99 loader.Load( 133 loader.Load(
100 base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, 134 false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
101 base::Unretained(this))); 135 base::Unretained(this)));
102 136
103 EXPECT_EQ(1u, remote_devices_.size()); 137 EXPECT_EQ(1u, remote_devices_.size());
104 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); 138 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty());
105 EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name); 139 EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name);
106 EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key); 140 EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
107 EXPECT_EQ(device_infos[0].bluetooth_address(), 141 EXPECT_EQ(device_infos[0].bluetooth_address(),
108 remote_devices_[0].bluetooth_address); 142 remote_devices_[0].bluetooth_address);
143 EXPECT_EQ(0u, remote_devices_[0].beacon_seeds.size());
109 } 144 }
110 145
111 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithoutAddress) { 146 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithoutAddress) {
112 std::vector<cryptauth::ExternalDeviceInfo> device_infos(1, 147 std::vector<cryptauth::ExternalDeviceInfo> device_infos(1,
113 CreateDeviceInfo("0")); 148 CreateDeviceInfo("0"));
114 device_infos[0].set_bluetooth_address(std::string()); 149 device_infos[0].set_bluetooth_address(std::string());
115 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, 150 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
116 std::move(secure_message_delegate_)); 151 std::move(secure_message_delegate_));
117 152
118 std::vector<cryptauth::RemoteDevice> result; 153 std::vector<cryptauth::RemoteDevice> result;
119 EXPECT_CALL(*this, LoadCompleted()); 154 EXPECT_CALL(*this, LoadCompleted());
120 loader.Load( 155 loader.Load(
121 base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, 156 false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
122 base::Unretained(this))); 157 base::Unretained(this)));
123 158
124 EXPECT_EQ(1u, remote_devices_.size()); 159 EXPECT_EQ(1u, remote_devices_.size());
125 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty()); 160 EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty());
126 EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name); 161 EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name);
127 EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key); 162 EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
128 EXPECT_EQ("", remote_devices_[0].bluetooth_address); 163 EXPECT_EQ("", remote_devices_[0].bluetooth_address);
129 } 164 }
130 165
131 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadThreeRemoteDevices) { 166 TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadThreeRemoteDevices) {
132 std::vector<cryptauth::ExternalDeviceInfo> device_infos; 167 std::vector<cryptauth::ExternalDeviceInfo> device_infos;
133 device_infos.push_back(CreateDeviceInfo("0")); 168 device_infos.push_back(CreateDeviceInfo("0"));
134 device_infos.push_back(CreateDeviceInfo("1")); 169 device_infos.push_back(CreateDeviceInfo("1"));
135 device_infos.push_back(CreateDeviceInfo("2")); 170 device_infos.push_back(CreateDeviceInfo("2"));
136 171
137 // Devices 0 and 1 do not have a Bluetooth address, but device 2 does. 172 // Devices 0 and 1 do not have a Bluetooth address, but device 2 does.
138 device_infos[0].set_bluetooth_address(std::string()); 173 device_infos[0].set_bluetooth_address(std::string());
139 device_infos[1].set_bluetooth_address(std::string()); 174 device_infos[1].set_bluetooth_address(std::string());
140 175
141 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId, 176 RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
142 std::move(secure_message_delegate_)); 177 std::move(secure_message_delegate_));
143 178
144 EXPECT_CALL(*this, LoadCompleted()); 179 EXPECT_CALL(*this, LoadCompleted());
145 loader.Load( 180 loader.Load(
146 base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded, 181 false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
147 base::Unretained(this))); 182 base::Unretained(this)));
148 183
149 EXPECT_EQ(3u, remote_devices_.size()); 184 EXPECT_EQ(3u, remote_devices_.size());
150 for (size_t i = 0; i < 3; ++i) { 185 for (size_t i = 0; i < 3; ++i) {
151 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty()); 186 EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty());
152 EXPECT_EQ(device_infos[i].friendly_device_name(), remote_devices_[i].name); 187 EXPECT_EQ(device_infos[i].friendly_device_name(), remote_devices_[i].name);
153 EXPECT_EQ(device_infos[i].public_key(), remote_devices_[i].public_key); 188 EXPECT_EQ(device_infos[i].public_key(), remote_devices_[i].public_key);
154 EXPECT_EQ(device_infos[i].bluetooth_address(), 189 EXPECT_EQ(device_infos[i].bluetooth_address(),
155 remote_devices_[i].bluetooth_address); 190 remote_devices_[i].bluetooth_address);
156 } 191 }
157 } 192 }
158 193
159 } // namespace cryptauth 194 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698