From 7dfce71ac961dc7a8514ad911d3ac6820c2cd269 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 19 Nov 2023 16:39:24 +0000 Subject: [PATCH] fix: lowercase `addr` when it is set Prevent users from creating new accounts with uppercase letters in the address. --- src/config.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/config.rs b/src/config.rs index 53fed8338..1c4d0b0ba 100644 --- a/src/config.rs +++ b/src/config.rs @@ -513,6 +513,11 @@ impl Context { ); self.sql.set_raw_config(key.as_ref(), value).await?; } + Config::Addr => { + self.sql + .set_raw_config(key.as_ref(), value.map(|s| s.to_lowercase()).as_deref()) + .await?; + } _ => { self.sql.set_raw_config(key.as_ref(), value).await?; } @@ -662,6 +667,21 @@ mod tests { ); } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_set_config_addr() { + let t = TestContext::new().await; + + // Test that uppercase address get lowercased. + assert!(t + .set_config(Config::Addr, Some("Foobar@eXample.oRg")) + .await + .is_ok()); + assert_eq!( + t.get_config(Config::Addr).await.unwrap().unwrap(), + "foobar@example.org" + ); + } + /// Tests that "bot" config can only be set to "0" or "1". #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_set_config_bot() {