Skip to content

Commit

Permalink
Valset: validate metadata website to start with http:// or https://
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb committed Feb 9, 2022
1 parent 3543caf commit 6f6af3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions contracts/tgrade-valset/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub enum ContractError {
min: usize,
max: usize,
},

#[error("Invalid metadata - website needs to start with http:// or https://")]
InvalidMetadataWebsitePrefix {},
}

impl From<Ed25519PubkeyConversionError> for ContractError {
Expand Down
13 changes: 11 additions & 2 deletions contracts/tgrade-valset/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ impl ValidatorMetadata {
min: MIN_METADATA_SIZE,
max: MAX_METADATA_SIZE,
});
} else if !website.starts_with("https://") && !website.starts_with("http://") {
return Err(ContractError::InvalidMetadataWebsitePrefix {});
}
}
if let Some(security_contract) = &self.security_contact {
Expand Down Expand Up @@ -595,7 +597,7 @@ mod test {
);

let meta = ValidatorMetadata {
website: Some("website".to_owned()),
website: Some("https://website".to_owned()),
..meta
};
let resp = meta.validate().unwrap_err();
Expand Down Expand Up @@ -654,7 +656,7 @@ mod test {
);

let meta = ValidatorMetadata {
website: Some("website".to_owned()),
website: Some("http://website".to_owned()),
..meta
};
let resp = meta.validate().unwrap_err();
Expand All @@ -680,5 +682,12 @@ mod test {
},
resp
);

let meta = ValidatorMetadata {
website: Some("website".to_owned()),
..meta
};
let resp = meta.validate().unwrap_err();
assert_eq!(ContractError::InvalidMetadataWebsitePrefix {}, resp);
}
}

0 comments on commit 6f6af3e

Please sign in to comment.