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

Path and Identifier validation and improvements #22

Merged
merged 27 commits into from
Dec 9, 2021
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f5678a0
First pass at using validate_identifier in store.rs
seanchen1991 Oct 8, 2021
dac68ff
Call `validate_identifier` in `Identifier::is_valid`
seanchen1991 Oct 12, 2021
1df1bc0
Remove unnecessary `TraceError` modifier
seanchen1991 Oct 12, 2021
cbdb015
Merge branch 'seanchen1991-restructure'
seanchen1991 Oct 13, 2021
ee4d113
Add some simple property tests
seanchen1991 Oct 13, 2021
b1673de
Add some more proptests
seanchen1991 Oct 13, 2021
b0b4c50
Remove debug print statement
seanchen1991 Oct 13, 2021
4efd7b8
Merge branch 'main' of github.com:informalsystems/basecoin-rs
seanchen1991 Oct 14, 2021
cd228d2
Ensure that generated chars are ASCII
seanchen1991 Oct 14, 2021
8e4dec3
Merge branch 'main' of github.com:informalsystems/basecoin-rs
seanchen1991 Nov 9, 2021
9a9c434
Merge branch 'main' of github.com:informalsystems/basecoin-rs
seanchen1991 Nov 22, 2021
4a8a29b
First pass at using validate_identifier in store.rs
seanchen1991 Oct 8, 2021
02c3029
Call `validate_identifier` in `Identifier::is_valid`
seanchen1991 Oct 12, 2021
374e404
Remove unnecessary `TraceError` modifier
seanchen1991 Oct 12, 2021
6b8ff6b
Add some simple property tests
seanchen1991 Oct 13, 2021
734d1ea
Fix conflicts while rebasing
seanchen1991 Nov 22, 2021
aacfaae
Remove debug print statement
seanchen1991 Oct 13, 2021
f24bdf0
Ensure that generated chars are ASCII
seanchen1991 Oct 14, 2021
6e59b5b
Fix conflicts while pulling
seanchen1991 Nov 22, 2021
db9b47a
Allow unused imports to appease clippy
seanchen1991 Nov 22, 2021
8c8ad90
Implement Path as a collection of Identifiers
hu55a1n1 Dec 2, 2021
b66625a
Polish Display impl for Path
hu55a1n1 Dec 2, 2021
93ac739
Fix AsBytes trait
hu55a1n1 Dec 2, 2021
82021fb
Use ibc Paths
hu55a1n1 Dec 2, 2021
40fec64
Clippy happy
hu55a1n1 Dec 2, 2021
a38bc23
Merge branch 'phase4' into path-identifier-cleanup
hu55a1n1 Dec 2, 2021
002de7a
Merge branch 'main' into path-identifier-cleanup
hu55a1n1 Dec 9, 2021
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
Prev Previous commit
Next Next commit
Add some simple property tests
  • Loading branch information
seanchen1991 committed Nov 22, 2021
commit 6b8ff6b7f54905bf622230b27be2d78564eb8c0b
42 changes: 41 additions & 1 deletion src/app/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ impl Identifier {
fn validate(s: impl AsRef<str>) -> Result<(), Error> {
let s = s.as_ref();

validate_identifier(s, 1, s.len()).map_err(|v| Error::invalid_identifier(s.to_string(), v))
// give a `min` parameter of 0 here to allow id's of arbitrary
// length as inputs; `validate_identifier` itself checks for
// empty inputs and returns an error as appropriate
validate_identifier(s, 0, s.len()).map_err(|v| Error::invalid_identifier(s.to_string(), v))
}
}

Expand Down Expand Up @@ -441,3 +444,40 @@ impl<T: Identifiable> PrefixedPath for T {
}
}
}

#[cfg(test)]
mod tests {
#![allow(unused_must_use)]

use super::Identifier;
use proptest::prelude::*;

fn gen_valid_identifier(len: usize) -> String {
let mut rng = rand::thread_rng();
const ALLOWED_CHARS: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
._+-#[]<>";

(0..=len)
.map(|_| {
let idx = rng.gen_range(0..ALLOWED_CHARS.len());
ALLOWED_CHARS[idx] as char
})
.collect::<String>()
}

proptest! {
#[test]
fn doesnt_crash(s in "\\PC*") {
Identifier::validate(&s);
}

#[test]
fn valid_identifier_is_ok(l in 1usize..=30) {
let id = gen_valid_identifier(l);
let validated = Identifier::validate(&id);

assert!(validated.is_ok())
}
}
}