OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "remoting/host/it2me/it2me_host.h" | 5 #include "remoting/host/it2me/it2me_host.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 | 347 |
348 TEST_F(It2MeHostTest, HostValidation_HostDomainPolicy_MatchEnd) { | 348 TEST_F(It2MeHostTest, HostValidation_HostDomainPolicy_MatchEnd) { |
349 SetPolicies({{policy::key::kRemoteAccessHostDomain, | 349 SetPolicies({{policy::key::kRemoteAccessHostDomain, |
350 base::Value(kMismatchedDomain1)}}); | 350 base::Value(kMismatchedDomain1)}}); |
351 StartHost(); | 351 StartHost(); |
352 ASSERT_EQ(It2MeHostState::kInvalidDomainError, last_host_state_); | 352 ASSERT_EQ(It2MeHostState::kInvalidDomainError, last_host_state_); |
353 ShutdownHost(); | 353 ShutdownHost(); |
354 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 354 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
355 } | 355 } |
356 | 356 |
| 357 TEST_F(It2MeHostTest, HostValidation_HostDomainListPolicy_MatchFirst) { |
| 358 base::ListValue domains; |
| 359 domains.AppendString(kMatchingDomain); |
| 360 domains.AppendString(kMismatchedDomain1); |
| 361 SetPolicies({{policy::key::kRemoteAccessHostDomainList, domains}}); |
| 362 StartHost(); |
| 363 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); |
| 364 ShutdownHost(); |
| 365 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 366 } |
| 367 |
| 368 TEST_F(It2MeHostTest, HostValidation_HostDomainListPolicy_MatchSecond) { |
| 369 base::ListValue domains; |
| 370 domains.AppendString(kMismatchedDomain1); |
| 371 domains.AppendString(kMatchingDomain); |
| 372 SetPolicies({{policy::key::kRemoteAccessHostDomainList, domains}}); |
| 373 StartHost(); |
| 374 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); |
| 375 ShutdownHost(); |
| 376 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 377 } |
| 378 |
| 379 TEST_F(It2MeHostTest, HostValidation_HostDomainListPolicy_NoMatch) { |
| 380 base::ListValue domains; |
| 381 domains.AppendString(kMismatchedDomain1); |
| 382 domains.AppendString(kMismatchedDomain2); |
| 383 SetPolicies({{policy::key::kRemoteAccessHostDomainList, domains}}); |
| 384 StartHost(); |
| 385 ASSERT_EQ(It2MeHostState::kInvalidDomainError, last_host_state_); |
| 386 ShutdownHost(); |
| 387 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 388 } |
| 389 |
| 390 TEST_F(It2MeHostTest, HostValidation_HostDomainBothPolicies_BothMatch) { |
| 391 base::ListValue domains; |
| 392 domains.AppendString(kMatchingDomain); |
| 393 domains.AppendString(kMismatchedDomain1); |
| 394 SetPolicies( |
| 395 {{policy::key::kRemoteAccessHostDomain, base::Value(kMatchingDomain)}, |
| 396 {policy::key::kRemoteAccessHostDomainList, domains}}); |
| 397 StartHost(); |
| 398 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); |
| 399 ShutdownHost(); |
| 400 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 401 } |
| 402 |
| 403 TEST_F(It2MeHostTest, HostValidation_HostDomainBothPolicies_ListMatch) { |
| 404 base::ListValue domains; |
| 405 domains.AppendString(kMismatchedDomain1); |
| 406 domains.AppendString(kMatchingDomain); |
| 407 SetPolicies( |
| 408 {{policy::key::kRemoteAccessHostDomain, base::Value(kMismatchedDomain1)}, |
| 409 {policy::key::kRemoteAccessHostDomainList, domains}}); |
| 410 // Should succeed even though the legacy policy would deny. |
| 411 StartHost(); |
| 412 ASSERT_EQ(It2MeHostState::kReceivedAccessCode, last_host_state_); |
| 413 ShutdownHost(); |
| 414 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 415 } |
| 416 |
| 417 TEST_F(It2MeHostTest, HostValidation_HostDomainBothPolicies_LegacyMatch) { |
| 418 base::ListValue domains; |
| 419 domains.AppendString(kMismatchedDomain1); |
| 420 domains.AppendString(kMismatchedDomain2); |
| 421 SetPolicies( |
| 422 {{policy::key::kRemoteAccessHostDomain, base::Value(kMatchingDomain)}, |
| 423 {policy::key::kRemoteAccessHostDomainList, domains}}); |
| 424 // Should fail even though the legacy policy would allow. |
| 425 StartHost(); |
| 426 ASSERT_EQ(It2MeHostState::kInvalidDomainError, last_host_state_); |
| 427 ShutdownHost(); |
| 428 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 429 } |
| 430 |
357 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) { | 431 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_ValidJid) { |
358 StartHost(); | 432 StartHost(); |
359 RunValidationCallback(kTestClientJid); | 433 RunValidationCallback(kTestClientJid); |
360 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 434 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
361 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); | 435 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
362 ShutdownHost(); | 436 ShutdownHost(); |
363 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 437 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
364 } | 438 } |
365 | 439 |
366 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) { | 440 TEST_F(It2MeHostTest, ConnectionValidation_NoClientDomainPolicy_InvalidJid) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { | 518 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { |
445 SetPolicies({{policy::key::kRemoteAccessHostClientDomain, | 519 SetPolicies({{policy::key::kRemoteAccessHostClientDomain, |
446 base::Value(kMismatchedDomain1)}}); | 520 base::Value(kMismatchedDomain1)}}); |
447 StartHost(); | 521 StartHost(); |
448 RunValidationCallback(kTestClientJid); | 522 RunValidationCallback(kTestClientJid); |
449 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 523 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
450 RunUntilStateChanged(It2MeHostState::kDisconnected); | 524 RunUntilStateChanged(It2MeHostState::kDisconnected); |
451 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 525 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
452 } | 526 } |
453 | 527 |
| 528 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_MatchFirst) { |
| 529 base::ListValue domains; |
| 530 domains.AppendString(kMatchingDomain); |
| 531 domains.AppendString(kMismatchedDomain1); |
| 532 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 533 StartHost(); |
| 534 RunValidationCallback(kTestClientJid); |
| 535 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 536 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 537 ShutdownHost(); |
| 538 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 539 } |
| 540 |
| 541 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_MatchSecond) { |
| 542 base::ListValue domains; |
| 543 domains.AppendString(kMismatchedDomain1); |
| 544 domains.AppendString(kMatchingDomain); |
| 545 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 546 StartHost(); |
| 547 RunValidationCallback(kTestClientJid); |
| 548 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 549 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 550 ShutdownHost(); |
| 551 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 552 } |
| 553 |
| 554 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_NoMatch) { |
| 555 base::ListValue domains; |
| 556 domains.AppendString(kMismatchedDomain1); |
| 557 domains.AppendString(kMismatchedDomain2); |
| 558 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 559 StartHost(); |
| 560 RunValidationCallback(kTestClientJid); |
| 561 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 562 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 563 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 564 } |
| 565 |
| 566 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainBothPolicies_BothMatch) { |
| 567 base::ListValue domains; |
| 568 domains.AppendString(kMatchingDomain); |
| 569 domains.AppendString(kMismatchedDomain1); |
| 570 SetPolicies({{policy::key::kRemoteAccessHostClientDomain, |
| 571 base::Value(kMatchingDomain)}, |
| 572 {policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 573 StartHost(); |
| 574 RunValidationCallback(kTestClientJid); |
| 575 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 576 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 577 ShutdownHost(); |
| 578 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 579 } |
| 580 |
| 581 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainBothPolicies_ListMatch) { |
| 582 base::ListValue domains; |
| 583 domains.AppendString(kMismatchedDomain1); |
| 584 domains.AppendString(kMatchingDomain); |
| 585 SetPolicies({{policy::key::kRemoteAccessHostClientDomain, |
| 586 base::Value(kMismatchedDomain1)}, |
| 587 {policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 588 // Should succeed even though the legacy policy would deny. |
| 589 StartHost(); |
| 590 RunValidationCallback(kTestClientJid); |
| 591 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 592 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 593 ShutdownHost(); |
| 594 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 595 } |
| 596 |
| 597 TEST_F(It2MeHostTest, |
| 598 ConnectionValidation_ClientDomainBothPolicies_LegacyMatch) { |
| 599 base::ListValue domains; |
| 600 domains.AppendString(kMismatchedDomain1); |
| 601 domains.AppendString(kMismatchedDomain2); |
| 602 SetPolicies({{policy::key::kRemoteAccessHostClientDomain, |
| 603 base::Value(kMatchingDomain)}, |
| 604 {policy::key::kRemoteAccessHostClientDomainList, domains}}); |
| 605 // Should fail even though the legacy policy would allow. |
| 606 StartHost(); |
| 607 RunValidationCallback(kTestClientJid); |
| 608 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 609 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 610 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 611 } |
| 612 |
454 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { | 613 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { |
455 StartHost(); | 614 StartHost(); |
456 RunValidationCallback(kTestClientJid); | 615 RunValidationCallback(kTestClientJid); |
457 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 616 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
458 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); | 617 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
459 ShutdownHost(); | 618 ShutdownHost(); |
460 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 619 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
461 } | 620 } |
462 | 621 |
463 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { | 622 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { |
(...skipping 11 matching lines...) Expand all Loading... |
475 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 634 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
476 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); | 635 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
477 | 636 |
478 RunValidationCallback(kTestClientJid2); | 637 RunValidationCallback(kTestClientJid2); |
479 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); | 638 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); |
480 RunUntilStateChanged(It2MeHostState::kDisconnected); | 639 RunUntilStateChanged(It2MeHostState::kDisconnected); |
481 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 640 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
482 } | 641 } |
483 | 642 |
484 } // namespace remoting | 643 } // namespace remoting |
OLD | NEW |