mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-02-17 22:11:30 +08:00
@@ -1051,7 +1051,7 @@ fn get_api_server_(api: String, custom: String) -> String {
|
||||
|
||||
#[inline]
|
||||
pub fn is_public(url: &str) -> bool {
|
||||
url.contains("rustdesk.com")
|
||||
url.contains("rustdesk.com/") || url.ends_with("rustdesk.com")
|
||||
}
|
||||
|
||||
pub fn get_udp_punch_enabled() -> bool {
|
||||
@@ -2405,4 +2405,27 @@ mod tests {
|
||||
Duration::from_nanos(0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_public() {
|
||||
// Test URLs containing "rustdesk.com/"
|
||||
assert!(is_public("https://rustdesk.com/"));
|
||||
assert!(is_public("https://www.rustdesk.com/"));
|
||||
assert!(is_public("https://api.rustdesk.com/v1"));
|
||||
assert!(is_public("https://rustdesk.com/path"));
|
||||
|
||||
// Test URLs ending with "rustdesk.com"
|
||||
assert!(is_public("rustdesk.com"));
|
||||
assert!(is_public("https://rustdesk.com"));
|
||||
assert!(is_public("http://www.rustdesk.com"));
|
||||
assert!(is_public("https://api.rustdesk.com"));
|
||||
|
||||
// Test non-public URLs
|
||||
assert!(!is_public("https://example.com"));
|
||||
assert!(!is_public("https://custom-server.com"));
|
||||
assert!(!is_public("http://192.168.1.1"));
|
||||
assert!(!is_public("localhost"));
|
||||
assert!(!is_public("https://rustdesk.computer.com"));
|
||||
assert!(!is_public("rustdesk.comhello.com"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ fn heartbeat_url() -> String {
|
||||
Config::get_option("api-server"),
|
||||
Config::get_option("custom-rendezvous-server"),
|
||||
);
|
||||
if url.is_empty() || url.contains("rustdesk.com") {
|
||||
if url.is_empty() || crate::is_public(&url) {
|
||||
return "".to_owned();
|
||||
}
|
||||
format!("{}/api/heartbeat", url)
|
||||
|
||||
Reference in New Issue
Block a user