summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-types/src/settings/migrations/v1.rs59
-rw-r--r--mullvad-types/src/settings/migrations/v2.rs58
-rw-r--r--mullvad-types/src/settings/migrations/v3.rs30
-rw-r--r--mullvad-types/src/settings/migrations/v4.rs27
4 files changed, 86 insertions, 88 deletions
diff --git a/mullvad-types/src/settings/migrations/v1.rs b/mullvad-types/src/settings/migrations/v1.rs
index 484b35ee4e..8e9ed04b89 100644
--- a/mullvad-types/src/settings/migrations/v1.rs
+++ b/mullvad-types/src/settings/migrations/v1.rs
@@ -61,10 +61,10 @@ impl super::SettingsMigration for Migration {
#[cfg(test)]
mod test {
- use super::super::try_migrate_settings;
+ use super::{super::SettingsMigration, Migration};
use serde_json;
- pub const NEW_SETTINGS: &str = r#"
+ pub const V2_SETTINGS: &str = r#"
{
"account_token": "1234",
"relay_settings": {
@@ -75,27 +75,16 @@ mod test {
}
},
"tunnel_protocol": "any",
- "wireguard_constraints": {
- "port": "any"
- },
"openvpn_constraints": {
"port": {
- "only": {
- "protocol": "udp",
- "port": {
- "only": 53
- }
- }
+ "only": 53
+ },
+ "protocol": {
+ "only": "udp"
}
}
}
},
- "bridge_settings": {
- "normal": {
- "location": "any"
- }
- },
- "bridge_state": "auto",
"allow_lan": true,
"block_when_disconnected": false,
"auto_connect": false,
@@ -110,7 +99,8 @@ mod test {
"enable_ipv6": false
}
},
- "settings_version": 5
+ "show_beta_releases": false,
+ "settings_version": 2
}
"#;
@@ -138,12 +128,6 @@ mod test {
}
}
},
- "bridge_settings": {
- "normal": {
- "location": "any"
- }
- },
- "bridge_state": "auto",
"allow_lan": true,
"block_when_disconnected": false,
"auto_connect": false,
@@ -190,8 +174,7 @@ mod test {
"auto_connect": false,
"tunnel_options": {
"openvpn": {
- "mssfix": null,
- "proxy": null
+ "mssfix": null
},
"wireguard": {
"mtu": null
@@ -206,19 +189,27 @@ mod test {
#[test]
fn test_v1_migration() {
- let migrated_settings =
- try_migrate_settings(V1_SETTINGS.as_bytes()).expect("Migration failed");
- let new_settings = serde_json::from_str(NEW_SETTINGS).unwrap();
+ let mut old_settings = serde_json::from_str(V1_SETTINGS).unwrap();
- assert_eq!(&migrated_settings, &new_settings);
+ let migration = Migration;
+ assert!(migration.version_matches(&mut old_settings));
+
+ migration.migrate(&mut old_settings).unwrap();
+ let new_settings: serde_json::Value = serde_json::from_str(V2_SETTINGS).unwrap();
+
+ assert_eq!(&old_settings, &new_settings);
}
#[test]
fn test_v1_2019v3_migration() {
- let migrated_settings =
- try_migrate_settings(V1_SETTINGS_2019V3.as_bytes()).expect("Migration failed");
- let new_settings = serde_json::from_str(NEW_SETTINGS).unwrap();
+ let mut old_settings = serde_json::from_str(V1_SETTINGS_2019V3).unwrap();
+
+ let migration = Migration;
+ assert!(migration.version_matches(&mut old_settings));
+
+ migration.migrate(&mut old_settings).unwrap();
+ let new_settings: serde_json::Value = serde_json::from_str(V2_SETTINGS).unwrap();
- assert_eq!(&migrated_settings, &new_settings);
+ assert_eq!(&old_settings, &new_settings);
}
}
diff --git a/mullvad-types/src/settings/migrations/v2.rs b/mullvad-types/src/settings/migrations/v2.rs
index badeaacdbc..04d94eacbf 100644
--- a/mullvad-types/src/settings/migrations/v2.rs
+++ b/mullvad-types/src/settings/migrations/v2.rs
@@ -51,6 +51,10 @@ impl super::SettingsMigration for Migration {
settings["tunnel_options"]["wireguard"]["rotation_interval"] =
serde_json::json!(new_ivl);
+ settings["tunnel_options"]["wireguard"]
+ .as_object_mut()
+ .ok_or(Error::NoMatchingVersion)?
+ .remove("automatic_rotation");
}
settings["settings_version"] = serde_json::json!(SettingsVersion::V3);
@@ -61,7 +65,7 @@ impl super::SettingsMigration for Migration {
#[cfg(test)]
mod test {
- use super::super::try_migrate_settings;
+ use super::{super::SettingsMigration, Migration};
use serde_json;
const V2_SETTINGS: &str = r#"
@@ -74,16 +78,16 @@ mod test {
"country": "se"
}
},
- "tunnel": {
- "only": {
- "openvpn": {
- "port": {
- "only": 53
- },
- "protocol": {
- "only": "udp"
- }
- }
+ "tunnel_protocol": "any",
+ "wireguard_constraints": {
+ "port": "any"
+ },
+ "openvpn_constraints": {
+ "port": {
+ "only": 53
+ },
+ "protocol": {
+ "only": "udp"
}
}
}
@@ -103,16 +107,18 @@ mod test {
},
"wireguard": {
"mtu": null,
- "automatic_rotation": 24
+ "automatic_rotation": 10
},
"generic": {
"enable_ipv6": false
}
- }
+ },
+ "show_beta_releases": null,
+ "settings_version": 2
}
"#;
- pub const NEW_SETTINGS: &str = r#"
+ pub const V3_SETTINGS: &str = r#"
{
"account_token": "1234",
"relay_settings": {
@@ -128,12 +134,10 @@ mod test {
},
"openvpn_constraints": {
"port": {
- "only": {
- "protocol": "udp",
- "port": {
- "only": 53
- }
- }
+ "only": 53
+ },
+ "protocol": {
+ "only": "udp"
}
}
}
@@ -162,17 +166,21 @@ mod test {
"enable_ipv6": false
}
},
- "settings_version": 5
+ "settings_version": 3
}
"#;
#[test]
fn test_v2_migration() {
- let migrated_settings =
- try_migrate_settings(V2_SETTINGS.as_bytes()).expect("Migration failed");
- let new_settings = serde_json::from_str(NEW_SETTINGS).unwrap();
+ let mut old_settings = serde_json::from_str(V2_SETTINGS).unwrap();
+
+ let migration = Migration;
+ assert!(migration.version_matches(&mut old_settings));
+
+ migration.migrate(&mut old_settings).unwrap();
+ let new_settings: serde_json::Value = serde_json::from_str(V3_SETTINGS).unwrap();
- assert_eq!(&migrated_settings, &new_settings);
+ assert_eq!(&old_settings, &new_settings);
}
}
diff --git a/mullvad-types/src/settings/migrations/v3.rs b/mullvad-types/src/settings/migrations/v3.rs
index 0aa53e3da4..70b5cef196 100644
--- a/mullvad-types/src/settings/migrations/v3.rs
+++ b/mullvad-types/src/settings/migrations/v3.rs
@@ -50,7 +50,7 @@ impl super::SettingsMigration for Migration {
#[cfg(test)]
mod test {
- use super::super::try_migrate_settings;
+ use super::{super::SettingsMigration, Migration};
use serde_json;
pub const V3_SETTINGS: &str = r#"
@@ -69,7 +69,7 @@ mod test {
},
"openvpn_constraints": {
"port": {
- "only": 53
+ "only": 1195
},
"protocol": {
"only": "udp"
@@ -112,7 +112,7 @@ mod test {
}
"#;
- pub const NEW_SETTINGS: &str = r#"
+ pub const V4_SETTINGS: &str = r#"
{
"account_token": "1234",
"relay_settings": {
@@ -128,12 +128,10 @@ mod test {
},
"openvpn_constraints": {
"port": {
- "only": {
- "protocol": "udp",
- "port": {
- "only": 53
- }
- }
+ "only": 1195
+ },
+ "protocol": {
+ "only": "udp"
}
}
}
@@ -175,17 +173,21 @@ mod test {
}
}
},
- "settings_version": 5
+ "settings_version": 4
}
"#;
#[test]
fn test_v3_migration() {
- let migrated_settings =
- try_migrate_settings(V3_SETTINGS.as_bytes()).expect("Migration failed");
- let new_settings = serde_json::from_str(NEW_SETTINGS).unwrap();
+ let mut old_settings = serde_json::from_str(V3_SETTINGS).unwrap();
+
+ let migration = Migration;
+ assert!(migration.version_matches(&mut old_settings));
+
+ migration.migrate(&mut old_settings).unwrap();
+ let new_settings: serde_json::Value = serde_json::from_str(V4_SETTINGS).unwrap();
- assert_eq!(&migrated_settings, &new_settings);
+ assert_eq!(&old_settings, &new_settings);
}
}
diff --git a/mullvad-types/src/settings/migrations/v4.rs b/mullvad-types/src/settings/migrations/v4.rs
index 7a9d1a88fb..f1b3bd43ab 100644
--- a/mullvad-types/src/settings/migrations/v4.rs
+++ b/mullvad-types/src/settings/migrations/v4.rs
@@ -81,16 +81,9 @@ impl super::SettingsMigration for Migration {
protocol: openvpn_protocol_from_port(port),
port: Constraint::Only(port),
}),
- (Constraint::Only(port), Constraint::Only(protocol)) => {
- Constraint::Only(TransportPort {
- protocol,
- port: Constraint::Only(port),
- })
+ (port, Constraint::Only(protocol)) => {
+ Constraint::Only(TransportPort { protocol, port })
}
- (Constraint::Any, Constraint::Only(protocol)) => Constraint::Only(TransportPort {
- protocol,
- port: Constraint::Any,
- }),
(Constraint::Any, Constraint::Any) => Constraint::Any,
};
@@ -128,7 +121,7 @@ fn wg_protocol_from_port(port: u16) -> TransportProtocol {
#[cfg(test)]
mod test {
- use super::super::try_migrate_settings;
+ use super::{super::SettingsMigration, Migration};
use serde_json;
pub const V4_SETTINGS: &str = r#"
@@ -197,7 +190,7 @@ mod test {
}
"#;
- pub const NEW_SETTINGS: &str = r#"
+ pub const V5_SETTINGS: &str = r#"
{
"account_token": "1234",
"relay_settings": {
@@ -274,10 +267,14 @@ mod test {
#[test]
fn test_v4_migration() {
- let migrated_settings =
- try_migrate_settings(V4_SETTINGS.as_bytes()).expect("Migration failed");
- let new_settings = serde_json::from_str(NEW_SETTINGS).unwrap();
+ let mut old_settings = serde_json::from_str(V4_SETTINGS).unwrap();
+
+ let migration = Migration;
+ assert!(migration.version_matches(&mut old_settings));
+
+ migration.migrate(&mut old_settings).unwrap();
+ let new_settings: serde_json::Value = serde_json::from_str(V5_SETTINGS).unwrap();
- assert_eq!(&migrated_settings, &new_settings);
+ assert_eq!(&old_settings, &new_settings);
}
}