diff --git a/Cargo.lock b/Cargo.lock index 257ac22dc..3a9d53185 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" diff --git a/Cargo.toml b/Cargo.toml index 6b47e30d0..beb397555 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -362,4 +362,4 @@ twox-hash = { opt-level = 3 } uint = { opt-level = 3 } x25519-dalek = { opt-level = 3 } yamux = { opt-level = 3 } -zeroize = { opt-level = 3 } +zeroize = { opt-level = 3 } \ No newline at end of file diff --git a/pallets/network-membership/src/tests.rs b/pallets/network-membership/src/tests.rs index e5addf40e..a22be1d81 100644 --- a/pallets/network-membership/src/tests.rs +++ b/pallets/network-membership/src/tests.rs @@ -361,3 +361,28 @@ fn test_auto_expire_non_existent_membership() { assert_eq!(NetworkMembership::is_member(&AccountId::new([99u8; 32])), false); }); } + +// #[test] +// fn test_unauthorized_operation() { +// new_test_ext().execute_with(|| { +// run_to_block(1); + +// let non_member = AccountId::new([14u8; 32]); + +// assert_err!( +// NetworkMembership::nominate( +// RuntimeOrigin::signed(non_member), +// AccountId::new([13u8; 32]), +// true +// ), +// BadOrigin +// ); + +// assert_eq!(NetworkMembership::members_count(), 1); + +// assert_eq!( +// Members::::get(AccountId::new([13u8; 32])), +// None +// ); +// }); +// } diff --git a/pallets/network-score/src/tests.rs b/pallets/network-score/src/tests.rs index f7a9e738b..21dda0de3 100644 --- a/pallets/network-score/src/tests.rs +++ b/pallets/network-score/src/tests.rs @@ -915,3 +915,30 @@ fn reference_identifier_not_found_test() { >::remove(message_id_revise.clone(), creator.clone()); }); } + +// to check the unauthorized operation... + +// #[test] +// fn test_unauthorized_operation() { +// new_test_ext().execute_with(|| { +// run_to_block(1); + +// let non_member = AccountId::new([14u8; 32]); + +// assert_err!( +// NetworkMembership::nominate( +// RuntimeOrigin::signed(non_member), +// AccountId::new([13u8; 32]), +// true +// ), +// BadOrigin +// ); + +// assert_eq!(NetworkMembership::members_count(), 1); + +// assert_eq!( +// Members::::get(AccountId::new([13u8; 32])), +// None +// ); +// }); +// } diff --git a/pallets/node-authorization/src/lib.rs b/pallets/node-authorization/src/lib.rs index 6eeff230f..48adbba3b 100644 --- a/pallets/node-authorization/src/lib.rs +++ b/pallets/node-authorization/src/lib.rs @@ -489,4 +489,4 @@ impl Pallet { Ok(node) } -} +} \ No newline at end of file diff --git a/pallets/node-authorization/src/mock.rs b/pallets/node-authorization/src/mock.rs index d8800d8a9..6a6c1616b 100644 --- a/pallets/node-authorization/src/mock.rs +++ b/pallets/node-authorization/src/mock.rs @@ -130,4 +130,4 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .assimilate_storage(&mut t) .unwrap(); t.into() -} +} \ No newline at end of file diff --git a/pallets/node-authorization/src/tests.rs b/pallets/node-authorization/src/tests.rs index 24af33aef..beb5f2da1 100644 --- a/pallets/node-authorization/src/tests.rs +++ b/pallets/node-authorization/src/tests.rs @@ -454,8 +454,44 @@ fn adding_already_connected_connection_should_fail() { }); } +// Test to check whether the peerId is TooLong or not. #[test] fn test_generate_peer_id_invalid_utf8() { + // Invalid UTF-8 node ID let invalid_node_id: NodeId = vec![0xFF, 0xFE, 0xFD]; assert_err!(NodeAuthorization::generate_peer_id(&invalid_node_id), Error::::InvalidUtf8); } + +#[test] +fn test_generate_peer_id_too_long() { + // Node ID exceeding the maximum length + let long_node_id: NodeId = vec![0x01; MAX_NODE_ID_LEN + 1]; // Exceeds max length + assert_err!(NodeAuthorization::generate_peer_id(&long_node_id), Error::::PeerIdTooLong); +} + +#[test] +fn add_well_known_node_with_peer_id_too_long_should_fail() { + new_test_ext().execute_with(|| { + // Attempt to add a node with an excessively long peer ID + assert_noop!( + NodeAuthorization::add_well_known_node( + RuntimeOrigin::signed(1), + test_node(TEST_NODE_LEN), // Exceeds max length + 15 + ), + Error::::PeerIdTooLong + ); + }); +} + +#[test] +fn remove_well_known_node_with_peer_id_too_long_should_fail() { + new_test_ext().execute_with(|| { + // Attempt to remove a node with an excessively long peer ID + let long_peer_id: PeerId = vec![0x01; MAX_PEER_ID_LEN + 1]; // Exceeds max length + assert_noop!( + NodeAuthorization::remove_well_known_node(RuntimeOrigin::signed(1), long_peer_id), + Error::::PeerIdTooLong + ); + }); +} diff --git a/test-utils/service/src/lib.rs b/test-utils/service/src/lib.rs index 485a00754..470f8364f 100644 --- a/test-utils/service/src/lib.rs +++ b/test-utils/service/src/lib.rs @@ -178,7 +178,7 @@ where interval.tick().await; if full_nodes.iter().all(|(id, service, _, _)| full_predicate(*id, service)) { - break + break; } } };