Skip to content

Commit 4dda375

Browse files
committed
Start on using {user,host}_as_argument in prepare_invocation
Right now this is more locked down than necessary, serving to check that ArgumentSafety can be easily matched on in scenarios where one may wish to reject both usernames and hosts that are ambiguous. This is verified by all tests passing except these that fail: - ambiguous_host_is_allowed_with_user_explicit_ssh - ambiguous_host_is_allowed_with_user_implicit_ssh Prohibiting ambiguous hosts even when the username is present and cannot itself be confused with a command-line option isn't needed in gix-transport, which passes URLs of the form `user@host` anytime the username is present. However, if an application ever passes the username as a separate argument rather than as part of the netloc with the host, then being able to express that in a natural and non-error-prone way is important.
1 parent 1b0af07 commit 4dda375

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

gix-transport/src/client/blocking_io/ssh/program_kind.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::{ffi::OsStr, io::ErrorKind};
22

33
use bstr::{BString, ByteSlice, ByteVec};
44

5+
use gix_url::ArgumentSafety::*;
6+
57
use crate::{
68
client::{ssh, ssh::ProgramKind},
79
Protocol,
@@ -60,23 +62,13 @@ impl ProgramKind {
6062
}
6163
}
6264
};
63-
let host_maybe_with_user_as_ssh_arg = match url.user() {
64-
Some(user) => {
65-
// FIXME: See the fixme comment on Url::user_argument_safe() about its return type.
66-
if url.user_argument_safe() != Some(user) {
67-
return Err(ssh::invocation::Error::AmbiguousUserName { user: user.into() });
68-
}
69-
let host = url.host().expect("present in ssh urls");
70-
format!("{user}@{host}")
71-
}
72-
None => {
73-
let host = url
74-
.host_argument_safe()
75-
.ok_or_else(|| ssh::invocation::Error::AmbiguousHostName {
76-
host: url.host().expect("ssh host always set").into(),
77-
})?;
78-
host.into()
79-
}
65+
66+
let host_maybe_with_user_as_ssh_arg = match (url.user_as_argument(), url.host_as_argument()) {
67+
(Usable(user), Usable(host)) => format!("{user}@{host}"),
68+
(Absent, Usable(host)) => host.into(),
69+
(Dangerous(user), _) => Err(ssh::invocation::Error::AmbiguousUserName { user: user.into() })?,
70+
(_, Dangerous(host)) => Err(ssh::invocation::Error::AmbiguousHostName { host: host.into() })?,
71+
(_, Absent) => panic!("BUG: host should always be present in SSH URLs"),
8072
};
8173

8274
// Try to force ssh to yield English messages (for parsing later).

0 commit comments

Comments
 (0)