Skip to content

Commit 5428609

Browse files
committed
Add ambiguous user unit tests, and more for hostname
Not all of these tests can pass yet, since gix-transport does not yet detect and refuse to proceed with leading-hypnen usernames. Some pass; those that do not are, as expected: - ambiguous_user_is_disallowed_explicit_ssh - ambiguous_user_is_disallowed_implicit_ssh - ambiguous_user_and_host_remain_disallowed_together_explicit_ssh - ambiguous_user_and_host_remain_disallowed_together_implicit_ssh This also adds AmbiguousUserName in one of the enums that will need to have it, but nothing fails with this error yet; it is introduced now only to facilitate writing unit tests that assert it.
1 parent a51003d commit 5428609

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub mod invocation {
4242
#[derive(Debug, thiserror::Error)]
4343
#[allow(missing_docs)]
4444
pub enum Error {
45+
#[error("Username '{user}' could be mistaken for a command-line argument")]
46+
AmbiguousUserName { user: String },
4547
#[error("Host name '{host}' could be mistaken for a command-line argument")]
4648
AmbiguousHostName { host: String },
4749
#[error("The 'Simple' ssh variant doesn't support {function}")]

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

+43-2
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,63 @@ mod program_kind {
144144
assert!(call_args(kind, "ssh://user@host:43/p", Protocol::V2).ends_with("-P 43 user@host"));
145145
}
146146
}
147+
147148
#[test]
148-
fn ambiguous_host_is_allowed_with_user() {
149+
fn ambiguous_user_is_disallowed_explicit_ssh() {
150+
assert!(matches!(
151+
try_call(ProgramKind::Ssh, "ssh://-arg@host/p", Protocol::V2),
152+
Err(ssh::invocation::Error::AmbiguousUserName { user }) if user == "-arg"
153+
))
154+
}
155+
156+
#[test]
157+
fn ambiguous_user_is_disallowed_implicit_ssh() {
158+
assert!(matches!(
159+
try_call(ProgramKind::Ssh, "-arg@host:p/q", Protocol::V2),
160+
Err(ssh::invocation::Error::AmbiguousUserName { user }) if user == "-arg"
161+
))
162+
}
163+
164+
#[test]
165+
fn ambiguous_host_is_allowed_with_user_explicit_ssh() {
149166
assert_eq!(
150167
call_args(ProgramKind::Ssh, "ssh://user@-arg/p", Protocol::V2),
151168
joined(&["ssh", "-o", "SendEnv=GIT_PROTOCOL", "user@-arg"])
152169
);
153170
}
154171

155172
#[test]
156-
fn ambiguous_host_is_disallowed() {
173+
fn ambiguous_host_is_allowed_with_user_implicit_ssh() {
174+
assert_eq!(
175+
call_args(ProgramKind::Ssh, "user@-arg:p/q", Protocol::V2),
176+
joined(&["ssh", "-o", "SendEnv=GIT_PROTOCOL", "user@-arg"])
177+
);
178+
}
179+
180+
#[test]
181+
fn ambiguous_host_is_disallowed_without_user() {
157182
assert!(matches!(
158183
try_call(ProgramKind::Ssh, "ssh://-arg/p", Protocol::V2),
159184
Err(ssh::invocation::Error::AmbiguousHostName { host }) if host == "-arg"
160185
));
161186
}
162187

188+
#[test]
189+
fn ambiguous_user_and_host_remain_disallowed_together_explicit_ssh() {
190+
assert!(matches!(
191+
try_call(ProgramKind::Ssh, "ssh://-arg@host/p", Protocol::V2),
192+
Err(ssh::invocation::Error::AmbiguousUserName { user }) if user == "-arg"
193+
));
194+
}
195+
196+
#[test]
197+
fn ambiguous_user_and_host_remain_disallowed_together_implicit_ssh() {
198+
assert!(matches!(
199+
try_call(ProgramKind::Ssh, "-userarg@-hostarg:p/q", Protocol::V2),
200+
Err(ssh::invocation::Error::AmbiguousUserName { user }) if user == "-userarg"
201+
));
202+
}
203+
163204
#[test]
164205
fn simple_cannot_handle_any_arguments() {
165206
assert!(matches!(

0 commit comments

Comments
 (0)