From 1b899a5ce8cdc6aba83db1f3e8335fba2bdead34 Mon Sep 17 00:00:00 2001 From: Guido Falsi Date: Fri, 28 Apr 2023 10:28:39 +0200 Subject: [PATCH] Add test for host and name extraction from filename. --- src/license.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/license.rs b/src/license.rs index 9d87ec7eb..1ad16f6f0 100644 --- a/src/license.rs +++ b/src/license.rs @@ -82,3 +82,60 @@ pub fn get_license_from_string(s: &str) -> ResultType { } bail!("Failed to parse"); } + +#[cfg(test)] +#[cfg(target_os = "windows")] +mod test { + #[test] + fn test_filename_license_string() { + assert_eq!( + get_license_from_string("rustdesk.exe"), + Ok(License { + host: "".to_owned(), + key: "".to_owned(), + api: "".to_owned(), + }) + ); + assert_eq!( + get_license_from_string("rustdesk"), + Ok(License { + host: "".to_owned(), + key: "".to_owned(), + api: "".to_owned(), + }) + ); + assert_eq!( + get_license_from_string("rustdesk-host=server.example.net.exe"), + Ok(License { + host: "server.example.net".to_owned(), + key: "".to_owned(), + api: "".to_owned(), + }) + ); + assert_eq!( + get_license_from_string("rustdesk-host=server.example.net,.exe"), + Ok(License { + host: "server.example.net".to_owned(), + key: "".to_owned(), + api: "".to_owned(), + }) + ); + // key in these tests is "foobar.,2" base64 encoded + assert_eq!( + get_license_from_string("rustdesk-host=server.example.net,key=Zm9vYmFyLiwyCg==.exe"), + Ok(License { + host: "server.example.net".to_owned(), + key: "Zm9vYmFyLiwyCg==".to_owned(), + api: "".to_owned(), + }) + ); + assert_eq!( + get_license_from_string("rustdesk-host=server.example.net,key=Zm9vYmFyLiwyCg==,.exe"), + Ok(License { + host: "server.example.net".to_owned(), + key: "Zm9vYmFyLiwyCg==".to_owned(), + api: "".to_owned(), + }) + ); + } +}