Skip to content

Commit

Permalink
chore: raise error message when failing to validate tokens and url ha…
Browse files Browse the repository at this point in the history
…s url postfix (#588)

Co-authored-by: Christopher Kolstad <[email protected]>
  • Loading branch information
sighphyre and chriswk authored Nov 25, 2024
1 parent a87340c commit f0df427
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ utoipa-swagger-ui = { version = "8", features = ["actix-web"] }
actix-http = "3.9.0"
actix-http-test = "3.2.0"
actix-service = "2.0.2"
capture-logger = "0.1.1"
env_logger = "0.11.5"
maplit = "1.0.2"
rand = "0.8.5"
Expand Down
17 changes: 9 additions & 8 deletions server/src/http/unleash_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use reqwest::header::{HeaderMap, HeaderName};
use reqwest::{header, Client};
use reqwest::{ClientBuilder, Identity, RequestBuilder, StatusCode, Url};
use serde::{Deserialize, Serialize};
use tracing::error;
use tracing::{info, trace, warn};
use unleash_types::client_features::ClientFeatures;
use unleash_types::client_metrics::ClientApplication;
Expand Down Expand Up @@ -178,11 +179,7 @@ pub struct EdgeTokens {
}

impl UnleashClient {
pub fn from_url(
server_url: Url,
token_header: String,
backing_client: Client,
) -> Self {
pub fn from_url(server_url: Url, token_header: String, backing_client: Client) -> Self {
Self {
urls: UnleashUrls::from_base_url(server_url),
backing_client,
Expand Down Expand Up @@ -434,7 +431,7 @@ impl UnleashClient {
let check_api_suffix = || {
let base_url = self.urls.base_url.to_string();
if base_url.ends_with("/api") || base_url.ends_with("/api/") {
info!("Try passing the instance URL without '/api'.");
error!("Try passing the instance URL without '/api'.");
}
};

Expand All @@ -447,7 +444,6 @@ impl UnleashClient {
.await
.map_err(|e| {
info!("Failed to validate tokens: [{e:?}]");
check_api_suffix();
EdgeError::EdgeTokenError
})?;
match result.status() {
Expand Down Expand Up @@ -476,7 +472,7 @@ impl UnleashClient {
TOKEN_VALIDATION_FAILURES
.with_label_values(&[result.status().as_str()])
.inc();
warn!(
error!(
"Failed to validate tokens. Requested url: [{}]. Got status: {:?}",
self.urls.edge_validate_url.to_string(),
s
Expand Down Expand Up @@ -504,6 +500,7 @@ mod tests {
http::header::EntityTag,
web, App, HttpResponse,
};
use capture_logger::{begin_capture, pop_captured};
use chrono::Duration;
use unleash_types::client_features::{ClientFeature, ClientFeatures};

Expand Down Expand Up @@ -576,6 +573,10 @@ mod tests {
.service(
web::resource("/edge/validate")
.route(web::post().to(return_validate_tokens)),
)
.service(
web::resource("/api/edge/validate")
.route(web::post().to(|| HttpResponse::Forbidden())),
),
|_| AppConfig::default(),
))
Expand Down

0 comments on commit f0df427

Please sign in to comment.