Skip to content

Commit 08b91eb

Browse files
test(trogon-mcp): cover safe_url helper with unit tests
safe_url is called only from coverage(off) functions so its lines were new misses. Add 5 unit tests covering the main branches: strip path/query/fragment, strip userinfo, preserve port, no-scheme fallback, and plain host with no path. Signed-off-by: Jorge Gonzalez <jgonzalez@straw-hat.co> Signed-off-by: Jorge <jramirezhdez02@gmail.com>
1 parent 885e411 commit 08b91eb

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

rsworkspace/crates/trogon-mcp/src/client.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,42 @@ impl McpClient {
168168
.map_err(|e| format!("MCP parse error: {e}"))
169169
}
170170
}
171+
172+
#[cfg(test)]
173+
mod tests {
174+
use super::safe_url;
175+
176+
#[test]
177+
fn safe_url_strips_path_query_fragment() {
178+
assert_eq!(
179+
safe_url("http://mcp.example.com/mcp?token=secret#frag"),
180+
"http://mcp.example.com"
181+
);
182+
}
183+
184+
#[test]
185+
fn safe_url_strips_userinfo() {
186+
assert_eq!(
187+
safe_url("http://user:pass@mcp.example.com/mcp"),
188+
"http://mcp.example.com"
189+
);
190+
}
191+
192+
#[test]
193+
fn safe_url_preserves_port() {
194+
assert_eq!(
195+
safe_url("http://mcp.example.com:8080/mcp"),
196+
"http://mcp.example.com:8080"
197+
);
198+
}
199+
200+
#[test]
201+
fn safe_url_no_scheme_returns_original() {
202+
assert_eq!(safe_url("not-a-url"), "not-a-url");
203+
}
204+
205+
#[test]
206+
fn safe_url_plain_host_no_path() {
207+
assert_eq!(safe_url("http://mcp.example.com"), "http://mcp.example.com");
208+
}
209+
}

0 commit comments

Comments
 (0)