mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 06:26:14 -05:00
Merge remote-tracking branch 'origin/main' into feat/auth-callback-handler
# Conflicts: # apps/gpclient/src/cli.rs # apps/gpclient/src/connect/args.rs
This commit is contained in:
3 files changed
+57
No files matched your search
@@ -119,6 +119,7 @@ impl Cli {
|
|||||||
fn can_run_alongside_client(&self) -> bool {
|
fn can_run_alongside_client(&self) -> bool {
|
||||||
match &self.command {
|
match &self.command {
|
||||||
CliCommand::Disconnect(_) => true,
|
CliCommand::Disconnect(_) => true,
|
||||||
|
CliCommand::Hip(_) => true,
|
||||||
CliCommand::LaunchGui(args) => args.is_auth_callback(),
|
CliCommand::LaunchGui(args) => args.is_auth_callback(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@@ -240,6 +241,25 @@ mod tests {
|
|||||||
assert_eq!(cli.lock_file, PathBuf::from("/tmp/gpclient-portal.lock"));
|
assert_eq!(cli.lock_file, PathBuf::from("/tmp/gpclient-portal.lock"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hip_can_run_alongside_connected_client() {
|
||||||
|
let cli = Cli::try_parse_from([
|
||||||
|
"gpclient",
|
||||||
|
"hip",
|
||||||
|
"--client-version",
|
||||||
|
"6.2.4-49",
|
||||||
|
"--client-os",
|
||||||
|
"Mac",
|
||||||
|
"--cookie",
|
||||||
|
"user=alice",
|
||||||
|
"--md5",
|
||||||
|
"test",
|
||||||
|
])
|
||||||
|
.expect("HIP arguments should parse");
|
||||||
|
|
||||||
|
assert!(cli.can_run_alongside_client());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"))]
|
||||||
fn launch_gui_accepts_auth_callback() {
|
fn launch_gui_accepts_auth_callback() {
|
||||||
|
|||||||
@@ -149,6 +149,14 @@ pub(crate) struct ConnectArgs {
|
|||||||
|
|
||||||
#[arg(long, help = "Listen on this IP address when using '--browser remote'")]
|
#[arg(long, help = "Listen on this IP address when using '--browser remote'")]
|
||||||
pub(super) browser_listen: Option<IpAddr>,
|
pub(super) browser_listen: Option<IpAddr>,
|
||||||
|
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
help = "Authenticate and print the gateway cookie to stdout, then exit without starting the \
|
||||||
|
VPN tunnel. Outputs two lines: COOKIE='<value>' and HOST='<gateway>'. Combine with \
|
||||||
|
--cookie-cache to avoid re-authenticating when the portal session is still valid."
|
||||||
|
)]
|
||||||
|
pub(super) cookie_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn build_os_profile(args: &ConnectArgs) -> OsProfile {
|
pub(super) fn build_os_profile(args: &ConnectArgs) -> OsProfile {
|
||||||
@@ -418,4 +426,23 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(err.kind(), ErrorKind::ArgumentConflict);
|
assert_eq!(err.kind(), ErrorKind::ArgumentConflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cookie_only_flag_parses() {
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com", "--cookie-only"])
|
||||||
|
.expect("--cookie-only should parse");
|
||||||
|
|
||||||
|
assert!(cli.args.cookie_only);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cookie_only_is_disabled_by_default() {
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
let cli = ConnectArgsTestCli::try_parse_from(["test", "portal.example.com"]).expect("connect args should parse");
|
||||||
|
|
||||||
|
assert!(!cli.args.cookie_only);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -341,6 +341,16 @@ impl ConnectHandler<'_> {
|
|||||||
allow_extend_session: bool,
|
allow_extend_session: bool,
|
||||||
extension_auth: SessionExtensionAuth,
|
extension_auth: SessionExtensionAuth,
|
||||||
) -> Result<(), GatewayConnectError> {
|
) -> Result<(), GatewayConnectError> {
|
||||||
|
// --cookie-only: print the gateway cookie and exit without opening a tunnel.
|
||||||
|
// No tun device is allocated, no root is required, and no logout is issued
|
||||||
|
// against the gateway — the cookie remains valid for subsequent use.
|
||||||
|
// Output format matches openconnect --authenticate for easy shell consumption.
|
||||||
|
if self.args.cookie_only {
|
||||||
|
println!("COOKIE='{}'", cookie);
|
||||||
|
println!("HOST='{}'", gateway);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let mtu = self.args.mtu.unwrap_or(0);
|
let mtu = self.args.mtu.unwrap_or(0);
|
||||||
let (hip, csd_wrapper) = self.determine_hip_script();
|
let (hip, csd_wrapper) = self.determine_hip_script();
|
||||||
let hip_user = self.determine_hip_user();
|
let hip_user = self.determine_hip_user();
|
||||||
|
|||||||
Reference in new issue
Block a user