Skip to content

Commit

Permalink
Reproduce error when delete client with sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
rien committed Oct 26, 2023
1 parent f3da85c commit e087f81
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 41 additions & 1 deletion tests/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}

0 comments on commit e087f81

Please sign in to comment.