From 62b161cb34c5827269bca92f8ce1eb9315ea6e1f Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Fri, 15 Nov 2024 14:34:33 +0100 Subject: [PATCH 1/3] Delete bootstrap_whitelist.json --- massa-node/base_config/bootstrap_whitelist.json | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 massa-node/base_config/bootstrap_whitelist.json diff --git a/massa-node/base_config/bootstrap_whitelist.json b/massa-node/base_config/bootstrap_whitelist.json deleted file mode 100644 index 5793b574453..00000000000 --- a/massa-node/base_config/bootstrap_whitelist.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - "149.202.86.103", - "149.202.89.125", - "158.69.120.215", - "158.69.23.120", - "198.27.74.5", - "51.75.60.228", - "2001:41d0:1004:67::", - "2001:41d0:a:7f7d::", - "2001:41d0:602:21e4::" -] \ No newline at end of file From c64651ee8f5399ec8186f70103f10cc3370c2e47 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Fri, 15 Nov 2024 15:41:59 +0100 Subject: [PATCH 2/3] Add bootstrap_whitelist file for tests --- massa-bootstrap/src/tests/scenarios.rs | 2 +- .../src/tests/test_bootstrap_whitelist.json | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 massa-bootstrap/src/tests/test_bootstrap_whitelist.json diff --git a/massa-bootstrap/src/tests/scenarios.rs b/massa-bootstrap/src/tests/scenarios.rs index 226cf32fc1d..5968e537d1f 100644 --- a/massa-bootstrap/src/tests/scenarios.rs +++ b/massa-bootstrap/src/tests/scenarios.rs @@ -20,7 +20,7 @@ fn test_bootstrap_not_whitelisted() { let server_keypair = KeyPair::generate(0).unwrap(); let bootstrap_server_config = BootstrapConfig { bootstrap_whitelist_path: PathBuf::from( - "../massa-node/base_config/bootstrap_whitelist.json", + "../massa-bootstrap/src/tests/test_bootstrap_whitelist.json", ), ..Default::default() }; diff --git a/massa-bootstrap/src/tests/test_bootstrap_whitelist.json b/massa-bootstrap/src/tests/test_bootstrap_whitelist.json new file mode 100644 index 00000000000..5793b574453 --- /dev/null +++ b/massa-bootstrap/src/tests/test_bootstrap_whitelist.json @@ -0,0 +1,11 @@ +[ + "149.202.86.103", + "149.202.89.125", + "158.69.120.215", + "158.69.23.120", + "198.27.74.5", + "51.75.60.228", + "2001:41d0:1004:67::", + "2001:41d0:a:7f7d::", + "2001:41d0:602:21e4::" +] \ No newline at end of file From 3a06caa69edf9a3f21a07195b8f27f26c06753dc Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Mon, 18 Nov 2024 12:50:48 +0100 Subject: [PATCH 3/3] Use TempFile instead of hardcoded whitelist test file --- massa-bootstrap/src/tests/scenarios.rs | 36 ++++++++++++++++--- .../src/tests/test_bootstrap_whitelist.json | 11 ------ 2 files changed, 32 insertions(+), 15 deletions(-) delete mode 100644 massa-bootstrap/src/tests/test_bootstrap_whitelist.json diff --git a/massa-bootstrap/src/tests/scenarios.rs b/massa-bootstrap/src/tests/scenarios.rs index 5968e537d1f..8a5efef7901 100644 --- a/massa-bootstrap/src/tests/scenarios.rs +++ b/massa-bootstrap/src/tests/scenarios.rs @@ -11,17 +11,45 @@ use massa_models::{address::Address, node::NodeId}; use massa_signature::KeyPair; use massa_test_framework::TestUniverse; use serial_test::serial; -use std::path::PathBuf; +use std::collections::HashSet; +use std::fs::File; +use std::net::IpAddr; +use std::str::FromStr; +use tempfile::NamedTempFile; #[test] #[serial] fn test_bootstrap_not_whitelisted() { let port = 8069; let server_keypair = KeyPair::generate(0).unwrap(); + + let bootstrap_whitelist_file = NamedTempFile::new().expect("unable to create temp file"); + + let ips_str = vec![ + "149.202.86.103", + "149.202.89.125", + "158.69.120.215", + "158.69.23.120", + "198.27.74.5", + "51.75.60.228", + "2001:41d0:1004:67::", + "2001:41d0:a:7f7d::", + "2001:41d0:602:21e4::", + ]; + + let mut bootstrap_whitelist = HashSet::new(); + for ip_str in ips_str { + bootstrap_whitelist.insert(IpAddr::from_str(ip_str).unwrap()); + } + + serde_json::to_writer_pretty::<&File, HashSet>( + bootstrap_whitelist_file.as_file(), + &bootstrap_whitelist, + ) + .expect("unable to write bootstrap whitelist temp file"); + let bootstrap_server_config = BootstrapConfig { - bootstrap_whitelist_path: PathBuf::from( - "../massa-bootstrap/src/tests/test_bootstrap_whitelist.json", - ), + bootstrap_whitelist_path: bootstrap_whitelist_file.path().to_path_buf(), ..Default::default() }; let server_universe = BootstrapServerTestUniverseBuilder::new() diff --git a/massa-bootstrap/src/tests/test_bootstrap_whitelist.json b/massa-bootstrap/src/tests/test_bootstrap_whitelist.json deleted file mode 100644 index 5793b574453..00000000000 --- a/massa-bootstrap/src/tests/test_bootstrap_whitelist.json +++ /dev/null @@ -1,11 +0,0 @@ -[ - "149.202.86.103", - "149.202.89.125", - "158.69.120.215", - "158.69.23.120", - "198.27.74.5", - "51.75.60.228", - "2001:41d0:1004:67::", - "2001:41d0:a:7f7d::", - "2001:41d0:602:21e4::" -] \ No newline at end of file