Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node-Authorization : Test for PeerIdTooLong #499

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pallets/node-authorization/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use super::*;
use crate as pallet_node_authorization;
use crate::{Config, NodeId};
use frame_support::ensure;

use frame_support::{
construct_runtime, derive_impl, ord_parameter_types,
Expand Down Expand Up @@ -131,3 +132,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
.unwrap();
t.into()
}

pub fn test_peer_id_length(testing: PeerId) -> Result<(), Error<Test>> {
ensure!(testing.0.len() <= 128 as usize, Error::<Test>::PeerIdTooLong);
Ok(())
}
12 changes: 12 additions & 0 deletions pallets/node-authorization/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,15 @@ fn test_generate_peer_id_invalid_utf8() {
let invalid_node_id: NodeId = vec![0xFF, 0xFE, 0xFD];
assert_err!(NodeAuthorization::generate_peer_id(&invalid_node_id), Error::<Test>::InvalidUtf8);
}

zeel991 marked this conversation as resolved.
Show resolved Hide resolved
#[test]
fn peer_id_too_long_test() {
new_test_ext().execute_with(|| {
let node_id: &str = &"nodeid".repeat(32);

let node_identity = test_node(&node_id);
let testing = NodeAuthorization::generate_peer_id(&node_identity).unwrap();

assert_eq!(test_peer_id_length(testing), Err(Error::<Test>::PeerIdTooLong));
})
}
Loading