Fixed tests and serialization constants

This commit is contained in:
Dennis Schwerdel 2017-07-22 16:42:32 +02:00
parent 0e13277911
commit 00b4641056
4 changed files with 17 additions and 4 deletions

View File

@ -121,7 +121,10 @@ extern {
#[derive(Serialize, Deserialize, Debug, PartialEq)] #[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum CryptoMethod { pub enum CryptoMethod {
ChaCha20, AES256 #[serde(rename = "chacha20")]
ChaCha20,
#[serde(rename = "aes256")]
AES256
} }
pub enum Crypto { pub enum Crypto {

View File

@ -19,8 +19,10 @@ extern {
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub enum Type { pub enum Type {
/// Tun interface: This interface transports IP packets. /// Tun interface: This interface transports IP packets.
#[serde(rename = "tun")]
Tun, Tun,
/// Tap interface: This insterface transports Ethernet frames. /// Tap interface: This insterface transports Ethernet frames.
#[serde(rename = "tap")]
Tap Tap
} }

View File

@ -7,6 +7,8 @@ use std::str::FromStr;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use serde_yaml;
use super::MAGIC; use super::MAGIC;
use super::ethernet::{Frame, SwitchTable}; use super::ethernet::{Frame, SwitchTable};
use super::ip::{RoutingTable, Packet}; use super::ip::{RoutingTable, Packet};
@ -15,7 +17,6 @@ use super::types::{Protocol, Address, Range, Table, Mode};
use super::udpmessage::{Message, decode, encode}; use super::udpmessage::{Message, decode, encode};
use super::crypto::{Crypto, CryptoMethod}; use super::crypto::{Crypto, CryptoMethod};
use super::config::{Config, ConfigFile}; use super::config::{Config, ConfigFile};
use super::configfile;
use super::Args; use super::Args;
@ -464,7 +465,7 @@ user: nobody
group: nogroup group: nogroup
pid_file: /run/vpncloud.run pid_file: /run/vpncloud.run
"; ";
assert_eq!(configfile::parse_str::<ConfigFile>(config_file).unwrap(), ConfigFile{ assert_eq!(serde_yaml::from_str::<ConfigFile>(config_file).unwrap(), ConfigFile{
device_type: Some(Type::Tun), device_type: Some(Type::Tun),
device_name: Some("vpncloud%d".to_string()), device_name: Some("vpncloud%d".to_string()),
ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()), ifup: Some("ifconfig $IFNAME 10.0.1.1/16 mtu 1400 up".to_string()),

View File

@ -187,7 +187,14 @@ impl fmt::Debug for Range {
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub enum Mode { pub enum Mode {
Normal, Hub, Switch, Router #[serde(rename = "normal")]
Normal,
#[serde(rename = "hub")]
Hub,
#[serde(rename = "switch")]
Switch,
#[serde(rename = "router")]
Router
} }
impl fmt::Display for Mode { impl fmt::Display for Mode {
fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {