Skip to content
Snippets Groups Projects
Verified Commit eb9024f8 authored by Pascal Engélibert's avatar Pascal Engélibert :bicyclist:
Browse files

fix(common-runtime): stricter idty name validation

parent 7f396b42
No related branches found
No related tags found
No related merge requests found
...@@ -83,7 +83,20 @@ impl<Runtime: pallet_babe::Config> frame_support::pallet_prelude::Get<u64> ...@@ -83,7 +83,20 @@ impl<Runtime: pallet_babe::Config> frame_support::pallet_prelude::Get<u64>
pub struct IdtyNameValidatorImpl; pub struct IdtyNameValidatorImpl;
impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorImpl { impl pallet_identity::traits::IdtyNameValidator for IdtyNameValidatorImpl {
// Bound length; forbid trailing or double spaces; accept only ascii alphanumeric or punctuation or space
fn validate(idty_name: &pallet_identity::IdtyName) -> bool { fn validate(idty_name: &pallet_identity::IdtyName) -> bool {
idty_name.0.len() >= 3 && idty_name.0.len() <= 64 idty_name.0.len() >= 3
&& idty_name.0.len() <= 64
&& idty_name.0[0] != 32
&& idty_name.0[idty_name.0.len() - 1] != 32
&& idty_name
.0
.iter()
.all(|c| c.is_ascii_alphanumeric() || c.is_ascii_punctuation() || *c == 32)
&& idty_name
.0
.iter()
.zip(idty_name.0.iter().skip(1))
.all(|(c1, c2)| *c1 != 32 || *c2 != 32)
} }
} }
...@@ -342,5 +342,14 @@ fn test_create_new_idty() { ...@@ -342,5 +342,14 @@ fn test_create_new_idty() {
Account::pending_random_id_assignments(0), Account::pending_random_id_assignments(0),
Some(AccountKeyring::Eve.to_account_id()) Some(AccountKeyring::Eve.to_account_id())
); );
// Double space is forbidden in identity name
assert_err!(
Identity::confirm_identity(
frame_system::RawOrigin::Signed(AccountKeyring::Eve.to_account_id()).into(),
pallet_identity::IdtyName::from("invalid name"),
),
pallet_identity::Error::<Runtime>::IdtyNameInvalid
);
}); });
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment