()
| 726 | |
| 727 | #[tokio::test] |
| 728 | async fn callback_server_rejects_missing_fields() { |
| 729 | let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); |
| 730 | let addr = listener.local_addr().unwrap(); |
| 731 | let (tx, rx) = oneshot::channel(); |
| 732 | |
| 733 | tokio::spawn(run_callback_server( |
| 734 | listener, |
| 735 | tx, |
| 736 | "ABC-1234".to_string(), |
| 737 | TEST_GATEWAY.to_string(), |
| 738 | )); |
| 739 | |
| 740 | // POST with no body. |
| 741 | let mut stream = tokio::net::TcpStream::connect(addr).await.unwrap(); |
| 742 | let request = format!( |
| 743 | "POST /callback HTTP/1.1\r\n\ |
| 744 | Host: 127.0.0.1\r\n\ |
| 745 | Origin: {TEST_GATEWAY}\r\n\ |
| 746 | Content-Length: 0\r\n\r\n" |
| 747 | ); |
| 748 | stream.write_all(request.as_bytes()).await.unwrap(); |
| 749 | |
| 750 | let mut buf = vec![0u8; 4096]; |
| 751 | let n = stream.read(&mut buf).await.unwrap(); |
| 752 | let response = String::from_utf8_lossy(&buf[..n]); |
| 753 | assert!( |
| 754 | response.contains("400 Bad Request"), |
| 755 | "missing fields should return 400:\n{response}" |
| 756 | ); |
| 757 | |
| 758 | assert!( |
| 759 | rx.await.is_err(), |
| 760 | "token channel should not receive a value when fields are missing" |
| 761 | ); |
| 762 | } |
| 763 | |
| 764 | #[tokio::test] |
| 765 | async fn callback_server_handles_cors_preflight() { |
nothing calls this directly
no test coverage detected