Skip to content

Commit

Permalink
task: Added version header to client register response (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Kolstad authored Jan 5, 2024
1 parent 4e20dde commit 5a3db0e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
43 changes: 35 additions & 8 deletions server/src/client_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::filters::{
use crate::http::feature_refresher::FeatureRefresher;
use crate::metrics::client_metrics::MetricsCache;
use crate::tokens::cache_key;
use crate::types::{EdgeJsonResult, EdgeResult, EdgeToken, FeatureFilters};
use crate::types::{self, EdgeJsonResult, EdgeResult, EdgeToken, FeatureFilters};
use actix_web::web::{self, Data, Json, Query};
use actix_web::{get, post, HttpRequest, HttpResponse};
use dashmap::DashMap;
Expand Down Expand Up @@ -171,7 +171,9 @@ pub async fn register(
client_application.into_inner(),
metrics_cache,
);
Ok(HttpResponse::Accepted().finish())
Ok(HttpResponse::Accepted()
.append_header(("X-Edge-Version", types::EDGE_VERSION))
.finish())
}

#[utoipa::path(
Expand Down Expand Up @@ -476,6 +478,31 @@ mod tests {
assert_eq!(saved_app.connect_via, Some(vec![our_app]));
}

#[tokio::test]
async fn register_endpoint_returns_version_header() {
let metrics_cache = Arc::new(MetricsCache::default());
let our_app = ConnectVia {
app_name: "test".into(),
instance_id: Ulid::new().to_string(),
};
let app = test::init_service(
App::new()
.app_data(Data::new(our_app.clone()))
.app_data(Data::from(metrics_cache.clone()))
.service(web::scope("/api/client").service(register)),
)
.await;
let mut client_app = ClientApplication::new("test_application", 15);
client_app.instance_id = Some("test_instance".into());
let req = make_register_post_request(client_app.clone()).await;
let res = test::call_service(&app, req).await;
assert_eq!(res.status(), StatusCode::ACCEPTED);
assert_eq!(
res.headers().get("X-Edge-Version").unwrap(),
types::EDGE_VERSION
);
}

#[tokio::test]
async fn client_features_endpoint_correctly_returns_cached_features() {
let features_cache: Arc<DashMap<String, ClientFeatures>> = Arc::new(DashMap::default());
Expand Down Expand Up @@ -1031,11 +1058,11 @@ mod tests {
let res = test::call_service(&app, request).await;
assert_eq!(res.status(), StatusCode::OK);
let request = test::TestRequest::get()
.uri("/api/client/features")
.insert_header(ContentType::json())
.insert_header(("ShouldNotWork", production_token.token.clone()))
.to_request();
let res = test::call_service(&app, request).await;
assert_eq!(res.status(), StatusCode::FORBIDDEN);
.uri("/api/client/features")
.insert_header(ContentType::json())
.insert_header(("ShouldNotWork", production_token.token.clone()))
.to_request();
let res = test::call_service(&app, request).await;
assert_eq!(res.status(), StatusCode::FORBIDDEN);
}
}
2 changes: 1 addition & 1 deletion server/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ pub struct BuildInfo {
pub build_os: String,
pub build_target: String,
}

shadow!(build); // Get build information set to build placeholder
pub const EDGE_VERSION: &str = build::PKG_VERSION;
impl Default for BuildInfo {
fn default() -> Self {
BuildInfo {
Expand Down

0 comments on commit 5a3db0e

Please sign in to comment.