Skip to content

Commit d51988f

Browse files
authored
Merge pull request #712 from input-output-hk/jpraynaud/fix-api-version-not-sent
Fix API version sent in wrong header
2 parents cd471d7 + 5a36966 commit d51988f

File tree

9 files changed

+41
-27
lines changed

9 files changed

+41
-27
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.2.10"
3+
version = "0.2.11"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/http_server/routes/router.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::http_server::routes::{
44
use crate::http_server::SERVER_BASE_PATH;
55
use crate::DependencyManager;
66

7-
use mithril_common::{MITHRIL_API_VERSION, MITHRIL_API_VERSION_REQUIREMENT};
7+
use mithril_common::{
8+
MITHRIL_API_VERSION, MITHRIL_API_VERSION_HEADER, MITHRIL_API_VERSION_REQUIREMENT,
9+
};
810

911
use reqwest::header::{HeaderMap, HeaderValue};
1012
use reqwest::StatusCode;
@@ -34,7 +36,7 @@ pub fn routes(
3436
.allow_methods(vec![Method::GET, Method::POST, Method::OPTIONS]);
3537
let mut headers = HeaderMap::new();
3638
headers.insert(
37-
"mithril-api-version",
39+
MITHRIL_API_VERSION_HEADER,
3840
HeaderValue::from_static(MITHRIL_API_VERSION),
3941
);
4042
warp::any()
@@ -54,7 +56,7 @@ pub fn routes(
5456

5557
/// API Version verification
5658
fn header_must_be() -> impl Filter<Extract = (), Error = Rejection> + Copy {
57-
warp::header::optional("mithril-api-version")
59+
warp::header::optional(MITHRIL_API_VERSION_HEADER)
5860
.and_then(|maybe_header: Option<String>| async move {
5961
match maybe_header {
6062
None => Ok(()),
@@ -97,7 +99,7 @@ mod tests {
9799
async fn test_parse_version_error() {
98100
let filters = header_must_be();
99101
warp::test::request()
100-
.header("mithril-api-version", "not_a_version")
102+
.header(MITHRIL_API_VERSION_HEADER, "not_a_version")
101103
.path("/aggregator/whatever")
102104
.filter(&filters)
103105
.await
@@ -110,7 +112,7 @@ mod tests {
110112
async fn test_bad_version() {
111113
let filters = header_must_be();
112114
warp::test::request()
113-
.header("mithril-api-version", "0.0.999")
115+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999")
114116
.path("/aggregator/whatever")
115117
.filter(&filters)
116118
.await
@@ -121,7 +123,7 @@ mod tests {
121123
async fn test_good_version() {
122124
let filters = header_must_be();
123125
warp::test::request()
124-
.header("mithril-api-version", MITHRIL_API_VERSION)
126+
.header(MITHRIL_API_VERSION_HEADER, MITHRIL_API_VERSION)
125127
.path("/aggregator/whatever")
126128
.filter(&filters)
127129
.await

mithril-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client"
3-
version = "0.2.6"
3+
version = "0.2.7"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client/src/aggregator.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use async_trait::async_trait;
22
use flate2::read::GzDecoder;
33
use futures::StreamExt;
4+
use mithril_common::MITHRIL_API_VERSION_HEADER;
45
use reqwest::{self, Response, StatusCode};
56
use reqwest::{Client, RequestBuilder};
67
use slog_scope::debug;
@@ -106,7 +107,7 @@ impl AggregatorHTTPClient {
106107

107108
/// Forge a client request adding protocol version in the headers.
108109
pub fn prepare_request_builder(&self, request_builder: RequestBuilder) -> RequestBuilder {
109-
request_builder.header("API_VERSION", MITHRIL_API_VERSION)
110+
request_builder.header(MITHRIL_API_VERSION_HEADER, MITHRIL_API_VERSION)
110111
}
111112

112113
/// Download certificate details
@@ -147,7 +148,7 @@ impl AggregatorHTTPClient {
147148

148149
/// API version error handling
149150
fn handle_api_error(&self, response: &Response) -> AggregatorHandlerError {
150-
if let Some(version) = response.headers().get("mithril-api-version") {
151+
if let Some(version) = response.headers().get(MITHRIL_API_VERSION_HEADER) {
151152
AggregatorHandlerError::ApiVersionMismatch(format!(
152153
"server version: '{}', signer version: '{}'",
153154
version.to_str().unwrap(),
@@ -390,7 +391,8 @@ mod tests {
390391
let (server, config) = setup_test();
391392
let _snapshots_mock = server.mock(|when, then| {
392393
when.path("/snapshots");
393-
then.status(412).header("mithril-api-version", "0.0.999");
394+
then.status(412)
395+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
394396
});
395397
let aggregator_client =
396398
AggregatorHTTPClient::new(config.network, config.aggregator_endpoint);
@@ -456,7 +458,8 @@ mod tests {
456458
let digest = "digest123";
457459
let _snapshots_mock = server.mock(|when, then| {
458460
when.path(format!("/snapshot/{digest}"));
459-
then.status(412).header("mithril-api-version", "0.0.999");
461+
then.status(412)
462+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
460463
});
461464
let aggregator_client =
462465
AggregatorHTTPClient::new(config.network, config.aggregator_endpoint);
@@ -520,7 +523,8 @@ mod tests {
520523
let url_path = "/download";
521524
let _snapshots_mock = server.mock(|when, then| {
522525
when.path(url_path.to_string());
523-
then.status(412).header("mithril-api-version", "0.0.999");
526+
then.status(412)
527+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
524528
});
525529
let aggregator_client =
526530
AggregatorHTTPClient::new(config.network, config.aggregator_endpoint);
@@ -593,7 +597,8 @@ mod tests {
593597
let certificate_hash = "certificate-hash-123";
594598
let _snapshots_mock = server.mock(|when, then| {
595599
when.path(format!("/certificate/{certificate_hash}"));
596-
then.status(412).header("mithril-api-version", "0.0.999");
600+
then.status(412)
601+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
597602
});
598603
let aggregator_client =
599604
AggregatorHTTPClient::new(config.network, config.aggregator_endpoint);

mithril-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.2.9"
3+
version = "0.2.10"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
documentation = { workspace = true }

mithril-common/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ use semver::{Version, VersionReq};
3434
/// please also update the entry in the openapi.yml
3535
pub const MITHRIL_API_VERSION: &str = "0.1.1";
3636

37+
/// Mithril API protocol version header name
38+
pub const MITHRIL_API_VERSION_HEADER: &str = "mithril-api-version";
39+
3740
lazy_static! {
3841
/// The [SemVer version requirement][semver::VersionReq] associated with the [MITHRIL_API_VERSION].
3942
///

mithril-signer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-signer"
3-
version = "0.2.7"
3+
version = "0.2.8"
44
description = "A Mithril Signer"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-signer/src/certificate_handler.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use thiserror::Error;
77
use mithril_common::{
88
entities::{CertificatePending, EpochSettings, Signer, SingleSignatures},
99
messages::{CertificatePendingMessage, EpochSettingsMessage},
10-
MITHRIL_API_VERSION,
10+
MITHRIL_API_VERSION, MITHRIL_API_VERSION_HEADER,
1111
};
1212

1313
#[cfg(test)]
@@ -94,12 +94,12 @@ impl CertificateHandlerHTTPClient {
9494

9595
/// Forge a client request adding protocol version in the headers.
9696
pub fn prepare_request_builder(&self, request_builder: RequestBuilder) -> RequestBuilder {
97-
request_builder.header("API_VERSION", MITHRIL_API_VERSION)
97+
request_builder.header(MITHRIL_API_VERSION_HEADER, MITHRIL_API_VERSION)
9898
}
9999

100100
/// API version error handling
101101
fn handle_api_error(&self, response: &Response) -> CertificateHandlerError {
102-
if let Some(version) = response.headers().get("mithril-api-version") {
102+
if let Some(version) = response.headers().get(MITHRIL_API_VERSION_HEADER) {
103103
CertificateHandlerError::ApiVersionMismatch(format!(
104104
"server version: '{}', signer version: '{}'",
105105
version.to_str().unwrap(),
@@ -381,7 +381,8 @@ mod tests {
381381
let (server, config) = setup_test();
382382
let _snapshots_mock = server.mock(|when, then| {
383383
when.path("/epoch-settings");
384-
then.status(412).header("mithril-api-version", "0.0.999");
384+
then.status(412)
385+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
385386
});
386387
let certificate_handler = CertificateHandlerHTTPClient::new(config.aggregator_endpoint);
387388
let epoch_settings = certificate_handler
@@ -431,7 +432,8 @@ mod tests {
431432
let (server, config) = setup_test();
432433
let _snapshots_mock = server.mock(|when, then| {
433434
when.path("/certificate-pending");
434-
then.status(412).header("mithril-api-version", "0.0.999");
435+
then.status(412)
436+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
435437
});
436438
let certificate_handler = CertificateHandlerHTTPClient::new(config.aggregator_endpoint);
437439
let error = certificate_handler
@@ -489,7 +491,8 @@ mod tests {
489491
let (server, config) = setup_test();
490492
let _snapshots_mock = server.mock(|when, then| {
491493
when.method(POST).path("/register-signer");
492-
then.status(412).header("mithril-api-version", "0.0.999");
494+
then.status(412)
495+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
493496
});
494497
let single_signers = fake_data::signers(1);
495498
let single_signer = single_signers.first().unwrap();
@@ -566,7 +569,8 @@ mod tests {
566569
let (server, config) = setup_test();
567570
let _snapshots_mock = server.mock(|when, then| {
568571
when.method(POST).path("/register-signatures");
569-
then.status(412).header("mithril-api-version", "0.0.999");
572+
then.status(412)
573+
.header(MITHRIL_API_VERSION_HEADER, "0.0.999");
570574
});
571575
let single_signatures = fake_data::single_signatures((1..5).collect());
572576
let certificate_handler = CertificateHandlerHTTPClient::new(config.aggregator_endpoint);

0 commit comments

Comments
 (0)