OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/cryptohome/homedir_methods.h" | 5 #include "chromeos/cryptohome/homedir_methods.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 15 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
16 #include "chromeos/dbus/cryptohome_client.h" | 16 #include "chromeos/dbus/cryptohome_client.h" |
17 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 18 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/dbus/mock_cryptohome_client.h" | 19 #include "chromeos/dbus/mock_cryptohome_client.h" |
20 #include "components/signin/core/account_id/account_id.h" | |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using testing::_; | 24 using testing::_; |
24 using testing::Invoke; | 25 using testing::Invoke; |
25 using testing::WithArg; | 26 using testing::WithArg; |
26 | 27 |
27 namespace cryptohome { | 28 namespace cryptohome { |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 MountError return_code, | 114 MountError return_code, |
114 const std::vector<KeyDefinition>& key_definitions) { | 115 const std::vector<KeyDefinition>& key_definitions) { |
115 success_ = success; | 116 success_ = success; |
116 return_code_ = return_code; | 117 return_code_ = return_code; |
117 key_definitions_ = key_definitions; | 118 key_definitions_ = key_definitions; |
118 } | 119 } |
119 | 120 |
120 // Verifies that the result of a GetKeyDataEx() call is correctly parsed. | 121 // Verifies that the result of a GetKeyDataEx() call is correctly parsed. |
121 TEST_F(HomedirMethodsTest, GetKeyDataEx) { | 122 TEST_F(HomedirMethodsTest, GetKeyDataEx) { |
122 AccountIdentifier expected_id; | 123 AccountIdentifier expected_id; |
123 expected_id.set_email(kUserID); | 124 expected_id.set_account_id( |
125 cryptohome::Identification(AccountId::FromUserEmail(kUserID)).id()); | |
xiyuan
2016/02/17 23:14:26
nit: remove "cryptohome::" since it is already in
Alexander Alekseev
2016/02/18 13:45:14
Done.
| |
124 const cryptohome::AuthorizationRequest expected_auth; | 126 const cryptohome::AuthorizationRequest expected_auth; |
125 cryptohome::GetKeyDataRequest expected_request; | 127 cryptohome::GetKeyDataRequest expected_request; |
126 expected_request.mutable_key()->mutable_data()->set_label(kKeyLabel); | 128 expected_request.mutable_key()->mutable_data()->set_label(kKeyLabel); |
127 | 129 |
128 EXPECT_CALL(*cryptohome_client_, | 130 EXPECT_CALL(*cryptohome_client_, |
129 GetKeyDataEx(EqualsProto(expected_id), | 131 GetKeyDataEx(EqualsProto(expected_id), |
130 EqualsProto(expected_auth), | 132 EqualsProto(expected_auth), |
131 EqualsProto(expected_request), | 133 EqualsProto(expected_request), |
132 _)) | 134 _)) |
133 .Times(1) | 135 .Times(1) |
(...skipping 14 matching lines...) Expand all Loading... | |
148 KeyProviderData* data = key_data->mutable_provider_data(); | 150 KeyProviderData* data = key_data->mutable_provider_data(); |
149 KeyProviderData::Entry* entry = data->add_entry(); | 151 KeyProviderData::Entry* entry = data->add_entry(); |
150 entry->set_name(kProviderData1Name); | 152 entry->set_name(kProviderData1Name); |
151 entry->set_number(kProviderData1Number); | 153 entry->set_number(kProviderData1Number); |
152 entry = data->add_entry(); | 154 entry = data->add_entry(); |
153 entry->set_name(kProviderData2Name); | 155 entry->set_name(kProviderData2Name); |
154 entry->set_bytes(kProviderData2Bytes); | 156 entry->set_bytes(kProviderData2Bytes); |
155 | 157 |
156 // Call GetKeyDataEx(). | 158 // Call GetKeyDataEx(). |
157 HomedirMethods::GetInstance()->GetKeyDataEx( | 159 HomedirMethods::GetInstance()->GetKeyDataEx( |
158 Identification(kUserID), | 160 Identification(AccountId::FromUserEmail(kUserID)), kKeyLabel, |
159 kKeyLabel, | 161 base::Bind(&HomedirMethodsTest::StoreGetKeyDataExResult, |
160 base::Bind(&HomedirMethodsTest::StoreGetKeyDataExResult, | 162 base::Unretained(this))); |
161 base::Unretained(this))); | |
162 | 163 |
163 // Verify that the call was successful and the result was correctly parsed. | 164 // Verify that the call was successful and the result was correctly parsed. |
164 EXPECT_TRUE(success_); | 165 EXPECT_TRUE(success_); |
165 EXPECT_EQ(MOUNT_ERROR_NONE, return_code_); | 166 EXPECT_EQ(MOUNT_ERROR_NONE, return_code_); |
166 ASSERT_EQ(1u, key_definitions_.size()); | 167 ASSERT_EQ(1u, key_definitions_.size()); |
167 const KeyDefinition& key_definition = key_definitions_.front(); | 168 const KeyDefinition& key_definition = key_definitions_.front(); |
168 EXPECT_EQ(KeyDefinition::TYPE_PASSWORD, key_definition.type); | 169 EXPECT_EQ(KeyDefinition::TYPE_PASSWORD, key_definition.type); |
169 EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE, | 170 EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE, |
170 key_definition.privileges); | 171 key_definition.privileges); |
171 EXPECT_EQ(kKeyRevision, key_definition.revision); | 172 EXPECT_EQ(kKeyRevision, key_definition.revision); |
172 ASSERT_EQ(1u, key_definition.authorization_data.size()); | 173 ASSERT_EQ(1u, key_definition.authorization_data.size()); |
173 EXPECT_EQ(KeyDefinition::AuthorizationData::TYPE_HMACSHA256, | 174 EXPECT_EQ(KeyDefinition::AuthorizationData::TYPE_HMACSHA256, |
174 key_definition.authorization_data.front().type); | 175 key_definition.authorization_data.front().type); |
175 ASSERT_EQ(2u, key_definition.provider_data.size()); | 176 ASSERT_EQ(2u, key_definition.provider_data.size()); |
176 const KeyDefinition::ProviderData* provider_data = | 177 const KeyDefinition::ProviderData* provider_data = |
177 &key_definition.provider_data[0]; | 178 &key_definition.provider_data[0]; |
178 EXPECT_EQ(kProviderData1Name, provider_data->name); | 179 EXPECT_EQ(kProviderData1Name, provider_data->name); |
179 ASSERT_TRUE(provider_data->number); | 180 ASSERT_TRUE(provider_data->number); |
180 EXPECT_EQ(kProviderData1Number, *provider_data->number.get()); | 181 EXPECT_EQ(kProviderData1Number, *provider_data->number.get()); |
181 EXPECT_FALSE(provider_data->bytes); | 182 EXPECT_FALSE(provider_data->bytes); |
182 provider_data = &key_definition.provider_data[1]; | 183 provider_data = &key_definition.provider_data[1]; |
183 EXPECT_EQ(kProviderData2Name, provider_data->name); | 184 EXPECT_EQ(kProviderData2Name, provider_data->name); |
184 EXPECT_FALSE(provider_data->number); | 185 EXPECT_FALSE(provider_data->number); |
185 ASSERT_TRUE(provider_data->bytes); | 186 ASSERT_TRUE(provider_data->bytes); |
186 EXPECT_EQ(kProviderData2Bytes, *provider_data->bytes.get()); | 187 EXPECT_EQ(kProviderData2Bytes, *provider_data->bytes.get()); |
187 } | 188 } |
188 | 189 |
189 } // namespace cryptohome | 190 } // namespace cryptohome |
OLD | NEW |