Skip to content

Commit

Permalink
add test for NOT_COORDINATOR
Browse files Browse the repository at this point in the history
  • Loading branch information
conradoplg committed Dec 26, 2024
1 parent 33f8017 commit 4c5dacf
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion server/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,9 @@ async fn test_http() -> Result<(), Box<dyn std::error::Error>> {
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")
Expand All @@ -511,6 +512,41 @@ async fn test_http() -> Result<(), Box<dyn std::error::Error>> {
let r = r.json::<server::Error>().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::<server::ChallengeOutput>().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::<server::KeyLoginOutput>().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::<server::Error>().await?;
assert_eq!(r.code, server::NOT_COORDINATOR);

Ok(())
}

Expand Down

0 comments on commit 4c5dacf

Please sign in to comment.