@@ -665,12 +665,12 @@ impl OidcLoginState {
665
665
if query. is_empty ( ) {
666
666
safe_path. to_string ( )
667
667
} else {
668
- format ! ( "{}?{}" , safe_path , query )
668
+ format ! ( "{safe_path }?{query}" )
669
669
}
670
670
}
671
671
}
672
672
673
- fn create_state_cookie ( request : & ServiceRequest , auth_url : AuthUrlParams ) -> Cookie {
673
+ fn create_state_cookie ( request : & ServiceRequest , auth_url : AuthUrlParams ) -> Cookie < ' _ > {
674
674
let state = OidcLoginState :: new ( request, auth_url) ;
675
675
let state_json = serde_json:: to_string ( & state) . unwrap ( ) ;
676
676
Cookie :: build ( SQLPAGE_STATE_COOKIE_NAME , state_json)
@@ -695,31 +695,27 @@ fn validate_redirect_url(url: &str) -> String {
695
695
if url. starts_with ( '/' ) && !url. starts_with ( "//" ) {
696
696
url. to_string ( )
697
697
} 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" ) ;
702
699
"/" . to_string ( )
703
700
}
704
701
}
705
702
706
703
#[ cfg( test) ]
707
704
mod tests {
708
- use super :: * ;
705
+ use super :: { validate_redirect_url , AuthUrlParams , OidcLoginState } ;
709
706
use actix_web:: { http:: Method , test} ;
707
+ use openidconnect:: { CsrfToken , Nonce } ;
710
708
711
709
#[ 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 ( ) ;
716
712
717
713
let result = OidcLoginState :: build_safe_redirect_url ( & req) ;
718
714
assert_eq ! ( result, "/page.sql?param=1¶m2=value" ) ;
719
715
}
720
716
721
717
#[ test]
722
- fn test_build_safe_redirect_url_without_query_params ( ) {
718
+ async fn test_build_safe_redirect_url_without_query_params ( ) {
723
719
let req = test:: TestRequest :: with_uri ( "/page.sql" )
724
720
. method ( Method :: GET )
725
721
. to_srv_request ( ) ;
@@ -729,7 +725,7 @@ mod tests {
729
725
}
730
726
731
727
#[ test]
732
- fn test_build_safe_redirect_url_with_special_characters ( ) {
728
+ async fn test_build_safe_redirect_url_with_special_characters ( ) {
733
729
let req = test:: TestRequest :: with_uri ( "/page.sql?param=hello%20world&special=%26%3D" )
734
730
. method ( Method :: GET )
735
731
. to_srv_request ( ) ;
@@ -739,19 +735,19 @@ mod tests {
739
735
}
740
736
741
737
#[ 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 "/"
744
740
let req = test:: TestRequest :: with_uri ( "page.sql" )
745
741
. method ( Method :: GET )
746
742
. to_srv_request ( ) ;
747
743
748
744
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, "/" ) ;
751
747
}
752
748
753
749
#[ test]
754
- fn test_validate_redirect_url_valid_paths ( ) {
750
+ async fn test_validate_redirect_url_valid_paths ( ) {
755
751
assert_eq ! ( validate_redirect_url( "/page.sql" ) , "/page.sql" ) ;
756
752
assert_eq ! (
757
753
validate_redirect_url( "/page.sql?param=1" ) ,
@@ -762,7 +758,7 @@ mod tests {
762
758
}
763
759
764
760
#[ test]
765
- fn test_validate_redirect_url_invalid_paths ( ) {
761
+ async fn test_validate_redirect_url_invalid_paths ( ) {
766
762
// Protocol-relative URLs are dangerous
767
763
assert_eq ! ( validate_redirect_url( "//evil.com/path" ) , "/" ) ;
768
764
@@ -775,7 +771,7 @@ mod tests {
775
771
}
776
772
777
773
#[ test]
778
- fn test_oidc_login_state_preserves_query_parameters ( ) {
774
+ async fn test_oidc_login_state_preserves_query_parameters ( ) {
779
775
let req = test:: TestRequest :: with_uri ( "/dashboard.sql?user_id=123&filter=active" )
780
776
. method ( Method :: GET )
781
777
. to_srv_request ( ) ;
0 commit comments