From e087f8126701f11ebcf5a44c054efcf3297ad52f Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Thu, 26 Oct 2023 09:41:56 +0200 Subject: [PATCH] Reproduce error when delete client with sessions --- Cargo.lock | 2 +- tests/clients.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dbd315..8ee7503 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2643,7 +2643,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zauth" -version = "2.0.0" +version = "2.0.1" dependencies = [ "askama", "askama_rocket", diff --git a/tests/clients.rs b/tests/clients.rs index acccfa9..16b95b9 100644 --- a/tests/clients.rs +++ b/tests/clients.rs @@ -9,8 +9,9 @@ use rocket::http::Status; mod common; -use crate::common::url; +use crate::common::{config, url}; use zauth::models::client::{Client, NewClient}; +use zauth::models::session::Session; #[rocket::async_test] async fn create_and_update_client() { @@ -100,3 +101,42 @@ async fn change_client_secret() { }) .await; } + +#[rocket::async_test] +async fn delete_client_with_session() { + common::as_admin(async move |http_client, db, user| { + let client_name = "test"; + + let client_form = format!("name={}", url(&client_name),); + + let create = http_client + .post("/clients") + .body(client_form) + .header(ContentType::Form) + .header(Accept::JSON) + .dispatch() + .await; + + assert_eq!(create.status(), Status::Created); + let client = Client::find_by_name(client_name.to_owned(), &db) + .await + .unwrap(); + + let session = + Session::create_client_session(&user, &client, &config(), &db) + .await + .unwrap(); + + let delete = http_client + .delete(format!("/clients/{}", &client.id)) + .header(ContentType::Form) + .header(Accept::JSON) + .dispatch() + .await; + + assert_eq!(delete.status(), Status::NoContent); + assert!(Client::find(client.id, &db).await.is_err()); + assert!(Session::find_by_id(session.id, &db).await.is_err()); + }) + .await; +}