mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
fix: enhance Linux serial number resolution and add unit tests
This commit is contained in:
2 files changed
+33
-4
No files matched your search
@@ -27,6 +27,7 @@ A modern GlobalProtect VPN client for Linux, built on OpenConnect with full supp
|
|||||||
- [Other Distributions](#other-distributions)
|
- [Other Distributions](#other-distributions)
|
||||||
- [Building from Source](#building-from-source)
|
- [Building from Source](#building-from-source)
|
||||||
- [Frequently Asked Questions](#frequently-asked-questions)
|
- [Frequently Asked Questions](#frequently-asked-questions)
|
||||||
|
- [NetworkManager Integration](#networkmanager-integration)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -284,7 +285,7 @@ gnome-extensions enable [email protected]
|
|||||||
|
|
||||||
### Official Docker Image
|
### Official Docker Image
|
||||||
|
|
||||||
The official Docker image provides the CLI tools on Alpine Linux:
|
The [official Docker image](https://hub.docker.com/r/yuezk/globalprotect-openconnect) provides the CLI tools on Alpine Linux:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker pull yuezk/globalprotect-openconnect:<version>
|
docker pull yuezk/globalprotect-openconnect:<version>
|
||||||
@@ -468,6 +469,11 @@ sudo -E gpclient connect <portal>
|
|||||||
|
|
||||||
See related issue: [#316](https://github.com/yuezk/GlobalProtect-openconnect/issues/316)
|
See related issue: [#316](https://github.com/yuezk/GlobalProtect-openconnect/issues/316)
|
||||||
|
|
||||||
|
## NetworkManager Integration
|
||||||
|
|
||||||
|
- [WMP/GlobalProtect-SAML-NetworkManager](https://github.com/WMP/GlobalProtect-SAML-NetworkManager) – NetworkManager VPN plugin with SAML/SSO support for GNOME and KDE Plasma
|
||||||
|
- [jdpipe/networkmanager-gpclient](https://github.com/jdpipe/networkmanager-gpclient) – NetworkManager VPN plugin that uses `gpclient`
|
||||||
|
|
||||||
## Licensing
|
## Licensing
|
||||||
|
|
||||||
### Trial and Pricing
|
### Trial and Pricing
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ mod platform {
|
|||||||
mod platform {
|
mod platform {
|
||||||
use super::{
|
use super::{
|
||||||
ClientOs, NativeHostIdentitySnapshot, derive_uuid_from_seed, fallback_hostname, primary_mac_colon, resolve_host_id,
|
ClientOs, NativeHostIdentitySnapshot, derive_uuid_from_seed, fallback_hostname, primary_mac_colon, resolve_host_id,
|
||||||
|
serial_number,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
@@ -429,9 +430,17 @@ mod platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn collect_linux_serial_number() -> Option<String> {
|
fn collect_linux_serial_number() -> Option<String> {
|
||||||
["/sys/class/dmi/id/product_serial", "/sys/class/dmi/id/product_uuid"]
|
resolve_linux_serial_number(
|
||||||
.iter()
|
read_linux_identity_file("/sys/class/dmi/id/product_serial"),
|
||||||
.find_map(|path| read_linux_identity_file(path))
|
collect_linux_product_uuid,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resolve_linux_serial_number(
|
||||||
|
product_serial: Option<String>,
|
||||||
|
product_uuid: impl FnOnce() -> Option<String>,
|
||||||
|
) -> Option<String> {
|
||||||
|
product_serial.or_else(|| product_uuid().and_then(|uuid| serial_number::vmware_from_uuid(&uuid)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -446,6 +455,20 @@ mod platform {
|
|||||||
);
|
);
|
||||||
assert_eq!(normalize_uuid("not-a-uuid"), None);
|
assert_eq!(normalize_uuid("not-a-uuid"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn linux_serial_number_preserves_product_serial_and_formats_uuid_fallback() {
|
||||||
|
let uuid = Some("5a784d56-6461-19ac-9ea9-d36a3b9c6cef".to_string());
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
resolve_linux_serial_number(Some("product-serial".to_string()), || uuid.clone()),
|
||||||
|
Some("product-serial".to_string())
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
resolve_linux_serial_number(None, || uuid),
|
||||||
|
Some("VMware-56 4d 78 5a 61 64 ac 19-9e a9 d3 6a 3b 9c 6c ef".to_string())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user