From b0570a09c9b5d4ab196374de9eead928d105bede Mon Sep 17 00:00:00 2001 From: Alexey Lebedenko Date: Thu, 26 Sep 2024 14:55:25 +0200 Subject: [PATCH] Show Server version on / --- next-gen-signing-service/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/next-gen-signing-service/src/main.rs b/next-gen-signing-service/src/main.rs index 0bc8d7f..a8d0f2a 100644 --- a/next-gen-signing-service/src/main.rs +++ b/next-gen-signing-service/src/main.rs @@ -3,6 +3,8 @@ use rocket::{get, launch, routes, serde::json::Json}; use next_gen_signatures::{Engine, BASE64_URL_SAFE_NO_PAD}; use rocket_errors::anyhow; +const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[derive(Debug, rocket::serde::Serialize, rocket::serde::Deserialize)] #[serde(crate = "rocket::serde")] pub struct KeyPair { @@ -28,8 +30,8 @@ mod bbs_plus_routes { } #[get("/")] -fn index() -> &'static str { - "Hello, World!" +fn index() -> String { + format!("SPRIND Signing Service v{VERSION}") } #[launch] @@ -80,6 +82,8 @@ fn rocket() -> _ { #[cfg(test)] mod test { + use crate::VERSION; + use super::rocket; use rocket::local::blocking::Client; use rocket::{http::Status, uri}; @@ -196,11 +200,11 @@ mod test { } #[test] - fn hello_world() { + fn index_should_contain_version() { let client = Client::tracked(rocket()).expect("valid rocket instance"); let response = client.get(uri!(super::index)).dispatch(); assert_eq!(response.status(), Status::Ok); - assert_eq!(response.into_string().unwrap(), "Hello, World!"); + assert!(response.into_string().unwrap().contains(VERSION)); } test_roundtrip_fips204!(44);