upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-11-26 16:28:09 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-11-26 16:28:09 +0000
commitbdf71cb3d5a5ff8399c10c8d2492d3dd01c5fa33 (patch)
tree057008f20a0206f76b4a64f39fb12417c2e018a0 /src/lib
parent08397221abcd009fee1ab1b69d92b107b604bee1 (diff)
test(login): update `ngit login` test
to reflect the new interface and testing only nsec login
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/login/existing.rs17
-rw-r--r--src/lib/login/fresh.rs18
2 files changed, 23 insertions, 12 deletions
diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs
index 342f792..872e459 100644
--- a/src/lib/login/existing.rs
+++ b/src/lib/login/existing.rs
@@ -69,11 +69,18 @@ fn get_signer_info(
69 Ok(match source { 69 Ok(match source {
70 None => { 70 None => {
71 let mut result = None; 71 let mut result = None;
72 for source in &[ 72 for source in if std::env::var("NGITTEST").is_ok() {
73 SignerInfoSource::CommandLineArguments, 73 vec![
74 SignerInfoSource::GitLocal, 74 SignerInfoSource::CommandLineArguments,
75 SignerInfoSource::GitGlobal, 75 SignerInfoSource::GitLocal,
76 ] { 76 ]
77 } else {
78 vec![
79 SignerInfoSource::CommandLineArguments,
80 SignerInfoSource::GitLocal,
81 SignerInfoSource::GitGlobal,
82 ]
83 } {
77 if let Ok(res) = 84 if let Ok(res) =
78 get_signer_info(git_repo, signer_info, password, &Some(source.clone())) 85 get_signer_info(git_repo, signer_info, password, &Some(source.clone()))
79 { 86 {
diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs
index 59026bd..b874992 100644
--- a/src/lib/login/fresh.rs
+++ b/src/lib/login/fresh.rs
@@ -25,7 +25,7 @@ use crate::{
25 Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, 25 Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms,
26 PromptInputParms, PromptPasswordParms, 26 PromptInputParms, PromptPasswordParms,
27 }, 27 },
28 client::{fetch_public_key, send_events, Connect}, 28 client::{send_events, Connect},
29 git::{remove_git_config_item, save_git_config_item, Repo, RepoActions}, 29 git::{remove_git_config_item, save_git_config_item, Repo, RepoActions},
30}; 30};
31 31
@@ -38,7 +38,7 @@ pub async fn fresh_login_or_signup(
38) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { 38) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> {
39 let (signer, public_key, signer_info, source) = loop { 39 let (signer, public_key, signer_info, source) = loop {
40 if let Some(signer_info) = signer_info { 40 if let Some(signer_info) = signer_info {
41 let (signer, _user_ref, source) = load_existing_login( 41 let (signer, user_ref, source) = load_existing_login(
42 git_repo, 42 git_repo,
43 &Some(signer_info.clone()), 43 &Some(signer_info.clone()),
44 &None, 44 &None,
@@ -48,8 +48,7 @@ pub async fn fresh_login_or_signup(
48 true, 48 true,
49 ) 49 )
50 .await?; 50 .await?;
51 let public_key = fetch_public_key(&signer).await?; 51 break (signer, user_ref.public_key, signer_info, source);
52 break (signer, public_key, signer_info, source);
53 } 52 }
54 match Interactor::default().choice( 53 match Interactor::default().choice(
55 PromptChoiceParms::default() 54 PromptChoiceParms::default()
@@ -176,7 +175,7 @@ pub async fn get_fresh_nsec_signer() -> Result<
176 (keys, signer_info) 175 (keys, signer_info)
177 } else if let Ok(keys) = nostr::Keys::from_str(&input) { 176 } else if let Ok(keys) = nostr::Keys::from_str(&input) {
178 let nsec = keys.secret_key().to_bech32()?; 177 let nsec = keys.secret_key().to_bech32()?;
179 show_prompt_success("nsec", &shorten_string(&nsec)); 178 show_prompt_success("nsec", &shorten_string(&input));
180 let signer_info = SignerInfo::Nsec { 179 let signer_info = SignerInfo::Nsec {
181 nsec, 180 nsec,
182 password: None, 181 password: None,
@@ -223,11 +222,11 @@ fn show_prompt_error(label: &str, value: &str) {
223 let _ = ColorfulTheme::default().format_error( 222 let _ = ColorfulTheme::default().format_error(
224 &mut s, 223 &mut s,
225 &format!( 224 &format!(
226 "{label}: {}", 225 "{label}: \"{}\"",
227 if value.is_empty() { 226 if value.is_empty() {
228 "empty".to_string() 227 "empty".to_string()
229 } else { 228 } else {
230 shorten_string(&format!("\"{}\"", &value)) 229 shorten_string(value)
231 } 230 }
232 ), 231 ),
233 ); 232 );
@@ -490,6 +489,11 @@ async fn save_to_git_config(
490 signer_info: &SignerInfo, 489 signer_info: &SignerInfo,
491 global: bool, 490 global: bool,
492) -> Result<()> { 491) -> Result<()> {
492 let global = if std::env::var("NGITTEST").is_ok() {
493 false
494 } else {
495 global
496 };
493 let err_msg = format!( 497 let err_msg = format!(
494 "failed to save login details to {} git config", 498 "failed to save login details to {} git config",
495 if global { "global" } else { "local" } 499 if global { "global" } else { "local" }