mirror of
https://github.com/rustdesk/hbb_common.git
synced 2026-07-12 17:53:51 +00:00
fix(security): symmetric nonce, update unit tests
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -3274,6 +3274,11 @@ mod tests {
|
||||
original_hard_settings: HashMap<String, String>,
|
||||
}
|
||||
|
||||
struct ConfigFileRestoreGuard {
|
||||
path: PathBuf,
|
||||
original_content: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl ConfigStateTestGuard {
|
||||
fn new(config: Config, hard_settings: HashMap<String, String>) -> Self {
|
||||
let original_config = Config::get();
|
||||
@@ -3294,6 +3299,29 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigFileRestoreGuard {
|
||||
fn new(path: PathBuf) -> Self {
|
||||
let original_content = fs::read(&path).ok();
|
||||
Self {
|
||||
path,
|
||||
original_content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ConfigFileRestoreGuard {
|
||||
fn drop(&mut self) {
|
||||
if let Some(content) = &self.original_content {
|
||||
if let Some(parent) = self.path.parent() {
|
||||
fs::create_dir_all(parent).ok();
|
||||
}
|
||||
fs::write(&self.path, content).ok();
|
||||
} else {
|
||||
fs::remove_file(&self.path).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn with_config_and_hard_settings<R>(
|
||||
config: Config,
|
||||
hard_settings: HashMap<String, String>,
|
||||
@@ -3522,6 +3550,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_config2_store_keeps_existing_unlock_pin_when_pin_is_unchanged() {
|
||||
let _guard = CONFIG_STATE_TEST_LOCK.lock().unwrap();
|
||||
let _file_guard = ConfigFileRestoreGuard::new(Config::file_("2"));
|
||||
let pin = "123456";
|
||||
let original_unlock_pin =
|
||||
encrypt_str_or_original(pin, PASSWORD_ENC_VERSION, ENCRYPT_MAX_LEN);
|
||||
|
||||
Reference in New Issue
Block a user