mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-05 15:41:23 +03:00
refactor is_public
This commit is contained in:
@@ -1087,8 +1087,15 @@ fn get_api_server_(api: String, custom: String) -> String {
|
||||
|
||||
#[inline]
|
||||
pub fn is_public(url: &str) -> bool {
|
||||
let url = url.to_ascii_lowercase();
|
||||
url.contains(".rustdesk.com")
|
||||
let parsed = url::Url::parse(url)
|
||||
.ok()
|
||||
.filter(|parsed| parsed.has_host())
|
||||
.or_else(|| url::Url::parse(&format!("http://{url}")).ok());
|
||||
let Some(host) = parsed.as_ref().and_then(url::Url::host_str) else {
|
||||
return false;
|
||||
};
|
||||
let host = host.strip_suffix('.').unwrap_or(host);
|
||||
host == "rustdesk.com" || host.ends_with(".rustdesk.com")
|
||||
}
|
||||
|
||||
pub fn get_udp_punch_enabled() -> bool {
|
||||
@@ -2880,6 +2887,16 @@ mod tests {
|
||||
assert!(!is_public("rustdesk.comhello.com"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_public_matches_rustdesk_root_domain() {
|
||||
assert!(is_public("rustdesk.com/"));
|
||||
assert!(is_public("rustdesk.com:21117"));
|
||||
assert!(is_public("api.rustdesk.com:21117"));
|
||||
assert!(!is_public("hello-rustdesk.com"));
|
||||
assert!(!is_public("api.rustdesk.com.evil.test"));
|
||||
assert!(!is_public("https://rustdesk.com@evil.test"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_should_use_tcp_proxy_for_api_url() {
|
||||
assert!(should_use_tcp_proxy_for_api_url(
|
||||
|
||||
Reference in New Issue
Block a user