diff --git a/config/default.json b/config/default.json index 06b4e3d..ff55504 100644 --- a/config/default.json +++ b/config/default.json @@ -19,7 +19,9 @@ { "period": "5 minutes", "limit": 0 } ] }, - "message_id_hmac_key": "YOU MUST CHANGE ME", + "messagedata": { + "hmackey": "YOU MUST CHANGE ME" + }, "logging": "mozlog", "provider": "ses", "redis": { diff --git a/src/message_data/mod.rs b/src/message_data/mod.rs index 3a68352..6e30b18 100644 --- a/src/message_data/mod.rs +++ b/src/message_data/mod.rs @@ -28,7 +28,7 @@ impl MessageData { client: RedisClient::open( format!("redis://{}:{}/", settings.redis.host, settings.redis.port).as_str(), ).expect("redis connection error"), - hmac_key: settings.message_id_hmac_key.clone(), + hmac_key: settings.messagedata.hmackey.clone(), } } diff --git a/src/message_data/test.rs b/src/message_data/test.rs index f1c7567..f4a6f08 100644 --- a/src/message_data/test.rs +++ b/src/message_data/test.rs @@ -63,7 +63,7 @@ impl TestFixture { pub fn setup(test: &str) -> TestFixture { let settings = Settings::new().expect("config error"); let unhashed_key = format!("fxa-email-service.test.message-data.{}.{}", test, now()); - let mut hmac = Hmac::::new_varkey(settings.message_id_hmac_key.as_bytes()).unwrap(); + let mut hmac = Hmac::::new_varkey(settings.messagedata.hmackey.as_bytes()).unwrap(); hmac.input(unhashed_key.as_bytes()); let internal_key = format!("msg:{:x}", hmac.result().code()); TestFixture { diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 61f8e1f..3591d24 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -51,6 +51,11 @@ pub struct BounceLimits { pub soft: Vec, } +#[derive(Debug, Default, Deserialize, Serialize)] +pub struct MessageData { + pub hmackey: String, +} + #[derive(Debug, Default, Deserialize, Serialize)] pub struct Redis { #[serde(deserialize_with = "deserialize::host")] @@ -93,7 +98,7 @@ pub struct Settings { pub authdb: AuthDb, pub aws: Aws, pub bouncelimits: BounceLimits, - pub message_id_hmac_key: String, + pub messagedata: MessageData, pub logging: String, #[serde(deserialize_with = "deserialize::provider")] pub provider: String, @@ -136,7 +141,7 @@ impl Settings { Ok(settings) => { if let Ok(rocket_env) = env::var("ROCKET_ENV") { if rocket_env == "production" - && &settings.message_id_hmac_key == "YOU MUST CHANGE ME" + && &settings.messagedata.hmackey == "YOU MUST CHANGE ME" { panic!("Please set a valid HMAC key.") } diff --git a/src/settings/test.rs b/src/settings/test.rs index f61663c..7082dd5 100644 --- a/src/settings/test.rs +++ b/src/settings/test.rs @@ -65,6 +65,7 @@ fn env_vars_take_precedence() { "FXA_EMAIL_AWS_SQSURLS_DELIVERY", "FXA_EMAIL_AWS_SQSURLS_NOTIFICATION", "FXA_EMAIL_BOUNCELIMITS_ENABLED", + "FXA_EMAIL_MESSAGEDATA_HMACKEY", "FXA_EMAIL_PROVIDER", "FXA_EMAIL_REDIS_HOST", "FXA_EMAIL_REDIS_PORT", @@ -114,6 +115,7 @@ fn env_vars_take_precedence() { } }; let bounce_limits_enabled = !settings.bouncelimits.enabled; + let message_data_hmac_key = String::from("something else"); let provider = if settings.provider == "ses" { "sendgrid" } else { @@ -142,6 +144,10 @@ fn env_vars_take_precedence() { "FXA_EMAIL_BOUNCELIMITS_ENABLED", &bounce_limits_enabled.to_string(), ); + env::set_var( + "FXA_EMAIL_MESSAGEDATA_HMACKEY", + &message_data_hmac_key.to_string(), + ); env::set_var("FXA_EMAIL_PROVIDER", &provider); env::set_var("FXA_EMAIL_REDIS_HOST", &redis_host); env::set_var("FXA_EMAIL_REDIS_PORT", &redis_port.to_string()); @@ -154,6 +160,7 @@ fn env_vars_take_precedence() { assert_eq!(env_settings.authdb.baseuri, auth_db_base_uri); assert_eq!(env_settings.aws.region, aws_region); assert_eq!(env_settings.bouncelimits.enabled, bounce_limits_enabled); + assert_eq!(env_settings.messagedata.hmackey, message_data_hmac_key); assert_eq!(env_settings.provider, provider); assert_eq!(env_settings.redis.host, redis_host); assert_eq!(env_settings.redis.port, redis_port);