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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 HomedirMethodsTest(); | 48 HomedirMethodsTest(); |
49 virtual ~HomedirMethodsTest(); | 49 virtual ~HomedirMethodsTest(); |
50 | 50 |
51 // testing::Test: | 51 // testing::Test: |
52 virtual void SetUp() OVERRIDE; | 52 virtual void SetUp() OVERRIDE; |
53 virtual void TearDown() OVERRIDE; | 53 virtual void TearDown() OVERRIDE; |
54 | 54 |
55 void RunProtobufMethodCallback( | 55 void RunProtobufMethodCallback( |
56 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback); | 56 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback); |
57 | 57 |
58 void StoreGetKeyDataExResult(bool success, | 58 void StoreGetKeyDataExResult( |
59 MountError return_code, | 59 bool success, |
60 ScopedVector<RetrievedKeyData> key_data); | 60 MountError return_code, |
| 61 const std::vector<KeyDefinition>& key_definitions); |
61 | 62 |
62 protected: | 63 protected: |
63 chromeos::MockCryptohomeClient* cryptohome_client_; | 64 chromeos::MockCryptohomeClient* cryptohome_client_; |
64 | 65 |
65 // The reply that |cryptohome_client_| will make. | 66 // The reply that |cryptohome_client_| will make. |
66 cryptohome::BaseReply cryptohome_reply_; | 67 cryptohome::BaseReply cryptohome_reply_; |
67 | 68 |
68 // The results of the most recent |HomedirMethods| method call. | 69 // The results of the most recent |HomedirMethods| method call. |
69 bool success_; | 70 bool success_; |
70 MountError return_code_; | 71 MountError return_code_; |
71 ScopedVector<RetrievedKeyData> key_data_; | 72 std::vector<KeyDefinition> key_definitions_; |
72 | 73 |
73 private: | 74 private: |
74 DISALLOW_COPY_AND_ASSIGN(HomedirMethodsTest); | 75 DISALLOW_COPY_AND_ASSIGN(HomedirMethodsTest); |
75 }; | 76 }; |
76 | 77 |
77 HomedirMethodsTest::HomedirMethodsTest() : cryptohome_client_(NULL), | 78 HomedirMethodsTest::HomedirMethodsTest() : cryptohome_client_(NULL), |
78 success_(false), | 79 success_(false), |
79 return_code_(MOUNT_ERROR_FATAL) { | 80 return_code_(MOUNT_ERROR_FATAL) { |
80 } | 81 } |
81 | 82 |
(...skipping 17 matching lines...) Expand all Loading... |
99 void HomedirMethodsTest::RunProtobufMethodCallback( | 100 void HomedirMethodsTest::RunProtobufMethodCallback( |
100 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { | 101 const chromeos::CryptohomeClient::ProtobufMethodCallback& callback) { |
101 callback.Run(chromeos::DBUS_METHOD_CALL_SUCCESS, | 102 callback.Run(chromeos::DBUS_METHOD_CALL_SUCCESS, |
102 true, | 103 true, |
103 cryptohome_reply_); | 104 cryptohome_reply_); |
104 } | 105 } |
105 | 106 |
106 void HomedirMethodsTest::StoreGetKeyDataExResult( | 107 void HomedirMethodsTest::StoreGetKeyDataExResult( |
107 bool success, | 108 bool success, |
108 MountError return_code, | 109 MountError return_code, |
109 ScopedVector<RetrievedKeyData> key_data) { | 110 const std::vector<KeyDefinition>& key_definitions) { |
110 success_ = success; | 111 success_ = success; |
111 return_code_ = return_code; | 112 return_code_ = return_code; |
112 key_data_.swap(key_data); | 113 key_definitions_ = key_definitions; |
113 } | 114 } |
114 | 115 |
115 // Verifies that the result of a GetKeyDataEx() call is correctly parsed. | 116 // Verifies that the result of a GetKeyDataEx() call is correctly parsed. |
116 TEST_F(HomedirMethodsTest, GetKeyDataEx) { | 117 TEST_F(HomedirMethodsTest, GetKeyDataEx) { |
117 AccountIdentifier expected_id; | 118 AccountIdentifier expected_id; |
118 expected_id.set_email(kUserID); | 119 expected_id.set_email(kUserID); |
119 const cryptohome::AuthorizationRequest expected_auth; | 120 const cryptohome::AuthorizationRequest expected_auth; |
120 cryptohome::GetKeyDataRequest expected_request; | 121 cryptohome::GetKeyDataRequest expected_request; |
121 expected_request.mutable_key()->mutable_data()->set_label(kKeyLabel); | 122 expected_request.mutable_key()->mutable_data()->set_label(kKeyLabel); |
122 | 123 |
(...skipping 28 matching lines...) Expand all Loading... |
151 // Call GetKeyDataEx(). | 152 // Call GetKeyDataEx(). |
152 HomedirMethods::GetInstance()->GetKeyDataEx( | 153 HomedirMethods::GetInstance()->GetKeyDataEx( |
153 Identification(kUserID), | 154 Identification(kUserID), |
154 kKeyLabel, | 155 kKeyLabel, |
155 base::Bind(&HomedirMethodsTest::StoreGetKeyDataExResult, | 156 base::Bind(&HomedirMethodsTest::StoreGetKeyDataExResult, |
156 base::Unretained(this))); | 157 base::Unretained(this))); |
157 | 158 |
158 // Verify that the call was successful and the result was correctly parsed. | 159 // Verify that the call was successful and the result was correctly parsed. |
159 EXPECT_TRUE(success_); | 160 EXPECT_TRUE(success_); |
160 EXPECT_EQ(MOUNT_ERROR_NONE, return_code_); | 161 EXPECT_EQ(MOUNT_ERROR_NONE, return_code_); |
161 ASSERT_EQ(1u, key_data_.size()); | 162 ASSERT_EQ(1u, key_definitions_.size()); |
162 const RetrievedKeyData* retrieved_key_data = key_data_.front(); | 163 const KeyDefinition& key_definition = key_definitions_.front(); |
163 EXPECT_EQ(RetrievedKeyData::TYPE_PASSWORD, retrieved_key_data->type); | 164 EXPECT_EQ(KeyDefinition::TYPE_PASSWORD, key_definition.type); |
164 EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE, | 165 EXPECT_EQ(PRIV_MOUNT | PRIV_ADD | PRIV_REMOVE, |
165 retrieved_key_data->privileges); | 166 key_definition.privileges); |
166 EXPECT_EQ(kKeyRevision, retrieved_key_data->revision); | 167 EXPECT_EQ(kKeyRevision, key_definition.revision); |
167 ASSERT_EQ(1u, retrieved_key_data->authorization_types.size()); | 168 ASSERT_EQ(1u, key_definition.authorization_data.size()); |
168 EXPECT_EQ(RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256, | 169 EXPECT_EQ(KeyDefinition::AuthorizationData::TYPE_HMACSHA256, |
169 retrieved_key_data->authorization_types.front()); | 170 key_definition.authorization_data.front().type); |
170 ASSERT_EQ(2u, retrieved_key_data->provider_data.size()); | 171 ASSERT_EQ(2u, key_definition.provider_data.size()); |
171 const RetrievedKeyData::ProviderData* provider_data = | 172 const KeyDefinition::ProviderData* provider_data = |
172 retrieved_key_data->provider_data[0]; | 173 &key_definition.provider_data[0]; |
173 EXPECT_EQ(kProviderData1Name, provider_data->name); | 174 EXPECT_EQ(kProviderData1Name, provider_data->name); |
174 ASSERT_TRUE(provider_data->number); | 175 ASSERT_TRUE(provider_data->number); |
175 EXPECT_EQ(kProviderData1Number, *provider_data->number.get()); | 176 EXPECT_EQ(kProviderData1Number, *provider_data->number.get()); |
176 EXPECT_FALSE(provider_data->bytes); | 177 EXPECT_FALSE(provider_data->bytes); |
177 provider_data = retrieved_key_data->provider_data[1]; | 178 provider_data = &key_definition.provider_data[1]; |
178 EXPECT_EQ(kProviderData2Name, provider_data->name); | 179 EXPECT_EQ(kProviderData2Name, provider_data->name); |
179 EXPECT_FALSE(provider_data->number); | 180 EXPECT_FALSE(provider_data->number); |
180 ASSERT_TRUE(provider_data->bytes); | 181 ASSERT_TRUE(provider_data->bytes); |
181 EXPECT_EQ(kProviderData2Bytes, *provider_data->bytes.get()); | 182 EXPECT_EQ(kProviderData2Bytes, *provider_data->bytes.get()); |
182 } | 183 } |
183 | 184 |
184 } // namespace cryptohome | 185 } // namespace cryptohome |
OLD | NEW |