File tree Expand file tree Collapse file tree 2 files changed +36
-3
lines changed
coprocessor/fhevm-engine/fhevm-engine-common Expand file tree Collapse file tree 2 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -122,14 +122,14 @@ pub struct DatabaseURL(String);
122122impl From < & str > for DatabaseURL {
123123 fn from ( s : & str ) -> Self {
124124 let url: Self = Self ( s. to_owned ( ) ) ;
125- url. parse ( ) . expect ( "DatabaseURL is valid" ) ;
125+ url. parse ( ) . expect ( "DatabaseURL should be valid" ) ;
126126 url
127127 }
128128}
129129impl From < String > for DatabaseURL {
130130 fn from ( s : String ) -> Self {
131131 let url: Self = Self ( s) ;
132- url. parse ( ) . expect ( "DatabaseURL is valid" ) ;
132+ url. parse ( ) . expect ( "DatabaseURL should be valid" ) ;
133133 url
134134 }
135135}
@@ -160,7 +160,7 @@ impl DatabaseURL {
160160 }
161161 }
162162 let url: Self = Self ( url) ;
163- let _ = url. parse ( ) . expect ( "DatabaseURL is valid" ) ;
163+ let _ = url. parse ( ) . expect ( "DatabaseURL should be valid" ) ;
164164 url
165165 }
166166
Original file line number Diff line number Diff line change 1+ use fhevm_engine_common:: utils:: DatabaseURL ;
2+
3+ #[ tokio:: test]
4+ async fn mask_database_url ( ) {
5+ let db_url: DatabaseURL = "postgres://postgres:mypassword@localhost:5432/coprocessor" . into ( ) ;
6+
7+ let debug_fmt = format ! ( "{:?}" , db_url) ;
8+ assert ! ( !debug_fmt. contains( "mypassword" ) ) ;
9+
10+ let display_fmt = format ! ( "{}" , db_url) ;
11+ assert ! ( !display_fmt. contains( "mypassword" ) ) ;
12+ println ! ( "DatabaseURL: {}" , db_url) ;
13+
14+ let db_url: DatabaseURL = DatabaseURL :: new_with_app_name (
15+ "postgres://user:secret@dbhost:5432/mydb?sslmode=require" ,
16+ "tfhe-worker" ,
17+ ) ;
18+
19+ assert_eq ! (
20+ db_url. as_str( ) ,
21+ "postgres://user:secret@dbhost:5432/mydb?sslmode=require&application_name=tfhe-worker"
22+ ) ;
23+
24+ let db_url: DatabaseURL =
25+ DatabaseURL :: new_with_app_name ( "postgres://user:secret@dbhost:5432/mydb" , "tfhe-worker" ) ;
26+
27+ assert_eq ! (
28+ db_url. as_str( ) ,
29+ "postgres://user:secret@dbhost:5432/mydb?application_name=tfhe-worker"
30+ ) ;
31+
32+ println ! ( "DatabaseURL: {}" , db_url) ;
33+ }
You can’t perform that action at this time.
0 commit comments