telos_agent/tools/command_security/powershell/
aliases.rs1pub fn canonical_command_name(name: &str) -> String {
2 match name.to_ascii_lowercase().as_str() {
3 "ls" | "dir" | "gci" => "Get-ChildItem".into(),
4 "cat" | "gc" | "type" => "Get-Content".into(),
5 "pwd" | "gl" => "Get-Location".into(),
6 "ps" | "gps" => "Get-Process".into(),
7 "echo" | "write" => "Write-Output".into(),
8 "rm" | "del" | "erase" | "ri" => "Remove-Item".into(),
9 "cp" | "copy" | "cpi" => "Copy-Item".into(),
10 "mv" | "move" | "mi" => "Move-Item".into(),
11 other => canonical_case(other),
12 }
13}
14
15fn canonical_case(lower: &str) -> String {
16 match lower {
17 "get-process" => "Get-Process".into(),
18 "get-content" => "Get-Content".into(),
19 "get-childitem" => "Get-ChildItem".into(),
20 "get-location" => "Get-Location".into(),
21 "remove-item" => "Remove-Item".into(),
22 "copy-item" => "Copy-Item".into(),
23 "move-item" => "Move-Item".into(),
24 "write-output" => "Write-Output".into(),
25 "select-string" => "Select-String".into(),
26 _ => lower.to_string(),
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn canonicalizes_common_aliases_case_insensitively() {
36 assert_eq!(canonical_command_name("rm"), "Remove-Item");
37 assert_eq!(canonical_command_name("CAT"), "Get-Content");
38 assert_eq!(canonical_command_name("pwd"), "Get-Location");
39 assert_eq!(canonical_command_name("Get-Process"), "Get-Process");
40 }
41}