diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-07-19 14:25:55 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-07-26 11:25:54 +0100 |
| commit | 7484bf97ee46fe396350ed515ff12fef48eb2c91 (patch) | |
| tree | e9e2225a1896f66c9811b3d873eb1ccdd9da7f48 | |
| parent | 7106c34585f3db116307bc908f1eb1fbf51a73cf (diff) | |
| download | mullvadvpn-7484bf97ee46fe396350ed515ff12fef48eb2c91.tar.xz mullvadvpn-7484bf97ee46fe396350ed515ff12fef48eb2c91.zip | |
Add tests for settings migration
| -rw-r--r-- | mullvad-types/src/settings/migrations/v1.rs | 119 | ||||
| -rw-r--r-- | mullvad-types/src/settings/mod.rs | 2 |
2 files changed, 120 insertions, 1 deletions
diff --git a/mullvad-types/src/settings/migrations/v1.rs b/mullvad-types/src/settings/migrations/v1.rs index 8960d07499..a5b4e7c618 100644 --- a/mullvad-types/src/settings/migrations/v1.rs +++ b/mullvad-types/src/settings/migrations/v1.rs @@ -100,3 +100,122 @@ pub enum TunnelConstraints { #[serde(rename = "wireguard")] Wireguard(WireguardConstraints), } + +#[cfg(test)] +mod test { + use super::super::SettingsMigration; + use serde_json; + const OLD_SETTINGS: &str = r#" +{ + "account_token": "1234", + "relay_settings": { + "normal": { + "location": { + "only": { + "country": "se" + } + }, + "tunnel": { + "only": { + "openvpn": { + "port": { + "only": 53 + }, + "protocol": { + "only": "udp" + } + } + } + } + } + }, + "bridge_settings": { + "normal": { + "location": "any" + } + }, + "bridge_state": "auto", + "allow_lan": true, + "block_when_disconnected": false, + "auto_connect": false, + "tunnel_options": { + "openvpn": { + "mssfix": null + }, + "wireguard": { + "mtu": null + }, + "generic": { + "enable_ipv6": false + } + } +} +"#; + + const NEW_SETTINGS: &str = r#" +{ + "account_token": "1234", + "relay_settings": { + "normal": { + "location": { + "only": { + "country": "se" + } + }, + "tunnel_protocol": "any", + "wireguard_constraints": { + "port": "any" + }, + "openvpn_constraints": { + "port": { + "only": 53 + }, + "protocol": { + "only": "udp" + } + } + } + }, + "bridge_settings": { + "normal": { + "location": "any" + } + }, + "bridge_state": "auto", + "allow_lan": true, + "block_when_disconnected": false, + "auto_connect": false, + "tunnel_options": { + "openvpn": { + "mssfix": null + }, + "wireguard": { + "mtu": null + }, + "generic": { + "enable_ipv6": false + } + }, + "settings_version": 2 +} +"#; + + #[test] + fn test_migration() { + let m = super::Migration; + let old_settings = m + .read(&mut OLD_SETTINGS.as_bytes()) + .expect("Failed to deserialize old format"); + let new_settings = serde_json::from_str(&NEW_SETTINGS).unwrap(); + + assert_eq!(&m.migrate(old_settings).unwrap(), &new_settings); + } + + #[test] + #[should_panic] + fn test_deserialization_failure() { + let m = super::Migration; + m.read(&mut NEW_SETTINGS.as_bytes()) + .expect("Failed to deserialize old format"); + } +} diff --git a/mullvad-types/src/settings/mod.rs b/mullvad-types/src/settings/mod.rs index 0cc8ae34f1..c2f84cff59 100644 --- a/mullvad-types/src/settings/mod.rs +++ b/mullvad-types/src/settings/mod.rs @@ -50,7 +50,7 @@ static SETTINGS_FILE: &str = "settings.json"; /// Mullvad daemon settings. -#[derive(Debug, Clone, Deserialize, Serialize)] +#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)] #[serde(default)] pub struct Settings { account_token: Option<String>, |
