@@ -665,12 +665,12 @@ impl OidcLoginState {
665665 if query. is_empty ( ) {
666666 safe_path. to_string ( )
667667 } else {
668- format ! ( "{}?{}" , safe_path , query )
668+ format ! ( "{safe_path }?{query}" )
669669 }
670670 }
671671}
672672
673- fn create_state_cookie ( request : & ServiceRequest , auth_url : AuthUrlParams ) -> Cookie {
673+ fn create_state_cookie ( request : & ServiceRequest , auth_url : AuthUrlParams ) -> Cookie < ' _ > {
674674 let state = OidcLoginState :: new ( request, auth_url) ;
675675 let state_json = serde_json:: to_string ( & state) . unwrap ( ) ;
676676 Cookie :: build ( SQLPAGE_STATE_COOKIE_NAME , state_json)
@@ -695,31 +695,27 @@ fn validate_redirect_url(url: &str) -> String {
695695 if url. starts_with ( '/' ) && !url. starts_with ( "//" ) {
696696 url. to_string ( )
697697 } else {
698- log:: warn!(
699- "Invalid redirect URL '{}', redirecting to root instead" ,
700- url
701- ) ;
698+ log:: warn!( "Invalid redirect URL '{url}', redirecting to root instead" ) ;
702699 "/" . to_string ( )
703700 }
704701}
705702
706703#[ cfg( test) ]
707704mod tests {
708- use super :: * ;
705+ use super :: { validate_redirect_url , AuthUrlParams , OidcLoginState } ;
709706 use actix_web:: { http:: Method , test} ;
707+ use openidconnect:: { CsrfToken , Nonce } ;
710708
711709 #[ test]
712- fn test_build_safe_redirect_url_with_query_params ( ) {
713- let req = test:: TestRequest :: with_uri ( "/page.sql?param=1¶m2=value" )
714- . method ( Method :: GET )
715- . to_srv_request ( ) ;
710+ async fn test_build_safe_redirect_url_with_query_params ( ) {
711+ let req = test:: TestRequest :: with_uri ( "/page.sql?param=1¶m2=value" ) . to_srv_request ( ) ;
716712
717713 let result = OidcLoginState :: build_safe_redirect_url ( & req) ;
718714 assert_eq ! ( result, "/page.sql?param=1¶m2=value" ) ;
719715 }
720716
721717 #[ test]
722- fn test_build_safe_redirect_url_without_query_params ( ) {
718+ async fn test_build_safe_redirect_url_without_query_params ( ) {
723719 let req = test:: TestRequest :: with_uri ( "/page.sql" )
724720 . method ( Method :: GET )
725721 . to_srv_request ( ) ;
@@ -729,7 +725,7 @@ mod tests {
729725 }
730726
731727 #[ test]
732- fn test_build_safe_redirect_url_with_special_characters ( ) {
728+ async fn test_build_safe_redirect_url_with_special_characters ( ) {
733729 let req = test:: TestRequest :: with_uri ( "/page.sql?param=hello%20world&special=%26%3D" )
734730 . method ( Method :: GET )
735731 . to_srv_request ( ) ;
@@ -739,19 +735,19 @@ mod tests {
739735 }
740736
741737 #[ test]
742- fn test_build_safe_redirect_url_handles_non_absolute_paths ( ) {
743- // TestRequest with relative path not starting with '/'
738+ async fn test_build_safe_redirect_url_handles_root_path ( ) {
739+ // TestRequest with invalid relative path defaults to "/"
744740 let req = test:: TestRequest :: with_uri ( "page.sql" )
745741 . method ( Method :: GET )
746742 . to_srv_request ( ) ;
747743
748744 let result = OidcLoginState :: build_safe_redirect_url ( & req) ;
749- // Should work fine since TestRequest normalizes to absolute path
750- assert_eq ! ( result, "/page.sql " ) ;
745+ // TestRequest normalizes invalid URI to root path
746+ assert_eq ! ( result, "/" ) ;
751747 }
752748
753749 #[ test]
754- fn test_validate_redirect_url_valid_paths ( ) {
750+ async fn test_validate_redirect_url_valid_paths ( ) {
755751 assert_eq ! ( validate_redirect_url( "/page.sql" ) , "/page.sql" ) ;
756752 assert_eq ! (
757753 validate_redirect_url( "/page.sql?param=1" ) ,
@@ -762,7 +758,7 @@ mod tests {
762758 }
763759
764760 #[ test]
765- fn test_validate_redirect_url_invalid_paths ( ) {
761+ async fn test_validate_redirect_url_invalid_paths ( ) {
766762 // Protocol-relative URLs are dangerous
767763 assert_eq ! ( validate_redirect_url( "//evil.com/path" ) , "/" ) ;
768764
@@ -775,7 +771,7 @@ mod tests {
775771 }
776772
777773 #[ test]
778- fn test_oidc_login_state_preserves_query_parameters ( ) {
774+ async fn test_oidc_login_state_preserves_query_parameters ( ) {
779775 let req = test:: TestRequest :: with_uri ( "/dashboard.sql?user_id=123&filter=active" )
780776 . method ( Method :: GET )
781777 . to_srv_request ( ) ;
0 commit comments