diff --git a/server/tests/integration_tests.rs b/server/tests/integration_tests.rs index 0e93a8e..b23d5f2 100644 --- a/server/tests/integration_tests.rs +++ b/server/tests/integration_tests.rs @@ -496,8 +496,9 @@ async fn test_http() -> Result<(), Box> { let session_id = r.session_id; println!("Session ID: {}", session_id); - // Error test + // Error tests + // Test if passing the wrong session ID returns an error let wrong_session_id = Uuid::new_v4(); let r = client .post("http://127.0.0.1:2744/get_session_info") @@ -511,6 +512,41 @@ async fn test_http() -> Result<(), Box> { let r = r.json::().await?; assert_eq!(r.code, server::SESSION_NOT_FOUND); + // Test if trying to close the session as a participant fails + // Attempt to close the session as a participant (Bob) + // Log in as Bob + let r = client + .post("http://127.0.0.1:2744/challenge") + .json(&server::ChallengeArgs {}) + .send() + .await?; + let r = r.json::().await?; + let bob_challenge = r.challenge; + let bob_private = + xed25519::PrivateKey::from(&TryInto::<[u8; 32]>::try_into(bob_keypair.private).unwrap()); + let bob_signature: [u8; 64] = bob_private.sign(bob_challenge.as_bytes(), &mut rng); + let r = client + .post("http://127.0.0.1:2744/login") + .json(&server::KeyLoginArgs { + uuid: bob_challenge, + pubkey: bob_keypair.public.clone(), + signature: bob_signature.to_vec(), + }) + .send() + .await?; + let r = r.json::().await?; + let bob_access_token = r.access_token; + // Try to close the session + let r = client + .post("http://127.0.0.1:2744/close_session") + .bearer_auth(bob_access_token) + .json(&server::CloseSessionArgs { session_id }) + .send() + .await?; + assert_eq!(r.status(), reqwest::StatusCode::INTERNAL_SERVER_ERROR); + let r = r.json::().await?; + assert_eq!(r.code, server::NOT_COORDINATOR); + Ok(()) }