Use Windows username in SDK client
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
ci / test (push) Canceled after 0s
ci / fuzz-smoke (push) Canceled after 0s
ci / macos-client (macos-aarch64, macos-14) (push) Canceled after 0s
ci / macos-client (macos-x86_64, macos-13) (push) Canceled after 0s
ci / windows-client (push) Canceled after 0s
ci / package-release (linux-x86_64, ubuntu-latest, , , ) (push) Canceled after 0s
ci / package-release (macos-aarch64, macos-14, , , ) (push) Canceled after 0s
ci / package-release (macos-x86_64, macos-13, , , ) (push) Canceled after 0s
ci / package-release (windows-aarch64, windows-latest, aarch64, windows, aarch64-pc-windows-msvc) (push) Canceled after 0s
ci / package-release (windows-x86_64, windows-latest, , , ) (push) Canceled after 0s
ci / remote-bench (push) Canceled after 0s
ci / publish-gitea-release (push) Canceled after 0s
This commit is contained in:
+41
-1
@@ -159,7 +159,7 @@ impl DoshClientBuilder {
|
|||||||
.clone()
|
.clone()
|
||||||
.or_else(|| host_config.user.clone())
|
.or_else(|| host_config.user.clone())
|
||||||
.or_else(|| user_from_destination(&raw_server))
|
.or_else(|| user_from_destination(&raw_server))
|
||||||
.or_else(|| std::env::var("USER").ok())
|
.or_else(local_username)
|
||||||
.unwrap_or_else(|| "unknown".to_string());
|
.unwrap_or_else(|| "unknown".to_string());
|
||||||
let udp_host = self
|
let udp_host = self
|
||||||
.udp_host
|
.udp_host
|
||||||
@@ -410,6 +410,17 @@ fn user_from_destination(destination: &str) -> Option<String> {
|
|||||||
.filter(|user| !user.is_empty())
|
.filter(|user| !user.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn local_username() -> Option<String> {
|
||||||
|
local_username_from_env(|name| std::env::var(name).ok())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn local_username_from_env(mut get: impl FnMut(&str) -> Option<String>) -> Option<String> {
|
||||||
|
["USER", "USERNAME"]
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|name| get(name))
|
||||||
|
.find(|value| !value.is_empty())
|
||||||
|
}
|
||||||
|
|
||||||
fn default_sdk_session() -> String {
|
fn default_sdk_session() -> String {
|
||||||
let millis = SystemTime::now()
|
let millis = SystemTime::now()
|
||||||
.duration_since(UNIX_EPOCH)
|
.duration_since(UNIX_EPOCH)
|
||||||
@@ -432,6 +443,35 @@ mod tests {
|
|||||||
assert_eq!(destination_host("example.com:2222"), "example.com");
|
assert_eq!(destination_host("example.com:2222"), "example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn local_username_uses_unix_or_windows_environment_names() {
|
||||||
|
assert_eq!(
|
||||||
|
local_username_from_env(|name| match name {
|
||||||
|
"USER" => Some("palav".to_string()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.as_deref(),
|
||||||
|
Some("palav")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
local_username_from_env(|name| match name {
|
||||||
|
"USERNAME" => Some("palav-win".to_string()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.as_deref(),
|
||||||
|
Some("palav-win")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
local_username_from_env(|name| match name {
|
||||||
|
"USER" => Some(String::new()),
|
||||||
|
"USERNAME" => Some("palav-win".to_string()),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
.as_deref(),
|
||||||
|
Some("palav-win")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn default_identity_paths_are_expanded() {
|
fn default_identity_paths_are_expanded() {
|
||||||
assert!(
|
assert!(
|
||||||
|
|||||||
Reference in New Issue
Block a user