From 008f119137defd7ebaaedc85e098857fecf352a8 Mon Sep 17 00:00:00 2001 From: Phil Booth Date: Tue, 5 Jun 2018 20:45:09 +0100 Subject: [PATCH] fix(validation): relax the sendgrid API key validation regex (#55) r=@vbudhram,@vladikoff --- src/validate/mod.rs | 2 +- src/validate/test.rs | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/validate/mod.rs b/src/validate/mod.rs index 0d047a6..8fea431 100644 --- a/src/validate/mod.rs +++ b/src/validate/mod.rs @@ -21,7 +21,7 @@ lazy_static! { static ref PROVIDER_FORMAT: Regex = Regex::new("^(?:mock|sendgrid|ses|smtp)$").unwrap(); static ref SENDER_NAME_FORMAT: Regex = Regex::new("^[A-Za-z0-9-]+(?: [A-Za-z0-9-]+)*$").unwrap(); - static ref SENDGRID_API_KEY_FORMAT: Regex = Regex::new("^[A-Za-z0-9._]{69}$").unwrap(); + static ref SENDGRID_API_KEY_FORMAT: Regex = Regex::new("^[A-Za-z0-9._-]+$").unwrap(); static ref SQS_URL_FORMAT: Regex = Regex::new("^https://sqs\\.[a-z0-9-]+\\.amazonaws\\.com/[0-9]+/[A-Za-z0-9-]+$").unwrap(); } diff --git a/src/validate/test.rs b/src/validate/test.rs index d807c7f..5024c07 100644 --- a/src/validate/test.rs +++ b/src/validate/test.rs @@ -149,23 +149,17 @@ fn invalid_sender_name() { #[test] fn sendgrid_api_key() { assert!(validate::sendgrid_api_key( - "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._12345" + "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-" )); } #[test] fn invalid_sendgrid_api_key() { assert!(!validate::sendgrid_api_key( - "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._12345 " + "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._- " )); assert!(!validate::sendgrid_api_key( - " 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._12345" - )); - assert!(!validate::sendgrid_api_key( - "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._1234" - )); - assert!(!validate::sendgrid_api_key( - "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._123456" + " 1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz._-" )); }