Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.

Commit 78ac81b

Browse files
committed
test(rtc_tenclave,kv_store): round-trip encode_to_fs_safe and decode_from_fs_safe
1 parent ef3313b commit 78ac81b

File tree

1 file changed

+29
-0
lines changed
  • rtc_tenclave/src/kv_store/fs

1 file changed

+29
-0
lines changed

rtc_tenclave/src/kv_store/fs/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,32 @@ pub(crate) fn decode_from_fs_safe(file_name: &str) -> Result<String, String> {
131131

132132
#[cfg(test)]
133133
mod inspect;
134+
135+
#[cfg(test)]
136+
mod tests {
137+
use proptest::prelude::*;
138+
139+
use super::decode_from_fs_safe;
140+
use super::encode_to_fs_safe;
141+
142+
/// [`encode_to_fs_safe`] encodes to filesystem-safe, and [`decode_from_fs_safe`] round-trips.
143+
#[test]
144+
fn prop_fs_safe_roundtrip() {
145+
let test = |key: &String| {
146+
let encoded = &encode_to_fs_safe(key);
147+
assert!(
148+
is_fs_safe(encoded),
149+
"expected filesystem-safe, got encoded = {:?}",
150+
encoded
151+
);
152+
let decoded = &decode_from_fs_safe(encoded).unwrap();
153+
assert_eq!(key, decoded);
154+
};
155+
proptest!(|(key in ".*")| test(&key));
156+
}
157+
158+
/// Helper: Very conservative definition of filesystem-safe.
159+
fn is_fs_safe(encoded: &str) -> bool {
160+
0 < encoded.len() && encoded.chars().all(|c| c.is_ascii_alphanumeric())
161+
}
162+
}

0 commit comments

Comments
 (0)