upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-06-24 09:39:18 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-06-24 09:39:18 +0100
commit173ab188b326fbe78cfba4ab455a74619f4556bb (patch)
tree743a2413c241f7babd4efb336718c510eb743847 /tests
parent681fdd7683363c62251ecd8dabcc1931a18f4840 (diff)
feat(login): store in git config and use cache
replace ngit yaml file config with: * nsec / ncryptsec / npub in git config in nostr.* namespace * sql database cache for metadata and relay events allow different logins to be used for different git repositories by storing login in local git config
Diffstat (limited to 'tests')
-rw-r--r--tests/init.rs1
-rw-r--r--tests/login.rs254
-rw-r--r--tests/push.rs2
-rw-r--r--tests/send.rs3
4 files changed, 80 insertions, 180 deletions
diff --git a/tests/init.rs b/tests/init.rs
index 40b5a45..4e4b04f 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -4,7 +4,6 @@ use test_utils::{git::GitTestRepo, *};
4 4
5fn expect_msgs_first(p: &mut CliTester) -> Result<()> { 5fn expect_msgs_first(p: &mut CliTester) -> Result<()> {
6 p.expect("searching for profile and relay updates...\r\n")?; 6 p.expect("searching for profile and relay updates...\r\n")?;
7 p.expect("\r")?;
8 p.expect("logged in as fred\r\n")?; 7 p.expect("logged in as fred\r\n")?;
9 // // p.expect("searching for existing claims on repository...\r\n")?; 8 // // p.expect("searching for existing claims on repository...\r\n")?;
10 p.expect("publishing repostory reference...\r\n")?; 9 p.expect("publishing repostory reference...\r\n")?;
diff --git a/tests/login.rs b/tests/login.rs
index 371a7e7..aaadf00 100644
--- a/tests/login.rs
+++ b/tests/login.rs
@@ -2,17 +2,24 @@ use anyhow::Result;
2use serial_test::serial; 2use serial_test::serial;
3use test_utils::*; 3use test_utils::*;
4 4
5static EXPECTED_NSEC_PROMPT: &str = "login with nsec (or hex private key)"; 5static EXPECTED_NSEC_PROMPT: &str = "login with nsec";
6static EXPECTED_LOCAL_REPOSITORY_PROMPT: &str = "just for this repository?";
7static EXPECTED_REQUIRE_PASSWORD_PROMPT: &str = "require password?";
6static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password"; 8static EXPECTED_SET_PASSWORD_PROMPT: &str = "encrypt with password";
7static EXPECTED_SET_PASSWORD_CONFIRM_PROMPT: &str = "confirm password"; 9static EXPECTED_SET_PASSWORD_CONFIRM_PROMPT: &str = "confirm password";
8static EXPECTED_PASSWORD_PROMPT: &str = "password";
9 10
10fn standard_login() -> Result<CliTester> { 11fn standard_first_time_login_encrypting_nsec() -> Result<CliTester> {
11 let mut p = CliTester::new(["login", "--offline"]); 12 let mut p = CliTester::new(["login", "--offline"]);
12 13
13 p.expect_input_eventually(EXPECTED_NSEC_PROMPT)? 14 p.expect_input_eventually(EXPECTED_NSEC_PROMPT)?
14 .succeeds_with(TEST_KEY_1_NSEC)?; 15 .succeeds_with(TEST_KEY_1_NSEC)?;
15 16
17 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
18 .succeeds_with(Some(true))?;
19
20 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
21 .succeeds_with(Some(true))?;
22
16 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 23 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)?
17 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 24 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)?
18 .succeeds_with(TEST_PASSWORD)?; 25 .succeeds_with(TEST_PASSWORD)?;
@@ -56,16 +63,14 @@ mod with_relays {
56 p.expect_input(EXPECTED_NSEC_PROMPT)? 63 p.expect_input(EXPECTED_NSEC_PROMPT)?
57 .succeeds_with(TEST_KEY_1_NSEC)?; 64 .succeeds_with(TEST_KEY_1_NSEC)?;
58 65
59 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 66 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
60 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 67 .succeeds_with(Some(true))?;
61 .succeeds_with(TEST_PASSWORD)?; 68
69 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
70 .succeeds_with(Some(false))?;
62 71
63 p.expect("searching for profile and relay updates...\r\n")?; 72 p.expect("searching for profile and relay updates...\r\n")?;
64 p.expect("\r")?;
65 73
66 // p.expect_end_with(
67 // format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str(),
68 // )?;
69 p.expect_end_with("logged in as fred\r\n")?; 74 p.expect_end_with("logged in as fred\r\n")?;
70 for p in [51, 52] { 75 for p in [51, 52] {
71 shutdown_relay(8000 + p)?; 76 shutdown_relay(8000 + p)?;
@@ -97,12 +102,15 @@ mod with_relays {
97 p.expect_input(EXPECTED_NSEC_PROMPT)? 102 p.expect_input(EXPECTED_NSEC_PROMPT)?
98 .succeeds_with(TEST_KEY_1_NSEC)?; 103 .succeeds_with(TEST_KEY_1_NSEC)?;
99 104
100 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 105 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
101 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 106 .succeeds_with(Some(true))?;
102 .succeeds_with(TEST_PASSWORD)?; 107
108 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
109 .succeeds_with(Some(false))?;
103 110
104 p.expect("searching for profile and relay updates...\r\n")?; 111 p.expect("searching for profile and relay updates...\r\n")?;
105 p.expect("\r")?; 112
113 p.expect("cannot extract account name from account metadata...\r\n")?;
106 114
107 p.expect_end_with( 115 p.expect_end_with(
108 format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str(), 116 format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str(),
@@ -220,19 +228,6 @@ mod with_relays {
220 #[serial] 228 #[serial]
221 async fn displays_npub_when_metadata_contains_no_name_displayname_or_display_name() 229 async fn displays_npub_when_metadata_contains_no_name_displayname_or_display_name()
222 -> Result<()> { 230 -> Result<()> {
223 println!(
224 "displayName: {}",
225 nostr::Metadata::new()
226 .custom_field("displayName", "fred")
227 .custom
228 .get("displayName")
229 .unwrap()
230 );
231 println!(
232 "name: {}",
233 nostr::Metadata::new().name("fred").name.unwrap()
234 );
235
236 run_test_displays_fallback_to_npub( 231 run_test_displays_fallback_to_npub(
237 Some(&|relay, client_id, subscription_id, _| -> Result<()> { 232 Some(&|relay, client_id, subscription_id, _| -> Result<()> {
238 relay.respond_events( 233 relay.respond_events(
@@ -240,7 +235,7 @@ mod with_relays {
240 &subscription_id, 235 &subscription_id,
241 &vec![ 236 &vec![
242 nostr::event::EventBuilder::metadata( 237 nostr::event::EventBuilder::metadata(
243 &nostr::Metadata::new(), 238 &nostr::Metadata::new().about("other info in metadata"),
244 ) 239 )
245 .to_event(&TEST_KEY_1_KEYS) 240 .to_event(&TEST_KEY_1_KEYS)
246 .unwrap(), 241 .unwrap(),
@@ -419,7 +414,6 @@ mod with_relays {
419 let mut p = CliTester::new(["login", "--nsec", TEST_KEY_1_NSEC]); 414 let mut p = CliTester::new(["login", "--nsec", TEST_KEY_1_NSEC]);
420 415
421 p.expect("searching for profile and relay updates...\r\n")?; 416 p.expect("searching for profile and relay updates...\r\n")?;
422 p.expect("\r")?;
423 417
424 p.expect_end_with("logged in as fred\r\n")?; 418 p.expect_end_with("logged in as fred\r\n")?;
425 for p in [51, 52] { 419 for p in [51, 52] {
@@ -482,7 +476,6 @@ mod with_relays {
482 let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]); 476 let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]);
483 477
484 p.expect("searching for profile and relay updates...\r\n")?; 478 p.expect("searching for profile and relay updates...\r\n")?;
485 p.expect("\r")?;
486 479
487 p.expect_end_with("logged in as fred\r\n")?; 480 p.expect_end_with("logged in as fred\r\n")?;
488 for p in [51, 52] { 481 for p in [51, 52] {
@@ -541,7 +534,6 @@ mod with_relays {
541 ]); 534 ]);
542 535
543 p.expect("searching for profile and relay updates...\r\n")?; 536 p.expect("searching for profile and relay updates...\r\n")?;
544 p.expect("\r")?;
545 537
546 p.expect_end_with("logged in as fred\r\n")?; 538 p.expect_end_with("logged in as fred\r\n")?;
547 for p in [51, 52] { 539 for p in [51, 52] {
@@ -585,12 +577,14 @@ mod with_relays {
585 p.expect_input(EXPECTED_NSEC_PROMPT)? 577 p.expect_input(EXPECTED_NSEC_PROMPT)?
586 .succeeds_with(TEST_KEY_1_NSEC)?; 578 .succeeds_with(TEST_KEY_1_NSEC)?;
587 579
588 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 580 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
589 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 581 .succeeds_with(Some(true))?;
590 .succeeds_with(TEST_PASSWORD)?; 582
583 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
584 .succeeds_with(Some(false))?;
591 585
592 p.expect("searching for profile and relay updates...\r\n")?; 586 p.expect("searching for profile and relay updates...\r\n")?;
593 p.expect("\r")?; 587
594 p.expect( 588 p.expect(
595 "cannot find your account metadata (name, etc) on relays\r\n", 589 "cannot find your account metadata (name, etc) on relays\r\n",
596 )?; 590 )?;
@@ -649,12 +643,14 @@ mod with_relays {
649 p.expect_input(EXPECTED_NSEC_PROMPT)? 643 p.expect_input(EXPECTED_NSEC_PROMPT)?
650 .succeeds_with(TEST_KEY_1_NSEC)?; 644 .succeeds_with(TEST_KEY_1_NSEC)?;
651 645
652 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 646 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
653 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 647 .succeeds_with(Some(true))?;
654 .succeeds_with(TEST_PASSWORD)?; 648
649 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
650 .succeeds_with(Some(false))?;
655 651
656 p.expect("searching for profile and relay updates...\r\n")?; 652 p.expect("searching for profile and relay updates...\r\n")?;
657 p.expect("\r")?; 653
658 p.expect("cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience.\r\n")?; 654 p.expect("cannot find your relay list. consider using another nostr client to create one to enhance your nostr experience.\r\n")?;
659 655
660 p.expect_end_with("logged in as fred\r\n")?; 656 p.expect_end_with("logged in as fred\r\n")?;
@@ -677,11 +673,6 @@ mod with_relays {
677 mod when_second_time_login_and_details_already_fetched { 673 mod when_second_time_login_and_details_already_fetched {
678 use super::*; 674 use super::*;
679 675
680 // TODO: the following two tests would require a fake config file or
681 // fake time
682 // - uses_relays_from_user_relay_list
683 // - dislays_correct_name - when_local_metadata_is_the_most_recent
684
685 mod uses_cache { 676 mod uses_cache {
686 use super::*; 677 use super::*;
687 678
@@ -730,7 +721,6 @@ mod with_relays {
730 let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]); 721 let mut p = CliTester::new(["login", "--password", TEST_PASSWORD]);
731 722
732 p.expect("searching for profile and relay updates...\r\n")?; 723 p.expect("searching for profile and relay updates...\r\n")?;
733 p.expect("\r")?;
734 724
735 p.expect_end_eventually_with("logged in as fred\r\n")?; 725 p.expect_end_eventually_with("logged in as fred\r\n")?;
736 726
@@ -770,12 +760,13 @@ mod with_relays {
770 p.expect_input(EXPECTED_NSEC_PROMPT)? 760 p.expect_input(EXPECTED_NSEC_PROMPT)?
771 .succeeds_with(TEST_KEY_1_NSEC)?; 761 .succeeds_with(TEST_KEY_1_NSEC)?;
772 762
773 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 763 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
774 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 764 .succeeds_with(Some(true))?;
775 .succeeds_with(TEST_PASSWORD)?; 765
766 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
767 .succeeds_with(Some(false))?;
776 768
777 p.expect("searching for profile and relay updates...\r\n")?; 769 p.expect("searching for profile and relay updates...\r\n")?;
778 p.expect("\r")?;
779 770
780 p.expect_end_with("logged in as fred\r\n")?; 771 p.expect_end_with("logged in as fred\r\n")?;
781 for p in [51, 52, 53, 55] { 772 for p in [51, 52, 53, 55] {
@@ -842,7 +833,7 @@ mod with_offline_flag {
842 #[serial] 833 #[serial]
843 fn prompts_for_nsec_and_password() -> Result<()> { 834 fn prompts_for_nsec_and_password() -> Result<()> {
844 before()?; 835 before()?;
845 standard_login()?; 836 standard_first_time_login_encrypting_nsec()?;
846 after() 837 after()
847 } 838 }
848 839
@@ -855,6 +846,12 @@ mod with_offline_flag {
855 p.expect_input(EXPECTED_NSEC_PROMPT)? 846 p.expect_input(EXPECTED_NSEC_PROMPT)?
856 .succeeds_with(TEST_KEY_1_NSEC)?; 847 .succeeds_with(TEST_KEY_1_NSEC)?;
857 848
849 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
850 .succeeds_with(Some(true))?;
851
852 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
853 .succeeds_with(Some(true))?;
854
858 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 855 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)?
859 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 856 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)?
860 .succeeds_with(TEST_PASSWORD)?; 857 .succeeds_with(TEST_PASSWORD)?;
@@ -872,6 +869,12 @@ mod with_offline_flag {
872 p.expect_input(EXPECTED_NSEC_PROMPT)? 869 p.expect_input(EXPECTED_NSEC_PROMPT)?
873 .succeeds_with(TEST_KEY_1_SK_HEX)?; 870 .succeeds_with(TEST_KEY_1_SK_HEX)?;
874 871
872 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
873 .succeeds_with(Some(true))?;
874
875 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
876 .succeeds_with(Some(true))?;
877
875 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 878 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)?
876 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 879 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)?
877 .succeeds_with(TEST_PASSWORD)?; 880 .succeeds_with(TEST_PASSWORD)?;
@@ -904,6 +907,12 @@ mod with_offline_flag {
904 p.expect_input(invalid_nsec_response)? 907 p.expect_input(invalid_nsec_response)?
905 .succeeds_with(TEST_KEY_1_NSEC)?; 908 .succeeds_with(TEST_KEY_1_NSEC)?;
906 909
910 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
911 .succeeds_with(Some(true))?;
912
913 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
914 .succeeds_with(Some(true))?;
915
907 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 916 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)?
908 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 917 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)?
909 .succeeds_with(TEST_PASSWORD)?; 918 .succeeds_with(TEST_PASSWORD)?;
@@ -914,53 +923,6 @@ mod with_offline_flag {
914 } 923 }
915 } 924 }
916 925
917 mod when_second_time_login {
918 use super::*;
919
920 #[test]
921 #[serial]
922 fn prints_login_as_npub() -> Result<()> {
923 with_fresh_config(|| {
924 standard_login()?.exit()?;
925
926 CliTester::new(["login", "--offline"])
927 .expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())?
928 .exit()
929 })
930 }
931
932 #[test]
933 #[serial]
934 fn prompts_for_password_and_succeeds_with_logged_in_as_npub() -> Result<()> {
935 with_fresh_config(|| {
936 standard_login()?.exit()?;
937
938 let mut p = CliTester::new(["login", "--offline"]);
939
940 p.expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())?
941 .expect_password(EXPECTED_PASSWORD_PROMPT)?
942 .succeeds_with(TEST_PASSWORD)?;
943
944 p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())
945 })
946 }
947
948 #[test]
949 #[serial]
950 fn when_invalid_password_exit_with_error() -> Result<()> {
951 with_fresh_config(|| {
952 standard_login()?.exit()?;
953
954 let mut p = CliTester::new(["login", "--offline"]);
955
956 p.expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())?
957 .expect_password(EXPECTED_PASSWORD_PROMPT)?
958 .succeeds_with(TEST_INVALID_PASSWORD)?;
959 p.expect_end_with(format!("Error: failed to log in as {}\r\n\r\nCaused by:\r\n 0: failed to decrypt key with provided password\r\n 1: ChaCha20Poly1305: aead::Error\r\n", TEST_KEY_1_NPUB).as_str())
960 })
961 }
962 }
963
964 mod when_called_with_nsec_parameter_only { 926 mod when_called_with_nsec_parameter_only {
965 use super::*; 927 use super::*;
966 928
@@ -996,7 +958,7 @@ mod with_offline_flag {
996 #[serial] 958 #[serial]
997 fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { 959 fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> {
998 with_fresh_config(|| { 960 with_fresh_config(|| {
999 standard_login()?.exit()?; 961 standard_first_time_login_encrypting_nsec()?.exit()?;
1000 962
1001 CliTester::new(["login", "--offline", "--nsec", TEST_KEY_2_NSEC]) 963 CliTester::new(["login", "--offline", "--nsec", TEST_KEY_2_NSEC])
1002 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) 964 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str())
@@ -1035,26 +997,6 @@ mod with_offline_flag {
1035 997
1036 #[test] 998 #[test]
1037 #[serial] 999 #[serial]
1038 fn remembers_identity() -> Result<()> {
1039 with_fresh_config(|| {
1040 CliTester::new([
1041 "login",
1042 "--offline",
1043 "--nsec",
1044 TEST_KEY_1_NSEC,
1045 "--password",
1046 TEST_PASSWORD,
1047 ])
1048 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?;
1049
1050 CliTester::new(["login", "--offline"])
1051 .expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())?
1052 .exit()
1053 })
1054 }
1055
1056 #[test]
1057 #[serial]
1058 fn parameters_can_be_called_globally() -> Result<()> { 1000 fn parameters_can_be_called_globally() -> Result<()> {
1059 with_fresh_config(|| { 1001 with_fresh_config(|| {
1060 CliTester::new([ 1002 CliTester::new([
@@ -1076,7 +1018,7 @@ mod with_offline_flag {
1076 #[serial] 1018 #[serial]
1077 fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> { 1019 fn valid_nsec_param_succeeds_without_prompts_and_logs_in() -> Result<()> {
1078 with_fresh_config(|| { 1020 with_fresh_config(|| {
1079 standard_login()?.exit()?; 1021 standard_first_time_login_encrypting_nsec()?.exit()?;
1080 1022
1081 CliTester::new([ 1023 CliTester::new([
1082 "login", 1024 "login",
@@ -1089,28 +1031,6 @@ mod with_offline_flag {
1089 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str()) 1031 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str())
1090 }) 1032 })
1091 } 1033 }
1092
1093 #[test]
1094 #[serial]
1095 fn remembers_identity() -> Result<()> {
1096 with_fresh_config(|| {
1097 standard_login()?.exit()?;
1098
1099 CliTester::new([
1100 "login",
1101 "--offline",
1102 "--nsec",
1103 TEST_KEY_2_NSEC,
1104 "--password",
1105 TEST_PASSWORD,
1106 ])
1107 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_2_NPUB).as_str())?;
1108
1109 CliTester::new(["login", "--offline"])
1110 .expect(format!("login as {}\r\n", TEST_KEY_2_NPUB).as_str())?
1111 .exit()
1112 })
1113 }
1114 } 1034 }
1115 1035
1116 mod when_provided_with_new_password { 1036 mod when_provided_with_new_password {
@@ -1120,7 +1040,7 @@ mod with_offline_flag {
1120 #[serial] 1040 #[serial]
1121 fn password_changes() -> Result<()> { 1041 fn password_changes() -> Result<()> {
1122 with_fresh_config(|| { 1042 with_fresh_config(|| {
1123 standard_login()?.exit()?; 1043 standard_first_time_login_encrypting_nsec()?.exit()?;
1124 1044
1125 CliTester::new([ 1045 CliTester::new([
1126 "login", 1046 "login",
@@ -1157,31 +1077,6 @@ mod with_offline_flag {
1157 } 1077 }
1158 } 1078 }
1159 1079
1160 mod when_called_with_password_parameter_only {
1161 use super::*;
1162
1163 #[test]
1164 #[serial]
1165 fn when_nsec_stored_logs_in_without_prompts() -> Result<()> {
1166 with_fresh_config(|| {
1167 standard_login()?.exit()?;
1168
1169 CliTester::new(["login", "--offline", "--password", TEST_PASSWORD])
1170 .expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())
1171 })
1172 }
1173
1174 #[test]
1175 #[serial]
1176 fn when_no_nsec_stored_logs_error() -> Result<()> {
1177 with_fresh_config(|| {
1178 CliTester::new(["login", "--offline", "--password", TEST_PASSWORD]).expect_end_with(
1179 "Error: no nsec available to decrypt with specified password\r\n",
1180 )
1181 })
1182 }
1183 }
1184
1185 mod when_weak_password { 1080 mod when_weak_password {
1186 use super::*; 1081 use super::*;
1187 1082
@@ -1195,23 +1090,34 @@ mod with_offline_flag {
1195 p.expect_input(EXPECTED_NSEC_PROMPT)? 1090 p.expect_input(EXPECTED_NSEC_PROMPT)?
1196 .succeeds_with(TEST_KEY_1_NSEC)?; 1091 .succeeds_with(TEST_KEY_1_NSEC)?;
1197 1092
1093 p.expect_confirm(EXPECTED_LOCAL_REPOSITORY_PROMPT, Some(false))?
1094 .succeeds_with(Some(true))?;
1095
1096 p.expect_confirm(EXPECTED_REQUIRE_PASSWORD_PROMPT, Some(false))?
1097 .succeeds_with(Some(true))?;
1098
1198 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)? 1099 p.expect_password(EXPECTED_SET_PASSWORD_PROMPT)?
1199 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)? 1100 .with_confirmation(EXPECTED_SET_PASSWORD_CONFIRM_PROMPT)?
1200 .succeeds_with(TEST_WEAK_PASSWORD)?; 1101 .succeeds_with(TEST_WEAK_PASSWORD)?;
1201 1102
1202 p.expect("this may take a few seconds...\r\n")?; 1103 p.expect("this may take a few seconds...\r\n")?;
1203 1104
1204 p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())?; 1105 p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str())
1205 1106
1206 p = CliTester::new_with_timeout(10000, ["login", "--offline"]); 1107 // commented out as 'login' command now assumes you want to
1108 // login as a new user
1109 // p = CliTester::new_with_timeout(10000, ["login",
1110 // "--offline"]);
1207 1111
1208 p.expect(format!("login as {}\r\n", TEST_KEY_1_NPUB).as_str())? 1112 // p.expect(format!("login as {}\r\n",
1209 .expect_password(EXPECTED_PASSWORD_PROMPT)? 1113 // TEST_KEY_1_NPUB).as_str())?
1210 .succeeds_with(TEST_WEAK_PASSWORD)?; 1114 // .expect_password(EXPECTED_PASSWORD_PROMPT)?
1115 // .succeeds_with(TEST_WEAK_PASSWORD)?;
1211 1116
1212 p.expect("this may take a few seconds...\r\n")?; 1117 // p.expect("this may take a few seconds...\r\n")?;
1213 1118
1214 p.expect_end_with(format!("logged in as {}\r\n", TEST_KEY_1_NPUB).as_str()) 1119 // p.expect_end_with(format!("logged in as {}\r\n",
1120 // TEST_KEY_1_NPUB).as_str())
1215 }) 1121 })
1216 } 1122 }
1217 } 1123 }
diff --git a/tests/push.rs b/tests/push.rs
index 5fe1f15..fe711c1 100644
--- a/tests/push.rs
+++ b/tests/push.rs
@@ -347,7 +347,6 @@ mod when_branch_is_checked_out {
347 "1 commits ahead. preparing to create creating patch events.\r\n", 347 "1 commits ahead. preparing to create creating patch events.\r\n",
348 )?; 348 )?;
349 p.expect("searching for profile and relay updates...\r\n")?; 349 p.expect("searching for profile and relay updates...\r\n")?;
350 p.expect("\r")?;
351 p.expect("logged in as fred\r\n")?; 350 p.expect("logged in as fred\r\n")?;
352 p.expect("pushing 1 commits\r\n")?; 351 p.expect("pushing 1 commits\r\n")?;
353 352
@@ -593,7 +592,6 @@ mod when_branch_is_checked_out {
593 p.expect("355bdf1 add a4.md\r\n")?; 592 p.expect("355bdf1 add a4.md\r\n")?;
594 p.expect("dbd1115 add a3.md\r\n")?; 593 p.expect("dbd1115 add a3.md\r\n")?;
595 p.expect("searching for profile and relay updates...\r\n")?; 594 p.expect("searching for profile and relay updates...\r\n")?;
596 p.expect("\r")?;
597 p.expect("logged in as fred\r\n")?; 595 p.expect("logged in as fred\r\n")?;
598 p.expect("posting 2 patches without a covering letter...\r\n")?; 596 p.expect("posting 2 patches without a covering letter...\r\n")?;
599 597
diff --git a/tests/send.rs b/tests/send.rs
index 22216a8..2c95e1e 100644
--- a/tests/send.rs
+++ b/tests/send.rs
@@ -134,7 +134,6 @@ fn expect_msgs_first(p: &mut CliTester, include_cover_letter: bool) -> Result<()
134 p.expect("fe973a8 add t4.md\r\n")?; 134 p.expect("fe973a8 add t4.md\r\n")?;
135 p.expect("232efb3 add t3.md\r\n")?; 135 p.expect("232efb3 add t3.md\r\n")?;
136 p.expect("searching for profile and relay updates...\r\n")?; 136 p.expect("searching for profile and relay updates...\r\n")?;
137 p.expect("\r")?;
138 p.expect("logged in as fred\r\n")?; 137 p.expect("logged in as fred\r\n")?;
139 p.expect(format!( 138 p.expect(format!(
140 "posting 2 patches {} a covering letter...\r\n", 139 "posting 2 patches {} a covering letter...\r\n",
@@ -1163,7 +1162,6 @@ mod when_range_ommited_prompts_for_selection_defaulting_ahead_of_main {
1163 p.expect("fe973a8 add t4.md\r\n")?; 1162 p.expect("fe973a8 add t4.md\r\n")?;
1164 p.expect("232efb3 add t3.md\r\n")?; 1163 p.expect("232efb3 add t3.md\r\n")?;
1165 p.expect("searching for profile and relay updates...\r\n")?; 1164 p.expect("searching for profile and relay updates...\r\n")?;
1166 p.expect("\r")?;
1167 p.expect("logged in as fred\r\n")?; 1165 p.expect("logged in as fred\r\n")?;
1168 p.expect("posting 2 patches without a covering letter...\r\n")?; 1166 p.expect("posting 2 patches without a covering letter...\r\n")?;
1169 Ok(()) 1167 Ok(())
@@ -1358,7 +1356,6 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let
1358 p.expect("fe973a8 add t4.md\r\n")?; 1356 p.expect("fe973a8 add t4.md\r\n")?;
1359 p.expect("232efb3 add t3.md\r\n")?; 1357 p.expect("232efb3 add t3.md\r\n")?;
1360 p.expect("searching for profile and relay updates...\r\n")?; 1358 p.expect("searching for profile and relay updates...\r\n")?;
1361 p.expect("\r")?;
1362 p.expect("logged in as fred\r\n")?; 1359 p.expect("logged in as fred\r\n")?;
1363 p.expect(format!( 1360 p.expect(format!(
1364 "posting 2 patches {} a covering letter...\r\n", 1361 "posting 2 patches {} a covering letter...\r\n",