diff --git a/crates/kitsune-db/tests/unicode_collation.rs b/crates/kitsune-db/tests/unicode_collation.rs index de02c6d78..08aac0ffc 100644 --- a/crates/kitsune-db/tests/unicode_collation.rs +++ b/crates/kitsune-db/tests/unicode_collation.rs @@ -3,7 +3,7 @@ use diesel_async::{scoped_futures::ScopedFutureExt, AsyncPgConnection, RunQueryD use kitsune_db::{ model::{ account::{Account, ActorType, NewAccount}, - user::User, + user::{NewUser, User}, }, schema::{accounts, users}, }; @@ -41,6 +41,27 @@ async fn create_account(conn: &mut AsyncPgConnection, username: &str) -> Result< .map_err(Into::into) } +async fn create_user(conn: &mut AsyncPgConnection, username: &str) -> Result { + let account = create_account(conn, Uuid::now_v7().to_string().as_str()).await?; + + diesel::insert_into(users::table) + .values(NewUser { + id: Uuid::now_v7(), + account_id: account.id, + oidc_id: None, + username, + email: format!("{username}@kitsune.example").as_str(), + password: None, + domain: "kitsune.example", + private_key: "---WHATEVER---", + confirmation_token: Uuid::now_v7().to_string().as_str(), + }) + .returning(User::as_returning()) + .get_result(conn) + .await + .map_err(Into::into) +} + #[tokio::test] #[serial_test::serial] async fn accounts_username() { @@ -76,5 +97,31 @@ async fn accounts_username() { #[tokio::test] #[serial_test::serial] async fn users_username() { - database_test(|db_pool| async move {}).await; + database_test(|db_pool| async move { + db_pool + .with_connection(|conn| { + async move { + let initial_insert = create_user(conn, "aumetra").await; + assert!(initial_insert.is_ok()); + + let case_mutation = create_user(conn, "AuMeTrA").await; + assert!(case_mutation.is_err()); + + let unicode_mutation_1 = create_user(conn, "äumeträ").await; + assert!(unicode_mutation_1.is_err()); + + let unicode_mutation_2 = create_user(conn, "🅰umetr🅰").await; + assert!(unicode_mutation_2.is_err()); + + let unicode_case_mutation = create_user(conn, "🅰UMETR🅰").await; + assert!(unicode_case_mutation.is_err()); + + Result::Ok(()) + } + .scoped() + }) + .await + .unwrap(); + }) + .await; }