| 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/dbus/fake_easy_unlock_client.h" | 5 #include "chromeos/dbus/fake_easy_unlock_client.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 client.PerformECDHKeyAgreement(private_key, | 196 client.PerformECDHKeyAgreement(private_key, |
| 197 public_key, | 197 public_key, |
| 198 base::Bind(&RecordData, &shared_key)); | 198 base::Bind(&RecordData, &shared_key)); |
| 199 EXPECT_TRUE(shared_key.empty()); | 199 EXPECT_TRUE(shared_key.empty()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST(FakeEasyUnlockClientTest, CreateSecureMessage) { | 202 TEST(FakeEasyUnlockClientTest, CreateSecureMessage) { |
| 203 chromeos::FakeEasyUnlockClient client; | 203 chromeos::FakeEasyUnlockClient client; |
| 204 | 204 |
| 205 std::string message; | 205 std::string message; |
| 206 |
| 207 chromeos::EasyUnlockClient::CreateSecureMessageOptions options; |
| 208 options.key = "KEY"; |
| 209 options.associated_data = "ASSOCIATED_DATA"; |
| 210 options.public_metadata = "PUBLIC_METADATA"; |
| 211 options.verification_key_id = "VERIFICATION_KEY_ID"; |
| 212 options.decryption_key_id = "DECRYPTION_KEY_ID"; |
| 213 options.encryption_type = "ENCRYPTION_TYPE"; |
| 214 options.signature_type = "SIGNATURE_TYPE"; |
| 215 |
| 206 client.CreateSecureMessage( | 216 client.CreateSecureMessage( |
| 207 "PAYLOAD", | 217 "PAYLOAD", |
| 208 "KEY", | 218 options, |
| 209 "ASSOCIATED_DATA", | |
| 210 "PUBLIC_METADATA", | |
| 211 "VERIFICATION_KEY_ID", | |
| 212 "DECRYPTION_KEY_ID", | |
| 213 "ENCRYPTION_TYPE", | |
| 214 "SIGNATURE_TYPE", | |
| 215 base::Bind(&RecordData, &message)); | 219 base::Bind(&RecordData, &message)); |
| 216 | 220 |
| 217 const std::string expected_message( | 221 const std::string expected_message( |
| 218 "{\"securemessage\": {" | 222 "{\"securemessage\": {" |
| 219 "\"payload\": \"PAYLOAD\"," | 223 "\"payload\": \"PAYLOAD\"," |
| 220 "\"key\": \"KEY\"," | 224 "\"key\": \"KEY\"," |
| 221 "\"associated_data\": \"ASSOCIATED_DATA\"," | 225 "\"associated_data\": \"ASSOCIATED_DATA\"," |
| 222 "\"public_metadata\": \"PUBLIC_METADATA\"," | 226 "\"public_metadata\": \"PUBLIC_METADATA\"," |
| 223 "\"verification_key_id\": \"VERIFICATION_KEY_ID\"," | 227 "\"verification_key_id\": \"VERIFICATION_KEY_ID\"," |
| 224 "\"decryption_key_id\": \"DECRYPTION_KEY_ID\"," | 228 "\"decryption_key_id\": \"DECRYPTION_KEY_ID\"," |
| 225 "\"encryption_type\": \"ENCRYPTION_TYPE\"," | 229 "\"encryption_type\": \"ENCRYPTION_TYPE\"," |
| 226 "\"signature_type\": \"SIGNATURE_TYPE\"}" | 230 "\"signature_type\": \"SIGNATURE_TYPE\"}" |
| 227 "}"); | 231 "}"); |
| 228 ASSERT_EQ(expected_message, message); | 232 ASSERT_EQ(expected_message, message); |
| 229 } | 233 } |
| 230 | 234 |
| 231 TEST(FakeEasyUnlockClientTest, UnwrapSecureMessage) { | 235 TEST(FakeEasyUnlockClientTest, UnwrapSecureMessage) { |
| 232 chromeos::FakeEasyUnlockClient client; | 236 chromeos::FakeEasyUnlockClient client; |
| 233 | 237 |
| 234 std::string message; | 238 std::string message; |
| 239 |
| 240 chromeos::EasyUnlockClient::UnwrapSecureMessageOptions options; |
| 241 options.key = "KEY"; |
| 242 options.associated_data = "ASSOCIATED_DATA"; |
| 243 options.encryption_type = "ENCRYPTION_TYPE"; |
| 244 options.signature_type = "SIGNATURE_TYPE"; |
| 245 |
| 235 client.UnwrapSecureMessage( | 246 client.UnwrapSecureMessage( |
| 236 "MESSAGE", | 247 "MESSAGE", |
| 237 "KEY", | 248 options, |
| 238 "ASSOCIATED_DATA", | |
| 239 "ENCRYPTION_TYPE", | |
| 240 "SIGNATURE_TYPE", | |
| 241 base::Bind(&RecordData, &message)); | 249 base::Bind(&RecordData, &message)); |
| 242 | 250 |
| 243 const std::string expected_message( | 251 const std::string expected_message( |
| 244 "{\"unwrapped_securemessage\": {" | 252 "{\"unwrapped_securemessage\": {" |
| 245 "\"message\": \"MESSAGE\"," | 253 "\"message\": \"MESSAGE\"," |
| 246 "\"key\": \"KEY\"," | 254 "\"key\": \"KEY\"," |
| 247 "\"associated_data\": \"ASSOCIATED_DATA\"," | 255 "\"associated_data\": \"ASSOCIATED_DATA\"," |
| 248 "\"encryption_type\": \"ENCRYPTION_TYPE\"," | 256 "\"encryption_type\": \"ENCRYPTION_TYPE\"," |
| 249 "\"signature_type\": \"SIGNATURE_TYPE\"}" | 257 "\"signature_type\": \"SIGNATURE_TYPE\"}" |
| 250 "}"); | 258 "}"); |
| 251 ASSERT_EQ(expected_message, message); | 259 ASSERT_EQ(expected_message, message); |
| 252 } | 260 } |
| 253 | 261 |
| 254 } // namespace | 262 } // namespace |
| 255 | 263 |
| OLD | NEW |