File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed
controllers/trustpub/tokens/revoke Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,15 @@ impl AuthHeader {
2525 } ;
2626
2727 let auth_header = auth_header. to_str ( ) . map_err ( |_| {
28- let message = "Invalid authorization header" ;
28+ let message = "Invalid `Authorization` header: Found unexpected non-ASCII characters " ;
2929 custom ( StatusCode :: UNAUTHORIZED , message)
3030 } ) ?;
3131
3232 let ( scheme, token) = auth_header. split_once ( ' ' ) . unwrap_or ( ( "" , auth_header) ) ;
3333 if !( scheme. eq_ignore_ascii_case ( "Bearer" ) || scheme. is_empty ( ) ) {
34- let message = "Invalid authorization header" ;
34+ let message = format ! (
35+ "Invalid `Authorization` header: Found unexpected authentication scheme `{scheme}`"
36+ ) ;
3537 return Err ( custom ( StatusCode :: UNAUTHORIZED , message) ) ;
3638 }
3739
@@ -42,7 +44,7 @@ impl AuthHeader {
4244 pub async fn from_request_parts ( parts : & Parts ) -> Result < Self , BoxedAppError > {
4345 let auth = Self :: optional_from_request_parts ( parts) . await ?;
4446 auth. ok_or_else ( || {
45- let message = "Missing authorization header" ;
47+ let message = "Missing `Authorization` header" ;
4648 custom ( StatusCode :: UNAUTHORIZED , message)
4749 } )
4850 }
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ mod tests;
2525pub async fn revoke_trustpub_token ( app : AppState , auth : AuthHeader ) -> AppResult < StatusCode > {
2626 let token = auth. token ( ) . expose_secret ( ) ;
2727 let Ok ( token) = AccessToken :: from_byte_str ( token. as_bytes ( ) ) else {
28- let message = "Invalid authorization header" ;
28+ let message = "Invalid `Authorization` header: Failed to parse token " ;
2929 return Err ( custom ( StatusCode :: UNAUTHORIZED , message) ) ;
3030 } ;
3131
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ async fn test_missing_authorization_header() -> anyhow::Result<()> {
8888
8989 let response = client. delete :: < ( ) > ( URL ) . await ;
9090 assert_snapshot ! ( response. status( ) , @"401 Unauthorized" ) ;
91- assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Missing authorization header"}]}"# ) ;
91+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Missing `Authorization` header"}]}"# ) ;
9292
9393 Ok ( ( ) )
9494}
@@ -103,7 +103,7 @@ async fn test_invalid_authorization_header_format() -> anyhow::Result<()> {
103103
104104 let response = token_client. delete :: < ( ) > ( URL ) . await ;
105105 assert_snapshot ! ( response. status( ) , @"401 Unauthorized" ) ;
106- assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid authorization header"}]}"# ) ;
106+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid `Authorization` header: Failed to parse token "}]}"# ) ;
107107
108108 Ok ( ( ) )
109109}
@@ -118,7 +118,7 @@ async fn test_invalid_token_format() -> anyhow::Result<()> {
118118
119119 let response = token_client. delete :: < ( ) > ( URL ) . await ;
120120 assert_snapshot ! ( response. status( ) , @"401 Unauthorized" ) ;
121- assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid authorization header"}]}"# ) ;
121+ assert_snapshot ! ( response. text( ) , @r#"{"errors":[{"detail":"Invalid `Authorization` header: Failed to parse token "}]}"# ) ;
122122
123123 Ok ( ( ) )
124124}
You can’t perform that action at this time.
0 commit comments