upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/ngit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ngit')
-rw-r--r--tests/ngit/login.rs32
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;
3use serial_test::serial; 3use serial_test::serial;
4use test_utils::*; 4use test_utils::*;
5 5
6static EXPECTED_NSEC_PROMPT: &str = "login with nostr address / nsec"; 6static EXPECTED_NSEC_PROMPT: &str = "login with nsec / bunker url / nostr address";
7static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?"; 7static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?";
8static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?"; 8static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?";
9static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; 9static 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
33fn 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}
32mod with_relays { 44mod 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