#![cfg(windows)]
use windows_token::{Privilege, SecurityImpersonationLevel, Token, TokenType};
#[test]
fn open_current_process_token() {
let tok = Token::open_current_process().expect("open current-process token");
assert!(!tok.as_raw().is_invalid(), "expected a live token handle");
}
#[test]
fn sechangenotify_is_enabled_for_normal_user() {
let tok = Token::open_current_process().expect("open token");
let prev = tok
.enable_privilege(Privilege::SeChangeNotify)
.expect("SeChangeNotify should be present on every normal user");
assert!(prev.was_applied);
assert_eq!(prev.privilege, Privilege::SeChangeNotify);
}
#[test]
fn duplicate_round_trip_impersonation_and_revert() {
let tok = Token::open_current_process().expect("open token");
let dup = tok
.duplicate(
TokenType::Impersonation,
SecurityImpersonationLevel::Impersonation,
)
.expect("duplicate as impersonation");
assert!(!dup.as_raw().is_invalid());
{
let _g = dup.impersonate_on_thread().expect("impersonate");
}
let _g2 = dup.impersonate_on_thread().expect("re-impersonate");
}