mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
fix: use portal policy for session extension
This commit is contained in:
10 files changed
+164
-49
No files matched your search
@@ -33,6 +33,10 @@ pub struct PortalConfig {
|
||||
* The version returned by the portal config, if any
|
||||
*/
|
||||
version: Option<String>,
|
||||
/**
|
||||
* Whether the portal policy allows extending the gateway session.
|
||||
*/
|
||||
allow_extend_session: Option<bool>,
|
||||
}
|
||||
|
||||
impl PortalConfig {
|
||||
@@ -60,6 +64,10 @@ impl PortalConfig {
|
||||
self.version.as_deref()
|
||||
}
|
||||
|
||||
pub fn allow_extend_session(&self) -> Option<bool> {
|
||||
self.allow_extend_session
|
||||
}
|
||||
|
||||
/// In-place sort the gateways by region
|
||||
pub fn sort_gateways(&mut self, region: &str) {
|
||||
let preferred_gateway = self.find_preferred_gateway(region);
|
||||
@@ -168,6 +176,7 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara
|
||||
|
||||
let version = root.descendant_text("version").map(|s| s.to_string());
|
||||
info!("Detected portal version: {:?}", version);
|
||||
let allow_extend_session = parse_allow_extend_session(&root);
|
||||
|
||||
Ok(PortalConfig {
|
||||
portal: server.to_string(),
|
||||
@@ -177,9 +186,18 @@ pub async fn retrieve_config(portal: &str, cred: &Credential, gp_params: &GpPara
|
||||
config_digest: config_digest.map(|s| s.to_string()),
|
||||
internal_host_detection: if ihd_enabled { Some(prefer_internal) } else { None },
|
||||
version,
|
||||
allow_extend_session,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_allow_extend_session(root: &Element) -> Option<bool> {
|
||||
match root.descendant_text("allow-extend-session")?.trim() {
|
||||
"yes" => Some(true),
|
||||
"no" => Some(false),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Perform DNS lookup and compare the result with the expected hostname
|
||||
fn internal_host_detect(element: &Element) -> bool {
|
||||
let ip_info = [
|
||||
@@ -213,3 +231,40 @@ fn internal_host_detect(element: &Element) -> bool {
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn parse_xml(xml: &str) -> Element {
|
||||
Element::parse(xml.as_bytes()).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_allow_extend_session_yes() {
|
||||
let root = parse_xml("<response><allow-extend-session>yes</allow-extend-session></response>");
|
||||
|
||||
assert_eq!(parse_allow_extend_session(&root), Some(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_allow_extend_session_no() {
|
||||
let root = parse_xml("<response><allow-extend-session>no</allow-extend-session></response>");
|
||||
|
||||
assert_eq!(parse_allow_extend_session(&root), Some(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaves_absent_allow_extend_session_unknown() {
|
||||
let root = parse_xml("<response></response>");
|
||||
|
||||
assert_eq!(parse_allow_extend_session(&root), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignores_non_official_allow_extend_session_values() {
|
||||
let root = parse_xml("<response><allow-extend-session>true</allow-extend-session></response>");
|
||||
|
||||
assert_eq!(parse_allow_extend_session(&root), None);
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,8 @@ pub struct ConnectArgs {
|
||||
local_hostname: Option<String>,
|
||||
force_dpd: u32,
|
||||
no_xmlpost: bool,
|
||||
#[serde(rename = "allowExtendSession")]
|
||||
allow_extend_session: bool,
|
||||
}
|
||||
|
||||
impl ConnectArgs {
|
||||
@@ -76,6 +78,7 @@ impl ConnectArgs {
|
||||
local_hostname: None,
|
||||
force_dpd: 0,
|
||||
no_xmlpost: false,
|
||||
allow_extend_session: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +161,10 @@ impl ConnectArgs {
|
||||
pub fn no_xmlpost(&self) -> bool {
|
||||
self.no_xmlpost
|
||||
}
|
||||
|
||||
pub fn allow_extend_session(&self) -> bool {
|
||||
self.allow_extend_session
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Type, Clone)]
|
||||
@@ -264,6 +271,11 @@ impl ConnectRequest {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_allow_extend_session(mut self, allow_extend_session: bool) -> Self {
|
||||
self.args.allow_extend_session = allow_extend_session;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn gateway(&self) -> &Gateway {
|
||||
self.info.gateway()
|
||||
}
|
||||
@@ -296,3 +308,20 @@ pub struct UpdateGuiRequest {
|
||||
pub path: String,
|
||||
pub checksum: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn connect_request_serializes_allow_extend_session() {
|
||||
let gateway = Gateway::new("Gateway".to_string(), "vpn.example.com".to_string());
|
||||
let info = ConnectInfo::new("portal.example.com".to_string(), gateway.clone(), vec![gateway]);
|
||||
let req = ConnectRequest::new(info, "authcookie=AUTH".to_string()).with_allow_extend_session(true);
|
||||
let value = serde_json::to_value(req).unwrap();
|
||||
|
||||
assert_eq!(value["args"]["allowExtendSession"], json!(true));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user