feat: add logging to server fixture (#903)

This commit is contained in:
Hendrik Eeckhaut
2025-06-04 08:49:33 +02:00
committed by GitHub
parent 24e10d664f
commit fa2fdfd601
7 changed files with 67 additions and 22 deletions

59
Cargo.lock generated
View File

@@ -4668,7 +4668,7 @@ dependencies = [
[[package]]
name = "notary-client"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"derive_builder 0.12.0",
"futures 0.3.31",
@@ -4686,14 +4686,14 @@ dependencies = [
[[package]]
name = "notary-common"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"serde",
]
[[package]]
name = "notary-server"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"async-tungstenite 0.28.2",
"axum 0.8.4",
@@ -4736,7 +4736,7 @@ dependencies = [
"tokio",
"tokio-rustls",
"tokio-util",
"tower-http",
"tower-http 0.5.2",
"tower-service",
"tower-util",
"tracing",
@@ -7201,7 +7201,7 @@ dependencies = [
[[package]]
name = "tlsn-cipher"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"aes 0.8.4",
"async-trait",
@@ -7220,7 +7220,7 @@ dependencies = [
[[package]]
name = "tlsn-common"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"async-trait",
"derive_builder 0.12.0",
@@ -7251,7 +7251,7 @@ dependencies = [
[[package]]
name = "tlsn-core"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"alloy-primitives",
"alloy-signer",
@@ -7289,7 +7289,7 @@ version = "0.0.0"
[[package]]
name = "tlsn-deap"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"async-trait",
"futures 0.3.31",
@@ -7343,7 +7343,7 @@ dependencies = [
[[package]]
name = "tlsn-formats"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"bytes",
"rstest",
@@ -7355,7 +7355,7 @@ dependencies = [
[[package]]
name = "tlsn-hmac-sha256"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"criterion",
"hex",
@@ -7376,7 +7376,7 @@ dependencies = [
[[package]]
name = "tlsn-key-exchange"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"async-trait",
"derive_builder 0.12.0",
@@ -7402,7 +7402,7 @@ dependencies = [
[[package]]
name = "tlsn-mpc-tls"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"aes 0.8.4",
"aes-gcm",
@@ -7452,7 +7452,7 @@ dependencies = [
[[package]]
name = "tlsn-prover"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"derive_builder 0.12.0",
"futures 0.3.31",
@@ -7499,7 +7499,10 @@ dependencies = [
"tokio",
"tokio-util",
"tower 0.5.2",
"tower-http 0.6.5",
"tower-service",
"tracing",
"tracing-subscriber",
]
[[package]]
@@ -7508,7 +7511,7 @@ version = "0.0.0"
[[package]]
name = "tlsn-tls-backend"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"async-trait",
"futures 0.3.31",
@@ -7518,7 +7521,7 @@ dependencies = [
[[package]]
name = "tlsn-tls-client"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"aes-gcm",
"async-trait",
@@ -7545,7 +7548,7 @@ dependencies = [
[[package]]
name = "tlsn-tls-client-async"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"bytes",
"futures 0.3.31",
@@ -7563,7 +7566,7 @@ dependencies = [
[[package]]
name = "tlsn-tls-core"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"futures 0.3.31",
"hmac",
@@ -7586,7 +7589,7 @@ source = "git+https://github.com/tlsnotary/tlsn-utils?rev=6168663#6168663495281f
[[package]]
name = "tlsn-verifier"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"derive_builder 0.12.0",
"futures 0.3.31",
@@ -7616,7 +7619,7 @@ dependencies = [
[[package]]
name = "tlsn-wasm"
version = "0.1.0-alpha.11"
version = "0.1.0-alpha.12-pre"
dependencies = [
"bincode",
"console_error_panic_hook",
@@ -7669,7 +7672,7 @@ dependencies = [
"tokio",
"tokio-util",
"tower 0.4.13",
"tower-http",
"tower-http 0.5.2",
"tracing",
"tracing-subscriber",
"websocket-relay",
@@ -7867,6 +7870,22 @@ dependencies = [
"tracing",
]
[[package]]
name = "tower-http"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc2d9e086a412a451384326f521c8123a99a466b329941a9403696bff9b0da2"
dependencies = [
"bitflags 2.9.1",
"bytes",
"http 1.3.1",
"http-body 1.0.1",
"pin-project-lite",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "tower-layer"
version = "0.3.3"

View File

@@ -13,7 +13,7 @@ Before starting the notarization, set up the local test server and local notary.
1. Run the test server:
```shell
PORT=4000 cargo run --bin tlsn-server-fixture
RUST_LOG=info PORT=4000 cargo run --bin tlsn-server-fixture
```
2. Run the notary server:
```shell

View File

@@ -4,7 +4,7 @@ This example demonstrates how to use TLSNotary in a simple interactive session b
This example fetches data from a local test server. To start this server, run:
```shell
PORT=4000 cargo run --bin tlsn-server-fixture
RUST_LOG=info PORT=4000 cargo run --bin tlsn-server-fixture
```
Next, run the interactive example with:
```shell

View File

@@ -19,6 +19,9 @@ tokio-util = { workspace = true, features = ["compat", "io"] }
tower-service = { version = "0.3" }
serde_json = { workspace = true }
tlsn-server-fixture-certs = { workspace = true }
tracing.workspace = true
tracing-subscriber.workspace = true
tower-http = { version = "0.6.5", features = ["trace"] }
[[bin]]
name = "tlsn-server-fixture"

View File

@@ -16,6 +16,14 @@ Set the enviroment variable `PORT` to configured the port the server runs on.
PORT=3001 cargo run --release
```
## Logging
Enable server logs by setting the log level:
```bash
RUST_LOG=info cargo run --release
```
## Testing
You can test the server works using curl:

View File

@@ -9,6 +9,8 @@ use axum::{
routing::get,
Json, Router,
};
use tower_http::trace::TraceLayer;
use futures::{channel::oneshot, AsyncRead, AsyncWrite};
use futures_rustls::{
pki_types::{CertificateDer, PrivateKeyDer},
@@ -30,6 +32,7 @@ use axum::extract::FromRequest;
use hyper::header;
use tlsn_server_fixture_certs::*;
use tracing::info;
pub const DEFAULT_FIXTURE_PORT: u16 = 3000;
@@ -44,6 +47,7 @@ fn app(state: AppState) -> Router {
.route("/formats/json", get(json))
.route("/formats/html", get(html))
.route("/protected", get(protected_route))
.layer(TraceLayer::new_for_http())
.with_state(Arc::new(Mutex::new(state)))
}
@@ -89,6 +93,8 @@ async fn bytes(
State(state): State<Arc<Mutex<AppState>>>,
Query(params): Query<HashMap<String, String>>,
) -> Result<Bytes, StatusCode> {
info!("Handling /bytes with params: {:?}", params);
let size = params
.get("size")
.and_then(|size| size.parse::<usize>().ok())
@@ -113,6 +119,8 @@ async fn json(
State(state): State<Arc<Mutex<AppState>>>,
Query(params): Query<HashMap<String, String>>,
) -> Result<Json<Value>, StatusCode> {
info!("Handling /json with params: {:?}", params);
let size = params
.get("size")
.and_then(|size| size.parse::<usize>().ok())
@@ -134,6 +142,8 @@ async fn html(
State(state): State<Arc<Mutex<AppState>>>,
Query(params): Query<HashMap<String, String>>,
) -> Html<&'static str> {
info!("Handling /html with params: {:?}", params);
if params.contains_key("shutdown") {
_ = state.lock().unwrap().shutdown.take().unwrap().send(());
}
@@ -173,6 +183,8 @@ where
}
async fn protected_route(_: AuthenticatedUser) -> Result<Json<Value>, StatusCode> {
info!("Handling /protected");
get_json_value(include_str!("data/protected_data.json"))
}

View File

@@ -3,12 +3,15 @@ use std::{env, io};
use tlsn_server_fixture::{bind, DEFAULT_FIXTURE_PORT};
use tokio::net::TcpListener;
use tokio_util::compat::TokioAsyncWriteCompatExt;
use tracing::info;
#[tokio::main]
async fn main() -> io::Result<()> {
tracing_subscriber::fmt::init();
let port = env::var("PORT").unwrap_or_else(|_| DEFAULT_FIXTURE_PORT.to_string());
let listener = TcpListener::bind(&format!("0.0.0.0:{port}")).await?;
info!("Starting server fixture on port {port}");
loop {
let (socket, _) = listener.accept().await?;
tokio::spawn(bind(socket.compat_write()));