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;
5
5
use diesel:: prelude:: * ;
6
6
use diesel_async:: async_connection_wrapper:: AsyncConnectionWrapper ;
7
7
use http:: request:: Parts ;
8
+ use lettre:: Address ;
8
9
use secrecy:: { ExposeSecret , SecretString } ;
9
10
use serde_json:: Value ;
10
11
use std:: collections:: HashMap ;
@@ -152,6 +153,10 @@ pub async fn update_user(
152
153
return Err ( bad_request ( "empty email rejected" ) ) ;
153
154
}
154
155
156
+ user_email
157
+ . parse :: < Address > ( )
158
+ . map_err ( |_| bad_request ( "invalid email address" ) ) ?;
159
+
155
160
conn. transaction :: < _ , BoxedAppError , _ > ( |conn| {
156
161
let new_email = NewEmail {
157
162
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() {
96
96
assert_eq ! ( response. status( ) , StatusCode :: FORBIDDEN ) ;
97
97
assert_snapshot ! ( response. text( ) , @r###"{"errors":[{"detail":"this action requires authentication"}]}"### ) ;
98
98
}
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