File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use axum::Json;
55use diesel:: prelude:: * ;
66use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
77use http:: request:: Parts ;
8+ use lettre:: Address ;
89use secrecy:: { ExposeSecret , SecretString } ;
910use serde_json:: Value ;
1011use std:: collections:: HashMap ;
@@ -152,6 +153,10 @@ pub async fn update_user(
152153 return Err ( bad_request ( "empty email rejected" ) ) ;
153154 }
154155
156+ user_email
157+ . parse :: < Address > ( )
158+ . map_err ( |_| bad_request ( "invalid email address" ) ) ?;
159+
155160 conn. transaction :: < _ , BoxedAppError , _ > ( |conn| {
156161 let new_email = NewEmail {
157162 user_id : user. id ,
Original file line number Diff line number Diff line change @@ -96,3 +96,13 @@ async fn test_other_users_cannot_change_my_email() {
9696 assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
9797 assert_snapshot ! ( response. text( ) , @r###"{"errors":[{"detail":"this action requires authentication"}]}"### ) ;
9898}
99+
100+ #[ tokio:: test( flavor = "multi_thread" ) ]
101+ async fn test_invalid_email_address ( ) {
102+ let ( _app, _, user) = TestApp :: init ( ) . with_user ( ) ;
103+ let model = user. as_model ( ) ;
104+
105+ let response = user. update_email_more_control ( model. id , Some ( "foo" ) ) . await ;
106+ assert_eq ! ( response. status( ) , StatusCode :: BAD_REQUEST ) ;
107+ assert_snapshot ! ( response. text( ) , @r###"{"errors":[{"detail":"invalid email address"}]}"### ) ;
108+ }
You can’t perform that action at this time.
0 commit comments