From a52f459da67606ebca1399a866994bdc078a2669 Mon Sep 17 00:00:00 2001 From: Reactor Scram Date: Fri, 9 Aug 2024 23:18:05 -0500 Subject: [PATCH] test(gui-client): add unit test for the elevation check (#6238) This will always be elevated in CI, so just check that it doesn't crash. This came up during debugging while I was offline, and I just want to make CI check for regressions, since there's a lot of `unsafe` code in the Windows impl --- rust/gui-client/src-tauri/src/client/elevation.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rust/gui-client/src-tauri/src/client/elevation.rs b/rust/gui-client/src-tauri/src/client/elevation.rs index cfff37847..9f3d5ddc4 100644 --- a/rust/gui-client/src-tauri/src/client/elevation.rs +++ b/rust/gui-client/src-tauri/src/client/elevation.rs @@ -112,8 +112,20 @@ mod imp { impl Drop for ProcessToken { fn drop(&mut self) { // SAFETY: We got `inner` from `OpenProcessToken` and didn't mutate it after that. + // Closing a pseudo-handle is a harmless no-op, though this is a real handle. + // + // > The pseudo handle need not be closed when it is no longer needed. Calling the CloseHandle function with a pseudo handle has no effect. If the pseudo handle is duplicated by DuplicateHandle, the duplicate handle must be closed. unsafe { CloseHandle(self.inner) }.expect("`CloseHandle` should always succeed"); self.inner = HANDLE::default(); } } } + +#[cfg(test)] +mod tests { + // Make sure it doesn't crash + #[test] + fn is_normal_user() { + super::is_normal_user().unwrap(); + } +}