From aaeb9d39a6370426422c187cff4727558571347f Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Sat, 22 Jun 2024 22:51:19 +0200 Subject: [PATCH] Add test --- tests/users.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/users.rs b/tests/users.rs index fa5a2f8..816e450 100644 --- a/tests/users.rs +++ b/tests/users.rs @@ -1014,3 +1014,43 @@ async fn validate_unique_username() { }) .await; } + +#[rocket::async_test] +async fn get_keys() { + common::as_visitor(async move |http_client: HttpClient, db| { + let mut user = User::create( + NewUser { + username: String::from("user"), + password: String::from("password"), + full_name: String::from("name"), + email: String::from("test@test.test"), + ssh_key: None, + not_a_robot: true, + }, + common::BCRYPT_COST, + &db, + ) + .await + .unwrap(); + + // User::create throws away ssh_key in NewUser. + user.ssh_key = Some(String::from("ssh-rsa rsa \n ssh-ed25519 ed25519")); + let user = user.update(&db).await.unwrap(); + + let response = http_client + .get(format!("/users/{}/keys", user.username)) + .dispatch() + .await; + + assert_eq!(response.status(), Status::Ok); + + let keys = response + .into_json::>() + .await + .expect("response json"); + assert_eq!(keys.len(), 2); + assert_eq!(keys[0], "ssh-rsa rsa"); + assert_eq!(keys[1], "ssh-ed25519 ed25519"); + }) + .await; +}