Skip to content

Commit bd29365

Browse files
authored
Update dependencies, fix invalid error logs (#1429)
1 parent 07bf86b commit bd29365

File tree

11 files changed

+319
-196
lines changed

11 files changed

+319
-196
lines changed

Cargo.lock

+291-181
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration/tests/examples/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a> IggyExampleTest<'a> {
141141
}
142142
}
143143

144-
impl<'a> IggyExampleTest<'a> {
144+
impl IggyExampleTest<'_> {
145145
async fn spawn_executables(&mut self, tcp_server_address: Vec<String>) -> (String, String) {
146146
let mut producer_cmd = Command::cargo_bin(format!("examples/{}-producer", self.module))
147147
.unwrap_or_else(|_| panic!("Failed to find {}-producer", self.module));

sdk/src/http/client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::ops::Deref;
1616
use std::str::FromStr;
1717
use std::sync::Arc;
1818

19-
const UNAUTHORIZED_PATHS: &[&str] = &[
19+
const PUBLIC_PATHS: &[&str] = &[
2020
"/",
2121
"/metrics",
2222
"/ping",
@@ -278,7 +278,7 @@ impl HttpClient {
278278
}
279279

280280
async fn fail_if_not_authenticated(&self, path: &str) -> Result<(), IggyError> {
281-
if UNAUTHORIZED_PATHS.contains(&path) {
281+
if PUBLIC_PATHS.contains(&path) {
282282
return Ok(());
283283
}
284284
if !self.is_authenticated().await {

server/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "server"
3-
version = "0.4.100"
3+
version = "0.4.101"
44
edition = "2021"
55
build = "src/build.rs"
66

server/src/configs/displays.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Display for HttpJwtConfig {
4141
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
4242
write!(
4343
f,
44-
"{{ algorithm: {}, audience: {}, expiry: {}, use_base64_secret: {} }}",
44+
"{{ algorithm: {}, audience: {}, access_token_expiry: {}, use_base64_secret: {} }}",
4545
self.algorithm, self.audience, self.access_token_expiry, self.use_base64_secret
4646
)
4747
}

server/src/http/error.rs

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ impl IntoResponse for CustomError {
3838
IggyError::ConsumerGroupMemberNotFound(_, _, _) => StatusCode::NOT_FOUND,
3939
IggyError::ResourceNotFound(_) => StatusCode::NOT_FOUND,
4040
IggyError::Unauthenticated => StatusCode::UNAUTHORIZED,
41+
IggyError::AccessTokenMissing => StatusCode::UNAUTHORIZED,
42+
IggyError::InvalidAccessToken => StatusCode::UNAUTHORIZED,
43+
IggyError::InvalidPersonalAccessToken => StatusCode::UNAUTHORIZED,
4144
IggyError::Unauthorized => StatusCode::FORBIDDEN,
4245
_ => StatusCode::BAD_REQUEST,
4346
};

server/src/http/jwt/jwt_manager.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl JwtManager {
185185
})
186186
}
187187

188+
// The access token can be refreshed only once and if it is not expired
188189
pub async fn refresh_token(&self, token: &str) -> Result<GeneratedToken, IggyError> {
189190
if token.is_empty() {
190191
return Err(IggyError::InvalidAccessToken);
@@ -212,7 +213,7 @@ impl JwtManager {
212213
})
213214
.await
214215
.with_error_context(|_| {
215-
format!("{COMPONENT} - failed to save revoked access token: {}", id)
216+
format!("{COMPONENT} - failed to save revoked access token: {id}")
216217
})?;
217218
self.generate(jwt_claims.claims.sub)
218219
}

server/src/http/jwt/middleware.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use axum::{
1010
use error_set::ErrContext;
1111
use std::sync::Arc;
1212

13+
const COMPONENT: &str = "JWT_MIDDLEWARE";
1314
const AUTHORIZATION: &str = "authorization";
1415
const BEARER: &str = "Bearer ";
1516
const UNAUTHORIZED: StatusCode = StatusCode::UNAUTHORIZED;
1617

17-
const UNAUTHORIZED_PATHS: &[&str] = &[
18+
const PUBLIC_PATHS: &[&str] = &[
1819
"/",
1920
"/metrics",
2021
"/ping",
@@ -29,17 +30,19 @@ pub async fn jwt_auth(
2930
mut request: Request<Body>,
3031
next: Next,
3132
) -> Result<Response, StatusCode> {
32-
if UNAUTHORIZED_PATHS.contains(&request.uri().path()) {
33+
if PUBLIC_PATHS.contains(&request.uri().path()) {
3334
return Ok(next.run(request).await);
3435
}
3536

3637
let bearer = request
3738
.headers()
3839
.get(AUTHORIZATION)
3940
.ok_or(UNAUTHORIZED)
40-
.with_error_context(|_| "{COMPONENT} - missing or inaccessible Authorization header")?
41+
.with_error_context(|_| {
42+
format!("{COMPONENT} - missing or inaccessible Authorization header")
43+
})?
4144
.to_str()
42-
.with_error_context(|_| "{COMPONENT} - invalid authorization header format")
45+
.with_error_context(|_| format!("{COMPONENT} - invalid authorization header format"))
4346
.map_err(|_| UNAUTHORIZED)?;
4447

4548
if !bearer.starts_with(BEARER) {
@@ -48,12 +51,14 @@ pub async fn jwt_auth(
4851

4952
let jwt_token = &bearer[BEARER.len()..];
5053
let token_header = jsonwebtoken::decode_header(jwt_token)
51-
.with_error_context(|_| "{COMPONENT} - failed to decode JWT header")
54+
.with_error_context(|_| format!("{COMPONENT} - failed to decode JWT header"))
5255
.map_err(|_| UNAUTHORIZED)?;
5356
let jwt_claims = state
5457
.jwt_manager
5558
.decode(jwt_token, token_header.alg)
56-
.with_error_context(|_| "{COMPONENT} - failed to decode JWT with provided algorithm")
59+
.with_error_context(|_| {
60+
format!("{COMPONENT} - failed to decode JWT with provided algorithm")
61+
})
5762
.map_err(|_| UNAUTHORIZED)?;
5863
if state
5964
.jwt_manager

server/src/http/jwt/storage.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ impl TokenStorage {
104104
let tokens = self
105105
.load_all_revoked_access_tokens()
106106
.await
107-
.with_error_context(|_| "{COMPONENT} - failed to load revoked access tokens")?;
107+
.with_error_context(|_| {
108+
format!("{COMPONENT} - failed to load revoked access tokens")
109+
})?;
108110
if tokens.is_empty() {
109111
return Ok(());
110112
}

server/src/http/personal_access_tokens.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ async fn login_with_personal_access_token(
152152
let user = system
153153
.login_with_personal_access_token(&command.token, None)
154154
.await
155-
.with_error_context(|_| "{COMPONENT} - failed to login with personal access token")?;
155+
.with_error_context(|_| {
156+
format!("{COMPONENT} - failed to login with personal access token")
157+
})?;
156158
let tokens = state.jwt_manager.generate(user.id)?;
157159
Ok(Json(map_generated_access_token_to_identity_info(tokens)))
158160
}

server/src/http/users.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ async fn refresh_token(
354354
.jwt_manager
355355
.refresh_token(&command.token)
356356
.await
357-
.with_error_context(|_| "{COMPONENT} - failed to refresh token")?;
357+
.with_error_context(|_| format!("{COMPONENT} - failed to refresh token"))?;
358358
Ok(Json(map_generated_access_token_to_identity_info(token)))
359359
}
360360

0 commit comments

Comments
 (0)