Skip to content

Commit 8ea42e4

Browse files
committed
chore(coprocessor): add mask_database_url unit test
1 parent 4b3950d commit 8ea42e4

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

coprocessor/fhevm-engine/fhevm-engine-common/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ pub struct DatabaseURL(String);
122122
impl 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
}
129129
impl 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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

coprocessor/fhevm-engine/stress-test-generator/data/json/minitest_002_erc20.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"user_address": "0xa0534e99d86F081E8D3868A8C4732C8f65dfdB07",
1010
"scenario": [
1111
[
12-
0.1,
13-
5
12+
20.0,
13+
120
1414
]
1515
]
1616
}

coprocessor/fhevm-engine/stress-test-generator/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl EnvConfig {
346346
};
347347
let acl_contract_address: String = match env::var("ACL_CONTRACT_ADDRESS") {
348348
Ok(val) => val,
349-
Err(_) => "0x617E46088ffe8d0f27A123574119b9C3F3b81073".to_string(),
349+
Err(_) => "0x05fD9B5EFE0a996095f42Ed7e77c390810CF660c".to_string(),
350350
};
351351
let chain_id: i64 = match env::var("CHAIN_ID") {
352352
Ok(val) => val.parse::<i64>().unwrap(),

0 commit comments

Comments
 (0)