diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/login.rs | 314 |
1 files changed, 204 insertions, 110 deletions
diff --git a/tests/login.rs b/tests/login.rs index 03fc2a9..166941e 100644 --- a/tests/login.rs +++ b/tests/login.rs | |||
| @@ -1,15 +1,17 @@ | |||
| 1 | use anyhow::Result; | 1 | use anyhow::Result; |
| 2 | use git::GitTestRepo; | ||
| 2 | use serial_test::serial; | 3 | use serial_test::serial; |
| 3 | use test_utils::*; | 4 | use test_utils::*; |
| 4 | 5 | ||
| 5 | static EXPECTED_NSEC_PROMPT: &str = "login with nsec"; | 6 | static EXPECTED_NSEC_PROMPT: &str = "login with bunker uri / nsec"; |
| 6 | static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?"; | 7 | static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?"; |
| 7 | static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?"; | 8 | static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?"; |
| 8 | static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; | 9 | static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; |
| 9 | static EXPECTED_SET_PASSWORD_CONFIRM_PROMPT: &str = "confirm password"; | 10 | static EXPECTED_SET_PASSWORD_CONFIRM_PROMPT: &str = "confirm password"; |
| 10 | 11 | ||
| 11 | fn standard_first_time_login_encrypting_nsec() -> Result<CliTester> { | 12 | fn standard_first_time_login_encrypting_nsec() -> Result<CliTester> { |
| 12 | let mut p = CliTester::new(["login", "--offline"]); | 13 | let test_repo = GitTestRepo::default(); |
| 14 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); | ||
| 13 | 15 | ||
| 14 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? | 16 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? |
| 15 | .succeeds_with(TEST_KEY_1_NSEC)?; | 17 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -57,7 +59,8 @@ mod with_relays { | |||
| 57 | ); | 59 | ); |
| 58 | 60 | ||
| 59 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 61 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 60 | let mut p = CliTester::new(["login"]); | 62 | let test_repo = GitTestRepo::default(); |
| 63 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | ||
| 61 | 64 | ||
| 62 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 65 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 63 | .succeeds_with(TEST_KEY_1_NSEC)?; | 66 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -68,6 +71,8 @@ mod with_relays { | |||
| 68 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? | 71 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? |
| 69 | .succeeds_with(Some(false))?; | 72 | .succeeds_with(Some(false))?; |
| 70 | 73 | ||
| 74 | p.expect("saved login details to local git config\r\n")?; | ||
| 75 | |||
| 71 | p.expect("searching for profile and relay updates...\r\n")?; | 76 | p.expect("searching for profile and relay updates...\r\n")?; |
| 72 | 77 | ||
| 73 | p.expect_end_with("logged in as fred\r\n")?; | 78 | p.expect_end_with("logged in as fred\r\n")?; |
| @@ -94,7 +99,8 @@ mod with_relays { | |||
| 94 | ); | 99 | ); |
| 95 | 100 | ||
| 96 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 101 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 97 | let mut p = CliTester::new(["login"]); | 102 | let test_repo = GitTestRepo::default(); |
| 103 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | ||
| 98 | 104 | ||
| 99 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 105 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 100 | .succeeds_with(TEST_KEY_1_NSEC)?; | 106 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -105,6 +111,8 @@ mod with_relays { | |||
| 105 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? | 111 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? |
| 106 | .succeeds_with(Some(false))?; | 112 | .succeeds_with(Some(false))?; |
| 107 | 113 | ||
| 114 | p.expect("saved login details to local git config\r\n")?; | ||
| 115 | |||
| 108 | p.expect("searching for profile and relay updates...\r\n")?; | 116 | p.expect("searching for profile and relay updates...\r\n")?; |
| 109 | 117 | ||
| 110 | p.expect("cannot extract account name from account metadata...\r\n")?; | 118 | p.expect("cannot extract account name from account metadata...\r\n")?; |
| @@ -406,7 +414,13 @@ mod with_relays { | |||
| 406 | ); | 414 | ); |
| 407 | 415 | ||
| 408 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 416 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 409 | let mut p = CliTester::new(["login", "--nsec", TEST_KEY_1_NSEC]); | 417 | let test_repo = GitTestRepo::default(); |
| 418 | let mut p = CliTester::new_from_dir( | ||
| 419 | &test_repo.dir, | ||
| 420 | ["login", "--nsec", TEST_KEY_1_NSEC], | ||
| 421 | ); | ||
| 422 | |||
| 423 | p.expect("saved login details to local git config\r\n")?; | ||
| 410 | 424 | ||
| 411 | p.expect("searching for profile and relay updates...\r\n")?; | 425 | p.expect("searching for profile and relay updates...\r\n")?; |
| 412 | 426 | ||
| @@ -456,17 +470,24 @@ mod with_relays { | |||
| 456 | ); | 470 | ); |
| 457 | 471 | ||
| 458 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 472 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 459 | CliTester::new([ | 473 | let test_repo = GitTestRepo::default(); |
| 460 | "login", | 474 | CliTester::new_from_dir( |
| 461 | "--offline", | 475 | &test_repo.dir, |
| 462 | "--nsec", | 476 | [ |
| 463 | TEST_KEY_1_NSEC, | 477 | "login", |
| 464 | "--password", | 478 | "--offline", |
| 465 | TEST_PASSWORD, | 479 | "--nsec", |
| 466 | ]) | 480 | TEST_KEY_1_NSEC, |
| 481 | "--password", | ||
| 482 | TEST_PASSWORD, | ||
| 483 | ], | ||
| 484 | ) | ||
| 467 | .expect_end_eventually()?; | 485 | .expect_end_eventually()?; |
| 468 | 486 | ||
| 469 | let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]); | 487 | let mut p = CliTester::new_from_dir( |
| 488 | &test_repo.dir, | ||
| 489 | ["login", "--password", TEST_PASSWORD], | ||
| 490 | ); | ||
| 470 | 491 | ||
| 471 | p.expect("searching for profile and relay updates...\r\n")?; | 492 | p.expect("searching for profile and relay updates...\r\n")?; |
| 472 | 493 | ||
| @@ -516,13 +537,19 @@ mod with_relays { | |||
| 516 | ); | 537 | ); |
| 517 | 538 | ||
| 518 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 539 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 519 | let mut p = CliTester::new([ | 540 | let test_repo = GitTestRepo::default(); |
| 520 | "login", | 541 | let mut p = CliTester::new_from_dir( |
| 521 | "--nsec", | 542 | &test_repo.dir, |
| 522 | TEST_KEY_1_NSEC, | 543 | [ |
| 523 | "--password", | 544 | "login", |
| 524 | TEST_PASSWORD, | 545 | "--nsec", |
| 525 | ]); | 546 | TEST_KEY_1_NSEC, |
| 547 | "--password", | ||
| 548 | TEST_PASSWORD, | ||
| 549 | ], | ||
| 550 | ); | ||
| 551 | |||
| 552 | p.expect("saved login details to local git config\r\n")?; | ||
| 526 | 553 | ||
| 527 | p.expect("searching for profile and relay updates...\r\n")?; | 554 | p.expect("searching for profile and relay updates...\r\n")?; |
| 528 | 555 | ||
| @@ -561,7 +588,8 @@ mod with_relays { | |||
| 561 | ); | 588 | ); |
| 562 | 589 | ||
| 563 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 590 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 564 | let mut p = CliTester::new(["login"]); | 591 | let test_repo = GitTestRepo::default(); |
| 592 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | ||
| 565 | 593 | ||
| 566 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 594 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 567 | .succeeds_with(TEST_KEY_1_NSEC)?; | 595 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -572,6 +600,8 @@ mod with_relays { | |||
| 572 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? | 600 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? |
| 573 | .succeeds_with(Some(false))?; | 601 | .succeeds_with(Some(false))?; |
| 574 | 602 | ||
| 603 | p.expect("saved login details to local git config\r\n")?; | ||
| 604 | |||
| 575 | p.expect("searching for profile and relay updates...\r\n")?; | 605 | p.expect("searching for profile and relay updates...\r\n")?; |
| 576 | 606 | ||
| 577 | p.expect("cannot find your account metadata (name, etc) on relays\r\n")?; | 607 | p.expect("cannot find your account metadata (name, etc) on relays\r\n")?; |
| @@ -621,7 +651,8 @@ mod with_relays { | |||
| 621 | ); | 651 | ); |
| 622 | 652 | ||
| 623 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 653 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 624 | let mut p = CliTester::new(["login"]); | 654 | let test_repo = GitTestRepo::default(); |
| 655 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | ||
| 625 | 656 | ||
| 626 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 657 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 627 | .succeeds_with(TEST_KEY_1_NSEC)?; | 658 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -632,6 +663,8 @@ mod with_relays { | |||
| 632 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? | 663 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? |
| 633 | .succeeds_with(Some(false))?; | 664 | .succeeds_with(Some(false))?; |
| 634 | 665 | ||
| 666 | p.expect("saved login details to local git config\r\n")?; | ||
| 667 | |||
| 635 | p.expect("searching for profile and relay updates...\r\n")?; | 668 | p.expect("searching for profile and relay updates...\r\n")?; |
| 636 | 669 | ||
| 637 | p.expect("cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience.\r\n")?; | 670 | p.expect("cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience.\r\n")?; |
| @@ -655,7 +688,7 @@ mod with_relays { | |||
| 655 | mod when_second_time_login_and_details_already_fetched { | 688 | mod when_second_time_login_and_details_already_fetched { |
| 656 | use super::*; | 689 | use super::*; |
| 657 | 690 | ||
| 658 | mod uses_cache { | 691 | mod uses_cache_and_stores_and_retrieves_ncryptsec_from_local_git_config { |
| 659 | use super::*; | 692 | use super::*; |
| 660 | 693 | ||
| 661 | #[tokio::test] | 694 | #[tokio::test] |
| @@ -685,13 +718,19 @@ mod with_relays { | |||
| 685 | ); | 718 | ); |
| 686 | 719 | ||
| 687 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 720 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 688 | let mut p = CliTester::new([ | 721 | let test_repo = GitTestRepo::default(); |
| 689 | "login", | 722 | let mut p = CliTester::new_from_dir( |
| 690 | "--nsec", | 723 | &test_repo.dir, |
| 691 | TEST_KEY_1_NSEC, | 724 | [ |
| 692 | "--password", | 725 | "login", |
| 693 | TEST_PASSWORD, | 726 | "--nsec", |
| 694 | ]); | 727 | TEST_KEY_1_NSEC, |
| 728 | "--password", | ||
| 729 | TEST_PASSWORD, | ||
| 730 | ], | ||
| 731 | ); | ||
| 732 | |||
| 733 | p.expect("saved login details to local git config\r\n")?; | ||
| 695 | 734 | ||
| 696 | p.expect_end_eventually_with("logged in as fred\r\n")?; | 735 | p.expect_end_eventually_with("logged in as fred\r\n")?; |
| 697 | 736 | ||
| @@ -699,7 +738,10 @@ mod with_relays { | |||
| 699 | shutdown_relay(8000 + p)?; | 738 | shutdown_relay(8000 + p)?; |
| 700 | } | 739 | } |
| 701 | 740 | ||
| 702 | let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]); | 741 | let mut p = CliTester::new_from_dir( |
| 742 | &test_repo.dir, | ||
| 743 | ["login", "--password", TEST_PASSWORD], | ||
| 744 | ); | ||
| 703 | 745 | ||
| 704 | p.expect("searching for profile and relay updates...\r\n")?; | 746 | p.expect("searching for profile and relay updates...\r\n")?; |
| 705 | 747 | ||
| @@ -734,7 +776,8 @@ mod with_relays { | |||
| 734 | ); | 776 | ); |
| 735 | 777 | ||
| 736 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 778 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 737 | let mut p = CliTester::new(["login"]); | 779 | let test_repo = GitTestRepo::default(); |
| 780 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | ||
| 738 | 781 | ||
| 739 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 782 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 740 | .succeeds_with(TEST_KEY_1_NSEC)?; | 783 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -745,6 +788,8 @@ mod with_relays { | |||
| 745 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? | 788 | p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))? |
| 746 | .succeeds_with(Some(false))?; | 789 | .succeeds_with(Some(false))?; |
| 747 | 790 | ||
| 791 | p.expect("saved login details to local git config\r\n")?; | ||
| 792 | |||
| 748 | p.expect("searching for profile and relay updates...\r\n")?; | 793 | p.expect("searching for profile and relay updates...\r\n")?; |
| 749 | 794 | ||
| 750 | p.expect_end_with("logged in as fred\r\n")?; | 795 | p.expect_end_with("logged in as fred\r\n")?; |
| @@ -808,16 +853,15 @@ mod with_offline_flag { | |||
| 808 | use super::*; | 853 | use super::*; |
| 809 | 854 | ||
| 810 | #[test] | 855 | #[test] |
| 811 | #[serial] | ||
| 812 | fn prompts_for_nsec_and_password() -> Result<()> { | 856 | fn prompts_for_nsec_and_password() -> Result<()> { |
| 813 | standard_first_time_login_encrypting_nsec()?; | 857 | standard_first_time_login_encrypting_nsec()?; |
| 814 | Ok(()) | 858 | Ok(()) |
| 815 | } | 859 | } |
| 816 | 860 | ||
| 817 | #[test] | 861 | #[test] |
| 818 | #[serial] | ||
| 819 | fn succeeds_with_text_logged_in_as_npub() -> Result<()> { | 862 | fn succeeds_with_text_logged_in_as_npub() -> Result<()> { |
| 820 | let mut p = CliTester::new(["login", "--offline"]); | 863 | let test_repo = GitTestRepo::default(); |
| 864 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); | ||
| 821 | 865 | ||
| 822 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 866 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 823 | .succeeds_with(TEST_KEY_1_NSEC)?; | 867 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -832,13 +876,15 @@ mod with_offline_flag { | |||
| 832 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? | 876 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? |
| 833 | .succeeds_with(TEST_PASSWORD)?; | 877 | .succeeds_with(TEST_PASSWORD)?; |
| 834 | 878 | ||
| 879 | p.expect("saved login details to local git config\r\n")?; | ||
| 880 | |||
| 835 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 881 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) |
| 836 | } | 882 | } |
| 837 | 883 | ||
| 838 | #[test] | 884 | #[test] |
| 839 | #[serial] | ||
| 840 | fn succeeds_with_hex_secret_key_in_place_of_nsec() -> Result<()> { | 885 | fn succeeds_with_hex_secret_key_in_place_of_nsec() -> Result<()> { |
| 841 | let mut p = CliTester::new(["login", "--offline"]); | 886 | let test_repo = GitTestRepo::default(); |
| 887 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); | ||
| 842 | 888 | ||
| 843 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 889 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 844 | .succeeds_with(TEST_KEY_1_SK_HEX)?; | 890 | .succeeds_with(TEST_KEY_1_SK_HEX)?; |
| @@ -853,6 +899,8 @@ mod with_offline_flag { | |||
| 853 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? | 899 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? |
| 854 | .succeeds_with(TEST_PASSWORD)?; | 900 | .succeeds_with(TEST_PASSWORD)?; |
| 855 | 901 | ||
| 902 | p.expect("saved login details to local git config\r\n")?; | ||
| 903 | |||
| 856 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 904 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) |
| 857 | } | 905 | } |
| 858 | 906 | ||
| @@ -860,12 +908,11 @@ mod with_offline_flag { | |||
| 860 | use super::*; | 908 | use super::*; |
| 861 | 909 | ||
| 862 | #[test] | 910 | #[test] |
| 863 | #[serial] | ||
| 864 | fn prompts_for_nsec_until_valid() -> Result<()> { | 911 | fn prompts_for_nsec_until_valid() -> Result<()> { |
| 865 | let invalid_nsec_response = | 912 | let invalid_nsec_response = "invalid. try again with nostr address / nsec"; |
| 866 | "invalid nsec. try again with nsec (or hex private key)"; | ||
| 867 | 913 | ||
| 868 | let mut p = CliTester::new(["login", "--offline"]); | 914 | let test_repo = GitTestRepo::default(); |
| 915 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); | ||
| 869 | 916 | ||
| 870 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 917 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 871 | // this behaviour is intentional. rejecting the response with dialoguer | 918 | // this behaviour is intentional. rejecting the response with dialoguer |
| @@ -889,6 +936,8 @@ mod with_offline_flag { | |||
| 889 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? | 936 | .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? |
| 890 | .succeeds_with(TEST_PASSWORD)?; | 937 | .succeeds_with(TEST_PASSWORD)?; |
| 891 | 938 | ||
| 939 | p.expect("saved login details to local git config\r\n")?; | ||
| 940 | |||
| 892 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 941 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) |
| 893 | } | 942 | } |
| 894 | } | 943 | } |
| @@ -898,19 +947,31 @@ mod with_offline_flag { | |||
| 898 | use super::*; | 947 | use super::*; |
| 899 | 948 | ||
| 900 | #[test] | 949 | #[test] |
| 901 | #[serial] | ||
| 902 | fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { | 950 | fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { |
| 903 | CliTester::new(["login", "--offline", "--nsec", TEST_KEY_1_NSEC]) | 951 | let test_repo = GitTestRepo::default(); |
| 904 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 952 | let mut p = CliTester::new_from_dir( |
| 953 | &test_repo.dir, | ||
| 954 | ["login", "--offline", "--nsec", TEST_KEY_1_NSEC], | ||
| 955 | ); | ||
| 956 | |||
| 957 | p.expect("saved login details to local git config\r\n")?; | ||
| 958 | |||
| 959 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | ||
| 905 | } | 960 | } |
| 906 | 961 | ||
| 907 | #[test] | 962 | #[test] |
| 908 | #[serial] | ||
| 909 | fn forgets_identity() -> Result<()> { | 963 | fn forgets_identity() -> Result<()> { |
| 910 | CliTester::new(["login", "--offline", "--nsec", TEST_KEY_1_NSEC]) | 964 | let test_repo = GitTestRepo::default(); |
| 911 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?; | 965 | let mut p = CliTester::new_from_dir( |
| 966 | &test_repo.dir, | ||
| 967 | ["login", "--offline", "--nsec", TEST_KEY_1_NSEC], | ||
| 968 | ); | ||
| 969 | |||
| 970 | p.expect("saved login details to local git config\r\n")?; | ||
| 971 | |||
| 972 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?; | ||
| 912 | 973 | ||
| 913 | let mut p = CliTester::new(["login", "--offline"]); | 974 | p = CliTester::new_from_dir(&test_repo.dir, ["login", "--offline"]); |
| 914 | 975 | ||
| 915 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 976 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 916 | .succeeds_with(TEST_KEY_1_NSEC)?; | 977 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| @@ -922,18 +983,28 @@ mod with_offline_flag { | |||
| 922 | use super::*; | 983 | use super::*; |
| 923 | 984 | ||
| 924 | #[test] | 985 | #[test] |
| 925 | #[serial] | ||
| 926 | fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { | 986 | fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { |
| 927 | standard_first_time_login_encrypting_nsec()?.exit()?; | 987 | standard_first_time_login_encrypting_nsec()?.exit()?; |
| 988 | let test_repo = GitTestRepo::default(); | ||
| 989 | let mut p = CliTester::new_from_dir( | ||
| 990 | &test_repo.dir, | ||
| 991 | ["login", "--offline", "--nsec", TEST_KEY_2_NSEC], | ||
| 992 | ); | ||
| 928 | 993 | ||
| 929 | CliTester::new(["login", "--offline", "--nsec", TEST_KEY_2_NSEC]) | 994 | p.expect("saved login details to local git config\r\n")?; |
| 930 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) | 995 | |
| 996 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) | ||
| 931 | } | 997 | } |
| 932 | } | 998 | } |
| 933 | #[test] | 999 | #[test] |
| 934 | #[serial] | ||
| 935 | fn invalid_nsec_param_fails_without_prompts() -> Result<()> { | 1000 | fn invalid_nsec_param_fails_without_prompts() -> Result<()> { |
| 936 | CliTester::new(["login", "--offline", "--nsec", TEST_INVALID_NSEC]).expect_end_with( | 1001 | let test_repo = GitTestRepo::default(); |
| 1002 | let mut p = CliTester::new_from_dir( | ||
| 1003 | &test_repo.dir, | ||
| 1004 | ["login", "--offline", "--nsec", TEST_INVALID_NSEC], | ||
| 1005 | ); | ||
| 1006 | |||
| 1007 | p.expect_end_with( | ||
| 937 | "Error: invalid nsec parameter\r\n\r\nCaused by:\r\n Invalid secret key\r\n", | 1008 | "Error: invalid nsec parameter\r\n\r\nCaused by:\r\n Invalid secret key\r\n", |
| 938 | ) | 1009 | ) |
| 939 | } | 1010 | } |
| @@ -943,50 +1014,61 @@ mod with_offline_flag { | |||
| 943 | use super::*; | 1014 | use super::*; |
| 944 | 1015 | ||
| 945 | #[test] | 1016 | #[test] |
| 946 | #[serial] | ||
| 947 | fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { | 1017 | fn valid_nsec_param_succeeds_without_prompts() -> Result<()> { |
| 948 | CliTester::new([ | 1018 | let test_repo = GitTestRepo::default(); |
| 949 | "login", | 1019 | let mut p = CliTester::new_from_dir( |
| 950 | "--offline", | 1020 | &test_repo.dir, |
| 951 | "--nsec", | 1021 | [ |
| 952 | TEST_KEY_1_NSEC, | 1022 | "login", |
| 953 | "--password", | 1023 | "--offline", |
| 954 | TEST_PASSWORD, | 1024 | "--nsec", |
| 955 | ]) | 1025 | TEST_KEY_1_NSEC, |
| 956 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 1026 | "--password", |
| 1027 | TEST_PASSWORD, | ||
| 1028 | ], | ||
| 1029 | ); | ||
| 1030 | p.expect("saved login details to local git config\r\n")?; | ||
| 1031 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | ||
| 957 | } | 1032 | } |
| 958 | 1033 | ||
| 959 | #[test] | 1034 | #[test] |
| 960 | #[serial] | ||
| 961 | fn parameters_can_be_called_globally() -> Result<()> { | 1035 | fn parameters_can_be_called_globally() -> Result<()> { |
| 962 | CliTester::new([ | 1036 | let test_repo = GitTestRepo::default(); |
| 963 | "--nsec", | 1037 | let mut p = CliTester::new_from_dir( |
| 964 | TEST_KEY_1_NSEC, | 1038 | &test_repo.dir, |
| 965 | "--password", | 1039 | [ |
| 966 | TEST_PASSWORD, | 1040 | "--nsec", |
| 967 | "login", | 1041 | TEST_KEY_1_NSEC, |
| 968 | "--offline", | 1042 | "--password", |
| 969 | ]) | 1043 | TEST_PASSWORD, |
| 970 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 1044 | "login", |
| 1045 | "--offline", | ||
| 1046 | ], | ||
| 1047 | ); | ||
| 1048 | p.expect("saved login details to local git config\r\n")?; | ||
| 1049 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | ||
| 971 | } | 1050 | } |
| 972 | 1051 | ||
| 973 | mod when_logging_in_as_different_nsec { | 1052 | mod when_logging_in_as_different_nsec { |
| 974 | use super::*; | 1053 | use super::*; |
| 975 | 1054 | ||
| 976 | #[test] | 1055 | #[test] |
| 977 | #[serial] | ||
| 978 | fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { | 1056 | fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { |
| 979 | standard_first_time_login_encrypting_nsec()?.exit()?; | 1057 | standard_first_time_login_encrypting_nsec()?.exit()?; |
| 980 | 1058 | let test_repo = GitTestRepo::default(); | |
| 981 | CliTester::new([ | 1059 | let mut p = CliTester::new_from_dir( |
| 982 | "login", | 1060 | &test_repo.dir, |
| 983 | "--offline", | 1061 | [ |
| 984 | "--nsec", | 1062 | "login", |
| 985 | TEST_KEY_2_NSEC, | 1063 | "--offline", |
| 986 | "--password", | 1064 | "--nsec", |
| 987 | TEST_PASSWORD, | 1065 | TEST_KEY_2_NSEC, |
| 988 | ]) | 1066 | "--password", |
| 989 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) | 1067 | TEST_PASSWORD, |
| 1068 | ], | ||
| 1069 | ); | ||
| 1070 | p.expect("saved login details to local git config\r\n")?; | ||
| 1071 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) | ||
| 990 | } | 1072 | } |
| 991 | } | 1073 | } |
| 992 | 1074 | ||
| @@ -994,37 +1076,46 @@ mod with_offline_flag { | |||
| 994 | use super::*; | 1076 | use super::*; |
| 995 | 1077 | ||
| 996 | #[test] | 1078 | #[test] |
| 997 | #[serial] | ||
| 998 | fn password_changes() -> Result<()> { | 1079 | fn password_changes() -> Result<()> { |
| 999 | standard_first_time_login_encrypting_nsec()?.exit()?; | 1080 | standard_first_time_login_encrypting_nsec()?.exit()?; |
| 1081 | let test_repo = GitTestRepo::default(); | ||
| 1082 | let mut p = CliTester::new_from_dir( | ||
| 1083 | &test_repo.dir, | ||
| 1084 | [ | ||
| 1085 | "login", | ||
| 1086 | "--offline", | ||
| 1087 | "--nsec", | ||
| 1088 | TEST_KEY_1_NSEC, | ||
| 1089 | "--password", | ||
| 1090 | TEST_INVALID_PASSWORD, | ||
| 1091 | ], | ||
| 1092 | ); | ||
| 1093 | p.expect("saved login details to local git config\r\n")?; | ||
| 1094 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?; | ||
| 1000 | 1095 | ||
| 1001 | CliTester::new([ | 1096 | CliTester::new_from_dir( |
| 1002 | "login", | 1097 | &test_repo.dir, |
| 1003 | "--offline", | 1098 | ["--password", TEST_INVALID_PASSWORD, "login", "--offline"], |
| 1004 | "--nsec", | 1099 | ) |
| 1005 | TEST_KEY_1_NSEC, | 1100 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) |
| 1006 | "--password", | ||
| 1007 | TEST_INVALID_PASSWORD, | ||
| 1008 | ]) | ||
| 1009 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?; | ||
| 1010 | |||
| 1011 | CliTester::new(["--password", TEST_INVALID_PASSWORD, "login", "--offline"]) | ||
| 1012 | .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | ||
| 1013 | } | 1101 | } |
| 1014 | } | 1102 | } |
| 1015 | 1103 | ||
| 1016 | #[test] | 1104 | #[test] |
| 1017 | #[serial] | ||
| 1018 | fn invalid_nsec_param_fails_without_prompts() -> Result<()> { | 1105 | fn invalid_nsec_param_fails_without_prompts() -> Result<()> { |
| 1019 | CliTester::new([ | 1106 | let test_repo = GitTestRepo::default(); |
| 1020 | "login", | 1107 | let mut p = CliTester::new_from_dir( |
| 1021 | "--offline", | 1108 | &test_repo.dir, |
| 1022 | "--nsec", | 1109 | [ |
| 1023 | TEST_INVALID_NSEC, | 1110 | "login", |
| 1024 | "--password", | 1111 | "--offline", |
| 1025 | TEST_PASSWORD, | 1112 | "--nsec", |
| 1026 | ]) | 1113 | TEST_INVALID_NSEC, |
| 1027 | .expect_end_with( | 1114 | "--password", |
| 1115 | TEST_PASSWORD, | ||
| 1116 | ], | ||
| 1117 | ); | ||
| 1118 | p.expect_end_with( | ||
| 1028 | "Error: invalid nsec parameter\r\n\r\nCaused by:\r\n Invalid secret key\r\n", | 1119 | "Error: invalid nsec parameter\r\n\r\nCaused by:\r\n Invalid secret key\r\n", |
| 1029 | ) | 1120 | ) |
| 1030 | } | 1121 | } |
| @@ -1034,11 +1125,12 @@ mod with_offline_flag { | |||
| 1034 | use super::*; | 1125 | use super::*; |
| 1035 | 1126 | ||
| 1036 | #[test] | 1127 | #[test] |
| 1037 | #[serial] | ||
| 1038 | // combined into a single test as it is computationally expensive to run | 1128 | // combined into a single test as it is computationally expensive to run |
| 1039 | fn warns_it_might_take_a_few_seconds_then_succeeds_then_second_login_prompts_for_password_then_warns_again_then_succeeds() | 1129 | fn warns_it_might_take_a_few_seconds_then_succeeds_then_second_login_prompts_for_password_then_warns_again_then_succeeds() |
| 1040 | -> Result<()> { | 1130 | -> Result<()> { |
| 1041 | let mut p = CliTester::new_with_timeout(10000, ["login", "--offline"]); | 1131 | let test_repo = GitTestRepo::default(); |
| 1132 | let mut p = | ||
| 1133 | CliTester::new_with_timeout_from_dir(10000, &test_repo.dir, ["login", "--offline"]); | ||
| 1042 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 1134 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 1043 | .succeeds_with(TEST_KEY_1_NSEC)?; | 1135 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 1044 | 1136 | ||
| @@ -1054,6 +1146,8 @@ mod with_offline_flag { | |||
| 1054 | 1146 | ||
| 1055 | p.expect("this may take a few seconds...\r\n")?; | 1147 | p.expect("this may take a few seconds...\r\n")?; |
| 1056 | 1148 | ||
| 1149 | p.expect("saved login details to local git config\r\n")?; | ||
| 1150 | |||
| 1057 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) | 1151 | p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) |
| 1058 | 1152 | ||
| 1059 | // commented out as 'login' command now assumes you want to | 1153 | // commented out as 'login' command now assumes you want to |