-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make account names case-insensitive (#407)
* make names insensitive * add dev dependency * make users table case-insensitive * use unicode collation * always use username from database * adjust regex * add validator test * up cargo deps * up yarn deps * flake.lock: Update Flake lock file updates: • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/603e4962d7d2225ba2caf66b0eabfcaa9a93c490' (2023-11-09) → 'github:oxalica/rust-overlay/41f7b0618052430d3a050e8f937030d00a2fcced' (2023-11-10) * add accounts table tests * add users table tests
- Loading branch information
Showing
28 changed files
with
677 additions
and
385 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ fn is_strong_password(value: &Option<String>, _context: &()) -> garde::Result { | |
#[derive(Clone, TypedBuilder, Validate)] | ||
pub struct Register { | ||
/// Username of the new user | ||
#[garde(length(min = 1, max = 64), pattern(r"[\w\.]+"))] | ||
#[garde(length(min = 1, max = 64), pattern(r"^[\p{L}\p{N}\.]+$"))] | ||
username: String, | ||
|
||
/// Email address of the new user | ||
|
@@ -261,3 +261,49 @@ impl UserService { | |
self.registrations_open | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::Register; | ||
use garde::Validate; | ||
|
||
#[test] | ||
fn alphanumeric_username() { | ||
let valid_usernames = [ | ||
"aumetra", | ||
"AUMETRA", | ||
"aum3tr4", | ||
"äumäträ", | ||
"아우멭라", | ||
"あうめtら", | ||
]; | ||
|
||
for username in valid_usernames { | ||
let register = Register::builder() | ||
.email("[email protected]".into()) | ||
.password("verysecurepassword123".into()) | ||
.username(username.into()) | ||
.build(); | ||
|
||
assert!( | ||
register.validate(&()).is_ok(), | ||
"{username} is considered invalid", | ||
); | ||
} | ||
|
||
let invalid_usernames = [",,,", "🎃spooky", "weewoo 🚨"]; | ||
|
||
for username in invalid_usernames { | ||
let register = Register::builder() | ||
.email("[email protected]".into()) | ||
.password("verysecurepassword123".into()) | ||
.username(username.into()) | ||
.build(); | ||
|
||
assert!( | ||
register.validate(&()).is_err(), | ||
"{username} is considered valid", | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.