diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-24 15:03:58 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-24 19:48:11 +0100 |
| commit | d01380f7b3efebc9c40a2e71c2ddd635fa936be4 (patch) | |
| tree | 58af24e8981bfa4b0c8dc330ea8903dac3bbc479 /tests/ngit | |
| parent | 0acc9768c2aff4bf4495c89698f29b56dae2f4b4 (diff) | |
feat(login): login via nip46 QR code
or nostrconnect url string which is a much better UX flow for nip46
Diffstat (limited to 'tests/ngit')
| -rw-r--r-- | tests/ngit/login.rs | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/tests/ngit/login.rs b/tests/ngit/login.rs index 3bcfbf9..477b25b 100644 --- a/tests/ngit/login.rs +++ b/tests/ngit/login.rs | |||
| @@ -3,7 +3,7 @@ use git::GitTestRepo; | |||
| 3 | use serial_test::serial; | 3 | use serial_test::serial; |
| 4 | use test_utils::*; | 4 | use test_utils::*; |
| 5 | 5 | ||
| 6 | static EXPECTED_NSEC_PROMPT: &str = "login with nostr address / nsec"; | 6 | static EXPECTED_NSEC_PROMPT: &str = "login with nsec / bunker url / nostr address"; |
| 7 | static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?"; | 7 | static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?"; |
| 8 | static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?"; | 8 | static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?"; |
| 9 | static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; | 9 | static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; |
| @@ -29,6 +29,18 @@ fn standard_first_time_login_encrypting_nsec() -> Result<CliTester> { | |||
| 29 | p.expect_end_eventually()?; | 29 | p.expect_end_eventually()?; |
| 30 | Ok(p) | 30 | Ok(p) |
| 31 | } | 31 | } |
| 32 | |||
| 33 | fn expect_qr_prompt_opt_for_other_methods(p: &mut CliTester) -> Result<()> { | ||
| 34 | p.expect_eventually("scan QR or paste into remote signer")?; | ||
| 35 | p.expect_eventually("\r\n")?; | ||
| 36 | p.expect_eventually("login with nsec / bunker url / nostr address instead")?; | ||
| 37 | p.expect_eventually("\r\n")?; | ||
| 38 | p.send_line("")?; | ||
| 39 | // p.expect_eventually("\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r")?; | ||
| 40 | // p.expect_eventually("\r\r\r\r\r\r\r\r\r\r\r\r\r")?; | ||
| 41 | |||
| 42 | Ok(()) | ||
| 43 | } | ||
| 32 | mod with_relays { | 44 | mod with_relays { |
| 33 | use anyhow::Ok; | 45 | use anyhow::Ok; |
| 34 | use futures::join; | 46 | use futures::join; |
| @@ -61,8 +73,8 @@ mod with_relays { | |||
| 61 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 73 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 62 | let test_repo = GitTestRepo::default(); | 74 | let test_repo = GitTestRepo::default(); |
| 63 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | 75 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); |
| 64 | 76 | expect_qr_prompt_opt_for_other_methods(&mut p)?; | |
| 65 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 77 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? |
| 66 | .succeeds_with(TEST_KEY_1_NSEC)?; | 78 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 67 | 79 | ||
| 68 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? | 80 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? |
| @@ -102,7 +114,8 @@ mod with_relays { | |||
| 102 | let test_repo = GitTestRepo::default(); | 114 | let test_repo = GitTestRepo::default(); |
| 103 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | 115 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); |
| 104 | 116 | ||
| 105 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 117 | expect_qr_prompt_opt_for_other_methods(&mut p)?; |
| 118 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? | ||
| 106 | .succeeds_with(TEST_KEY_1_NSEC)?; | 119 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 107 | 120 | ||
| 108 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? | 121 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? |
| @@ -591,7 +604,8 @@ mod with_relays { | |||
| 591 | let test_repo = GitTestRepo::default(); | 604 | let test_repo = GitTestRepo::default(); |
| 592 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | 605 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); |
| 593 | 606 | ||
| 594 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 607 | expect_qr_prompt_opt_for_other_methods(&mut p)?; |
| 608 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? | ||
| 595 | .succeeds_with(TEST_KEY_1_NSEC)?; | 609 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 596 | 610 | ||
| 597 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? | 611 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? |
| @@ -654,7 +668,8 @@ mod with_relays { | |||
| 654 | let test_repo = GitTestRepo::default(); | 668 | let test_repo = GitTestRepo::default(); |
| 655 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | 669 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); |
| 656 | 670 | ||
| 657 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 671 | expect_qr_prompt_opt_for_other_methods(&mut p)?; |
| 672 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? | ||
| 658 | .succeeds_with(TEST_KEY_1_NSEC)?; | 673 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 659 | 674 | ||
| 660 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? | 675 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? |
| @@ -777,7 +792,8 @@ mod with_relays { | |||
| 777 | let test_repo = GitTestRepo::default(); | 792 | let test_repo = GitTestRepo::default(); |
| 778 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); | 793 | let mut p = CliTester::new_from_dir(&test_repo.dir, ["login"]); |
| 779 | 794 | ||
| 780 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 795 | expect_qr_prompt_opt_for_other_methods(&mut p)?; |
| 796 | p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? | ||
| 781 | .succeeds_with(TEST_KEY_1_NSEC)?; | 797 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 782 | 798 | ||
| 783 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? | 799 | p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))? |
| @@ -1124,12 +1140,14 @@ mod with_offline_flag { | |||
| 1124 | use super::*; | 1140 | use super::*; |
| 1125 | 1141 | ||
| 1126 | #[test] | 1142 | #[test] |
| 1143 | #[serial] | ||
| 1127 | // combined into a single test as it is computationally expensive to run | 1144 | // combined into a single test as it is computationally expensive to run |
| 1128 | fn warns_it_might_take_a_few_seconds_then_succeeds_then_second_login_prompts_for_password_then_warns_again_then_succeeds() | 1145 | fn warns_it_might_take_a_few_seconds_then_succeeds_then_second_login_prompts_for_password_then_warns_again_then_succeeds() |
| 1129 | -> Result<()> { | 1146 | -> Result<()> { |
| 1130 | let test_repo = GitTestRepo::default(); | 1147 | let test_repo = GitTestRepo::default(); |
| 1131 | let mut p = | 1148 | let mut p = |
| 1132 | CliTester::new_with_timeout_from_dir(15000, &test_repo.dir, ["login", "--offline"]); | 1149 | CliTester::new_with_timeout_from_dir(15000, &test_repo.dir, ["login", "--offline"]); |
| 1150 | |||
| 1133 | p.expect_input(EXPECTED_NSEC_PROMPT)? | 1151 | p.expect_input(EXPECTED_NSEC_PROMPT)? |
| 1134 | .succeeds_with(TEST_KEY_1_NSEC)?; | 1152 | .succeeds_with(TEST_KEY_1_NSEC)?; |
| 1135 | 1153 | ||