summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2024-01-08 16:53:26 +0100
committerDavid Lönnhager <david.l@mullvad.net>2024-01-08 16:53:26 +0100
commit63aa10fefc87e0a37bc482cccaaa56b14a2fbc59 (patch)
tree761cc8d732e9d36d623965c215870136a5189526 /mullvad-daemon
parent4d33d452feaec4c82f134803c152486282ad36c8 (diff)
parent167e9a9a1f4d856e034fee55cad01065e24c427f (diff)
downloadmullvadvpn-63aa10fefc87e0a37bc482cccaaa56b14a2fbc59.tar.xz
mullvadvpn-63aa10fefc87e0a37bc482cccaaa56b14a2fbc59.zip
Merge branch 'doc-settings-patch'
Diffstat (limited to 'mullvad-daemon')
-rw-r--r--mullvad-daemon/src/settings/patch.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/mullvad-daemon/src/settings/patch.rs b/mullvad-daemon/src/settings/patch.rs
index f3682b4322..50c0da6304 100644
--- a/mullvad-daemon/src/settings/patch.rs
+++ b/mullvad-daemon/src/settings/patch.rs
@@ -131,8 +131,19 @@ pub async fn merge_validate_patch(
settings: &mut SettingsPersister,
json_patch: &str,
) -> Result<(), Error> {
+ let new_settings = merge_validate_patch_inner(settings, json_patch)?;
+
+ settings
+ .update(move |settings| *settings = new_settings)
+ .await
+ .map_err(Error::Settings)?;
+
+ Ok(())
+}
+
+fn merge_validate_patch_inner(settings: &Settings, json_patch: &str) -> Result<Settings, Error> {
let mut settings_value: serde_json::Value =
- serde_json::to_value(settings.to_settings()).map_err(Error::SerializeSettings)?;
+ serde_json::to_value(settings).map_err(Error::SerializeSettings)?;
let patch_value: serde_json::Value =
serde_json::from_str(json_patch).map_err(Error::ParsePatch)?;
@@ -142,12 +153,7 @@ pub async fn merge_validate_patch(
let new_settings: Settings =
serde_json::from_value(settings_value).map_err(Error::DeserializePatched)?;
- settings
- .update(move |settings| *settings = new_settings)
- .await
- .map_err(Error::Settings)?;
-
- Ok(())
+ Ok(new_settings)
}
/// Replace overrides for existing values in the array if there's a matching hostname. For hostnames
@@ -400,6 +406,17 @@ fn test_overflow() {
));
}
+/// Test whether valid patches from documentation are accepted by the implementation
+#[test]
+fn test_valid_patch_files() {
+ const OVERRIDE_PATCH: &str =
+ include_str!("../../../docs/patch-examples/override-relay-ips.json");
+
+ let prev_settings = Settings::default();
+ let _ = merge_validate_patch_inner(&prev_settings, OVERRIDE_PATCH)
+ .expect("failed to apply relay overrides");
+}
+
#[test]
fn test_patch_relay_override() {
const PERMITTED_SUBKEYS: &PermittedKey = &PermittedKey::object(&[(