@@ -1006,30 +1006,36 @@ mod tests {
1006
1006
async fn test_auth ( ) {
1007
1007
test_all_clients ( |mut client| async move {
1008
1008
// no handshake
1009
- assert ! ( client
1010
- . prepare( "select 1;" . to_string( ) , None )
1011
- . await
1012
- . unwrap_err( )
1013
- . to_string( )
1014
- . contains( "No authorization header" ) ) ;
1009
+ assert_contains (
1010
+ client
1011
+ . prepare ( "select 1;" . to_string ( ) , None )
1012
+ . await
1013
+ . unwrap_err ( )
1014
+ . to_string ( ) ,
1015
+ "No authorization header" ,
1016
+ ) ;
1015
1017
1016
1018
// Invalid credentials
1017
- assert ! ( client
1018
- . handshake( "admin" , "password2" )
1019
- . await
1020
- . unwrap_err( )
1021
- . to_string( )
1022
- . contains( "Invalid credentials" ) ) ;
1019
+ assert_contains (
1020
+ client
1021
+ . handshake ( "admin" , "password2" )
1022
+ . await
1023
+ . unwrap_err ( )
1024
+ . to_string ( ) ,
1025
+ "Invalid credentials" ,
1026
+ ) ;
1023
1027
1024
1028
// Invalid Tokens
1025
1029
client. handshake ( "admin" , "password" ) . await . unwrap ( ) ;
1026
1030
client. set_token ( "wrong token" . to_string ( ) ) ;
1027
- assert ! ( client
1028
- . prepare( "select 1;" . to_string( ) , None )
1029
- . await
1030
- . unwrap_err( )
1031
- . to_string( )
1032
- . contains( "invalid token" ) ) ;
1031
+ assert_contains (
1032
+ client
1033
+ . prepare ( "select 1;" . to_string ( ) , None )
1034
+ . await
1035
+ . unwrap_err ( )
1036
+ . to_string ( ) ,
1037
+ "invalid token" ,
1038
+ ) ;
1033
1039
1034
1040
client. clear_token ( ) ;
1035
1041
@@ -1039,4 +1045,15 @@ mod tests {
1039
1045
} )
1040
1046
. await
1041
1047
}
1048
+
1049
+ fn assert_contains ( actual : impl AsRef < str > , searched_for : impl AsRef < str > ) {
1050
+ let actual = actual. as_ref ( ) ;
1051
+ let searched_for = searched_for. as_ref ( ) ;
1052
+ assert ! (
1053
+ actual. contains( searched_for) ,
1054
+ "Expected '{}' to contain '{}'" ,
1055
+ actual,
1056
+ searched_for
1057
+ ) ;
1058
+ }
1042
1059
}
0 commit comments