Skip to content

Commit

Permalink
chore: add test for signer status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Jan 29, 2024
1 parent 9501bd2 commit bdb2e3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
16 changes: 5 additions & 11 deletions libsigner/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,11 @@ impl EventReceiver for SignerEventReceiver {
}
let request = http_server.recv()?;

if request.method() == &HttpMethod::Get {
if request.url() == "/status" {
request
.respond(HttpResponse::from_string("OK"))
.expect("response failed");
return Ok(SignerEvent::StatusCheck);
}
return Err(EventError::MalformedRequest(format!(
"Unrecognized GET request '{}'",
&request.url(),
)));
if request.url() == "/status" {
request
.respond(HttpResponse::from_string("OK"))
.expect("response failed");
return Ok(SignerEvent::StatusCheck);
}

if request.method() != &HttpMethod::Post {
Expand Down
20 changes: 19 additions & 1 deletion libsigner/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

mod http;

use std::io::Write;
use std::io::{Read, Write};
use std::net::{SocketAddr, TcpStream, ToSocketAddrs};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration;
Expand Down Expand Up @@ -138,6 +138,24 @@ fn test_simple_signer() {

num_sent += 1;
}
// Test the /status endpoint
{
let mut sock = match TcpStream::connect(endpoint) {
Ok(sock) => sock,
Err(..) => {
sleep_ms(100);
return;
}
};
let req = "GET /status HTTP/1.0\r\nConnection: close\r\n\r\n";
sock.write_all(req.as_bytes()).unwrap();
let mut buf = [0; 128];
sock.read(&mut buf).unwrap();
let res_str = std::str::from_utf8(&buf).unwrap();
let expected_status_res = "HTTP/1.0 200 OK\r\n";
assert_eq!(expected_status_res, &res_str[..expected_status_res.len()]);
sock.flush().unwrap();
}
});

let running_signer = signer.spawn(endpoint).unwrap();
Expand Down

0 comments on commit bdb2e3c

Please sign in to comment.