Implement backups, commit and restoration

This commit is contained in:
2026-10-20 00:13:39 +03:00
parent c879a8101b
commit 5418841b92
17 changed files with 5049 additions and 38 deletions
+17 -8
View File
@@ -1,4 +1,5 @@
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use wireguard_admin::config::{ResolvedSettings, SettingsFile};
@@ -32,6 +33,10 @@ restart_timeout_seconds = 30
.resolve_paths(Path::new("/synthetic/app"))
}
fn make_private(path: &Path) {
fs::set_permissions(path, fs::Permissions::from_mode(0o600)).unwrap();
}
fn server_and_client() -> (ConfigDocument, WireGuardPrivateKey, PublicKey) {
let server_key = WireGuardPrivateKey::generate().unwrap();
let client_key = WireGuardPrivateKey::generate().unwrap();
@@ -73,15 +78,21 @@ fn initial_setup_encrypts_valid_files_and_leaves_sources_and_server_unchanged()
let (server, client, identity) = server_and_client();
let original_server = server.render();
let source_bytes = client_file(&client, &server);
fs::write(directory.path().join("laptop.conf"), &source_bytes).unwrap();
let laptop = directory.path().join("laptop.conf");
fs::write(&laptop, &source_bytes).unwrap();
make_private(&laptop);
fs::write(
directory.path().join("broken.conf"),
b"not a WireGuard file",
)
.unwrap();
fs::write(directory.path().join("ignored.txt"), &source_bytes).unwrap();
let ignored = directory.path().join("ignored.txt");
fs::write(&ignored, &source_bytes).unwrap();
make_private(&ignored);
fs::create_dir(directory.path().join("nested")).unwrap();
fs::write(directory.path().join("nested/server.conf"), &source_bytes).unwrap();
let nested = directory.path().join("nested/server.conf");
fs::write(&nested, &source_bytes).unwrap();
make_private(&nested);
let prepared =
prepare_initial_setup(&settings(directory.path()), &server, "setup password").unwrap();
@@ -200,11 +211,9 @@ fn explicit_import_uses_existing_identity_and_rejects_duplicate_without_replacem
prepare_initial_setup(&settings(initial_source.path()), &server, "password").unwrap();
let original_recipient = initial.bundle.recipient().to_owned();
let mut bundle = initial.bundle;
fs::write(
directory.path().join("client.conf"),
client_file(&client, &server),
)
.unwrap();
let client_path = directory.path().join("client.conf");
fs::write(&client_path, client_file(&client, &server)).unwrap();
make_private(&client_path);
let report =
import_configured_directory(&mut bundle, &settings(directory.path()), &server).unwrap();
assert_eq!(bundle.recipient(), original_recipient);