-
Notifications
You must be signed in to change notification settings - Fork 93
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
feat(schema): Allow integers as username #3328
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ pub struct User { | |
|
||
/// Username of the user. | ||
#[metastructure(pii = "true", max_chars = 128, skip_serialization = "empty")] | ||
pub username: Annotated<String>, | ||
pub username: Annotated<LenientString>, | ||
|
||
/// Human readable name of the user. | ||
#[metastructure(pii = "true", max_chars = 128, skip_serialization = "empty")] | ||
|
@@ -163,7 +163,7 @@ mod tests { | |
email: Annotated::new("mail@example.org".to_string()), | ||
ip_address: Annotated::new(IpAddr::auto()), | ||
name: Annotated::new("John Doe".to_string()), | ||
username: Annotated::new("john_doe".to_string()), | ||
username: Annotated::new(LenientString("john_doe".to_owned())), | ||
geo: Annotated::empty(), | ||
segment: Annotated::new("vip".to_string()), | ||
data: { | ||
|
@@ -202,6 +202,19 @@ mod tests { | |
assert_eq!(output, user.to_json().unwrap()); | ||
} | ||
|
||
#[test] | ||
fn test_user_lenient_username() { | ||
let input = r#"{"username":42}"#; | ||
let output = r#"{"username":"42"}"#; | ||
let user = Annotated::new(User { | ||
username: Annotated::new("42".to_string().into()), | ||
..User::default() | ||
}); | ||
|
||
assert_eq!(user, Annotated::from_json(input).unwrap()); | ||
assert_eq!(output, user.to_json().unwrap()); | ||
Comment on lines
+209
to
+215
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo the round trip is enough assert_eq!( Annotated::from_json(input).unwrap().to_json().unwrap(), r#"{"username":"42"}"#) Can also maybe just use insta here to assert the output? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copy-pasted the existing tests around this, would like to keep them as similar as possible. |
||
} | ||
|
||
#[test] | ||
fn test_user_invalid_id() { | ||
let json = r#"{"id":[]}"#; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: floats are also accepted in
LenientString