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 "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 std::string expected_result; | 257 std::string expected_result; |
258 client_->CreateSecureMessage( | 258 client_->CreateSecureMessage( |
259 "PAYLOAD", | 259 "PAYLOAD", |
260 create_options, | 260 create_options, |
261 base::Bind(&CopyData, &expected_result)); | 261 base::Bind(&CopyData, &expected_result)); |
262 ASSERT_GT(expected_result.length(), 0u); | 262 ASSERT_GT(expected_result.length(), 0u); |
263 | 263 |
264 std::unique_ptr<base::ListValue> args(new base::ListValue); | 264 std::unique_ptr<base::ListValue> args(new base::ListValue); |
265 args->Append(StringToBinaryValue("PAYLOAD")); | 265 args->Append(StringToBinaryValue("PAYLOAD")); |
266 args->Append(StringToBinaryValue("KEY")); | 266 args->Append(StringToBinaryValue("KEY")); |
267 base::DictionaryValue* options = new base::DictionaryValue(); | 267 auto options = base::MakeUnique<base::DictionaryValue>(); |
268 args->Append(options); | |
269 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); | 268 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); |
270 options->Set("publicMetadata", StringToBinaryValue("PUBLIC_METADATA")); | 269 options->Set("publicMetadata", StringToBinaryValue("PUBLIC_METADATA")); |
271 options->Set("verificationKeyId", | 270 options->Set("verificationKeyId", |
272 StringToBinaryValue("VERIFICATION_KEY_ID")); | 271 StringToBinaryValue("VERIFICATION_KEY_ID")); |
273 options->Set("decryptionKeyId", | 272 options->Set("decryptionKeyId", |
274 StringToBinaryValue("DECRYPTION_KEY_ID")); | 273 StringToBinaryValue("DECRYPTION_KEY_ID")); |
275 options->SetString( | 274 options->SetString( |
276 "encryptType", | 275 "encryptType", |
277 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC)); | 276 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC)); |
278 options->SetString( | 277 options->SetString( |
279 "signType", | 278 "signType", |
280 api::ToString(api::SIGNATURE_TYPE_HMAC_SHA256)); | 279 api::ToString(api::SIGNATURE_TYPE_HMAC_SHA256)); |
| 280 args->Append(std::move(options)); |
281 | 281 |
282 ASSERT_TRUE(extension_function_test_utils::RunFunction( | 282 ASSERT_TRUE(extension_function_test_utils::RunFunction( |
283 function.get(), std::move(args), browser(), | 283 function.get(), std::move(args), browser(), |
284 extension_function_test_utils::NONE)); | 284 extension_function_test_utils::NONE)); |
285 | 285 |
286 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); | 286 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); |
287 } | 287 } |
288 | 288 |
289 TEST_F(EasyUnlockPrivateApiTest, CreateSecureMessage_EmptyOptions) { | 289 TEST_F(EasyUnlockPrivateApiTest, CreateSecureMessage_EmptyOptions) { |
290 scoped_refptr<EasyUnlockPrivateCreateSecureMessageFunction> function( | 290 scoped_refptr<EasyUnlockPrivateCreateSecureMessageFunction> function( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 std::string expected_result; | 331 std::string expected_result; |
332 client_->CreateSecureMessage( | 332 client_->CreateSecureMessage( |
333 "PAYLOAD", | 333 "PAYLOAD", |
334 create_options, | 334 create_options, |
335 base::Bind(&CopyData, &expected_result)); | 335 base::Bind(&CopyData, &expected_result)); |
336 ASSERT_GT(expected_result.length(), 0u); | 336 ASSERT_GT(expected_result.length(), 0u); |
337 | 337 |
338 std::unique_ptr<base::ListValue> args(new base::ListValue); | 338 std::unique_ptr<base::ListValue> args(new base::ListValue); |
339 args->Append(StringToBinaryValue("PAYLOAD")); | 339 args->Append(StringToBinaryValue("PAYLOAD")); |
340 args->Append(StringToBinaryValue("KEY")); | 340 args->Append(StringToBinaryValue("KEY")); |
341 base::DictionaryValue* options = new base::DictionaryValue(); | 341 auto options = base::MakeUnique<base::DictionaryValue>(); |
342 args->Append(options); | |
343 options->Set("associatedData", | 342 options->Set("associatedData", |
344 StringToBinaryValue("ASSOCIATED_DATA")); | 343 StringToBinaryValue("ASSOCIATED_DATA")); |
345 options->Set("verificationKeyId", | 344 options->Set("verificationKeyId", |
346 StringToBinaryValue("VERIFICATION_KEY_ID")); | 345 StringToBinaryValue("VERIFICATION_KEY_ID")); |
347 options->SetString( | 346 options->SetString( |
348 "signType", | 347 "signType", |
349 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256)); | 348 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256)); |
| 349 args->Append(std::move(options)); |
350 | 350 |
351 ASSERT_TRUE(extension_function_test_utils::RunFunction( | 351 ASSERT_TRUE(extension_function_test_utils::RunFunction( |
352 function.get(), std::move(args), browser(), | 352 function.get(), std::move(args), browser(), |
353 extension_function_test_utils::NONE)); | 353 extension_function_test_utils::NONE)); |
354 | 354 |
355 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); | 355 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); |
356 } | 356 } |
357 | 357 |
358 TEST_F(EasyUnlockPrivateApiTest, UnwrapSecureMessage) { | 358 TEST_F(EasyUnlockPrivateApiTest, UnwrapSecureMessage) { |
359 scoped_refptr<EasyUnlockPrivateUnwrapSecureMessageFunction> function( | 359 scoped_refptr<EasyUnlockPrivateUnwrapSecureMessageFunction> function( |
360 new EasyUnlockPrivateUnwrapSecureMessageFunction()); | 360 new EasyUnlockPrivateUnwrapSecureMessageFunction()); |
361 function->set_has_callback(true); | 361 function->set_has_callback(true); |
362 | 362 |
363 chromeos::EasyUnlockClient::UnwrapSecureMessageOptions unwrap_options; | 363 chromeos::EasyUnlockClient::UnwrapSecureMessageOptions unwrap_options; |
364 unwrap_options.key = "KEY"; | 364 unwrap_options.key = "KEY"; |
365 unwrap_options.associated_data = "ASSOCIATED_DATA"; | 365 unwrap_options.associated_data = "ASSOCIATED_DATA"; |
366 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; | 366 unwrap_options.encryption_type = easy_unlock::kEncryptionTypeAES256CBC; |
367 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; | 367 unwrap_options.signature_type = easy_unlock::kSignatureTypeHMACSHA256; |
368 | 368 |
369 std::string expected_result; | 369 std::string expected_result; |
370 client_->UnwrapSecureMessage( | 370 client_->UnwrapSecureMessage( |
371 "MESSAGE", | 371 "MESSAGE", |
372 unwrap_options, | 372 unwrap_options, |
373 base::Bind(&CopyData, &expected_result)); | 373 base::Bind(&CopyData, &expected_result)); |
374 ASSERT_GT(expected_result.length(), 0u); | 374 ASSERT_GT(expected_result.length(), 0u); |
375 | 375 |
376 std::unique_ptr<base::ListValue> args(new base::ListValue); | 376 std::unique_ptr<base::ListValue> args(new base::ListValue); |
377 args->Append(StringToBinaryValue("MESSAGE")); | 377 args->Append(StringToBinaryValue("MESSAGE")); |
378 args->Append(StringToBinaryValue("KEY")); | 378 args->Append(StringToBinaryValue("KEY")); |
379 base::DictionaryValue* options = new base::DictionaryValue(); | 379 auto options = base::MakeUnique<base::DictionaryValue>(); |
380 args->Append(options); | |
381 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); | 380 options->Set("associatedData", StringToBinaryValue("ASSOCIATED_DATA")); |
382 options->SetString( | 381 options->SetString( |
383 "encryptType", | 382 "encryptType", |
384 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC)); | 383 api::ToString(api::ENCRYPTION_TYPE_AES_256_CBC)); |
385 options->SetString( | 384 options->SetString( |
386 "signType", | 385 "signType", |
387 api::ToString(api::SIGNATURE_TYPE_HMAC_SHA256)); | 386 api::ToString(api::SIGNATURE_TYPE_HMAC_SHA256)); |
| 387 args->Append(std::move(options)); |
388 | 388 |
389 ASSERT_TRUE(extension_function_test_utils::RunFunction( | 389 ASSERT_TRUE(extension_function_test_utils::RunFunction( |
390 function.get(), std::move(args), browser(), | 390 function.get(), std::move(args), browser(), |
391 extension_function_test_utils::NONE)); | 391 extension_function_test_utils::NONE)); |
392 | 392 |
393 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); | 393 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); |
394 } | 394 } |
395 | 395 |
396 TEST_F(EasyUnlockPrivateApiTest, UnwrapSecureMessage_EmptyOptions) { | 396 TEST_F(EasyUnlockPrivateApiTest, UnwrapSecureMessage_EmptyOptions) { |
397 scoped_refptr<EasyUnlockPrivateUnwrapSecureMessageFunction> function( | 397 scoped_refptr<EasyUnlockPrivateUnwrapSecureMessageFunction> function( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 std::string expected_result; | 437 std::string expected_result; |
438 client_->UnwrapSecureMessage( | 438 client_->UnwrapSecureMessage( |
439 "MESSAGE", | 439 "MESSAGE", |
440 unwrap_options, | 440 unwrap_options, |
441 base::Bind(&CopyData, &expected_result)); | 441 base::Bind(&CopyData, &expected_result)); |
442 ASSERT_GT(expected_result.length(), 0u); | 442 ASSERT_GT(expected_result.length(), 0u); |
443 | 443 |
444 std::unique_ptr<base::ListValue> args(new base::ListValue); | 444 std::unique_ptr<base::ListValue> args(new base::ListValue); |
445 args->Append(StringToBinaryValue("MESSAGE")); | 445 args->Append(StringToBinaryValue("MESSAGE")); |
446 args->Append(StringToBinaryValue("KEY")); | 446 args->Append(StringToBinaryValue("KEY")); |
447 base::DictionaryValue* options = new base::DictionaryValue(); | 447 auto options = base::MakeUnique<base::DictionaryValue>(); |
448 args->Append(options); | |
449 options->Set("associatedData", | 448 options->Set("associatedData", |
450 StringToBinaryValue("ASSOCIATED_DATA")); | 449 StringToBinaryValue("ASSOCIATED_DATA")); |
451 options->SetString( | 450 options->SetString( |
452 "signType", | 451 "signType", |
453 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256)); | 452 api::ToString(api::SIGNATURE_TYPE_ECDSA_P256_SHA256)); |
| 453 args->Append(std::move(options)); |
454 | 454 |
455 ASSERT_TRUE(extension_function_test_utils::RunFunction( | 455 ASSERT_TRUE(extension_function_test_utils::RunFunction( |
456 function.get(), std::move(args), browser(), | 456 function.get(), std::move(args), browser(), |
457 extension_function_test_utils::NONE)); | 457 extension_function_test_utils::NONE)); |
458 | 458 |
459 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); | 459 EXPECT_EQ(expected_result, GetSingleBinaryResultAsString(function.get())); |
460 } | 460 } |
461 | 461 |
462 struct AutoPairingResult { | 462 struct AutoPairingResult { |
463 AutoPairingResult() : success(false) {} | 463 AutoPairingResult() : success(false) {} |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 | 654 |
655 scoped_refptr<TestableGetPermitAccessFunction> function( | 655 scoped_refptr<TestableGetPermitAccessFunction> function( |
656 new TestableGetPermitAccessFunction()); | 656 new TestableGetPermitAccessFunction()); |
657 std::unique_ptr<base::Value> value( | 657 std::unique_ptr<base::Value> value( |
658 extensions::api_test_utils::RunFunctionAndReturnSingleResult( | 658 extensions::api_test_utils::RunFunctionAndReturnSingleResult( |
659 function.get(), "[]", profile())); | 659 function.get(), "[]", profile())); |
660 EXPECT_FALSE(value); | 660 EXPECT_FALSE(value); |
661 } | 661 } |
662 | 662 |
663 } // namespace | 663 } // namespace |
OLD | NEW |