Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ rust-version = "1.86.0"
[workspace.dependencies]
# Workspace dependencies
reqsign-aliyun-oss = { version = "3.2.2", path = "services/aliyun-oss" }
reqsign-aws-core = { version = "3.3.1", path = "services/aws-core" }
reqsign-aws-v4 = { version = "3.4.1", path = "services/aws-v4" }
reqsign-aws-v4a = { version = "3.1.1", path = "services/aws-v4a" }
reqsign-aws-core = { version = "3.4.0", path = "services/aws-core" }
reqsign-aws-v4 = { version = "3.5.0", path = "services/aws-v4" }
reqsign-aws-v4a = { version = "3.2.0", path = "services/aws-v4a" }
reqsign-azure-storage = { version = "3.3.2", path = "services/azure-storage" }
reqsign-command-execute-tokio = { version = "3.0.9", path = "context/command-execute-tokio" }
reqsign-core = { version = "3.3.4", path = "core" }
reqsign-file-read-tokio = { version = "3.0.9", path = "context/file-read-tokio" }
reqsign-google = { version = "3.3.1", path = "services/google" }
reqsign-google = { version = "3.4.0", path = "services/google" }
reqsign-http-send-reqwest = { version = "4.0.9", path = "context/http-send-reqwest" }
reqsign-huaweicloud-obs = { version = "3.0.9", path = "services/huaweicloud-obs" }
reqsign-huaweicloud-obs = { version = "3.1.0", path = "services/huaweicloud-obs" }
reqsign-openstack-keystone = { version = "3.0.1", path = "services/openstack-keystone" }
reqsign-oracle = { version = "3.0.9", path = "services/oracle" }
reqsign-tencent-cos = { version = "3.0.9", path = "services/tencent-cos" }
reqsign-volcengine-tos = { version = "3.1.5", path = "services/volcengine-tos" }
reqsign-oracle = { version = "3.1.0", path = "services/oracle" }
reqsign-tencent-cos = { version = "3.1.0", path = "services/tencent-cos" }
reqsign-volcengine-tos = { version = "3.2.0", path = "services/volcengine-tos" }

# Crates.io dependencies
aes-gcm = "0.11"
Expand Down
2 changes: 1 addition & 1 deletion services/aws-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-aws-core"
version = "3.3.1"
version = "3.4.0"

description = "Shared AWS credential and request canonicalization support for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/aws-v4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-aws-v4"
version = "3.4.1"
version = "3.5.0"

description = "AWS SigV4 signing implementation for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/aws-v4a/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-aws-v4a"
version = "3.1.1"
version = "3.2.0"

description = "AWS SigV4a signing implementation for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/google/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-google"
version = "3.3.1"
version = "3.4.0"

description = "Google Cloud Platform signing implementation for reqsign."

Expand Down
55 changes: 39 additions & 16 deletions services/google/src/sign_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ impl TokenCache {

#[derive(Default)]
struct TokenState {
cache: Mutex<TokenCache>,
// Cache operations never await; a synchronous mutex preserves unwind safety.
cache: SyncMutex<TokenCache>,
refresh_locks: RefreshLockRegistry,
}

Expand Down Expand Up @@ -285,8 +286,12 @@ impl RequestSigner {
}

#[cfg(test)]
async fn cache_len(&self) -> usize {
self.token_state.cache.lock().await.len()
fn cache_len(&self) -> usize {
self.token_state
.cache
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.len()
}

#[cfg(test)]
Expand All @@ -304,13 +309,25 @@ impl RequestSigner {
scope: scope.clone(),
};

if let Some(token) = self.token_state.cache.lock().await.find(&key) {
if let Some(token) = self
.token_state
.cache
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.find(&key)
{
return Ok(token);
}

let refresh_lock = self.token_state.refresh_lock(&key);
let _refresh_guard = refresh_lock.lock.lock().await;
if let Some(token) = self.token_state.cache.lock().await.find(&key) {
if let Some(token) = self
.token_state
.cache
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
.find(&key)
{
return Ok(token);
}

Expand All @@ -324,7 +341,7 @@ impl RequestSigner {
self.token_state
.cache
.lock()
.await
.unwrap_or_else(std::sync::PoisonError::into_inner)
.insert(key, token.clone());
}
Ok(token)
Expand Down Expand Up @@ -877,6 +894,12 @@ mod tests {
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};

// Preserve compatibility with callers that capture a signer across catch_unwind.
const _: fn() = || {
fn assert_unwind_safe<T: std::panic::UnwindSafe + std::panic::RefUnwindSafe>() {}
assert_unwind_safe::<RequestSigner>();
};

const RAW_QUERY: &str = "slash=%2F&hash=%23&amp=%26&equals=%3D&space=%20&encoded-plus=%2B&literal-plus=+&double=%252F&dup=first&dup=second&=empty-key&empty=&flag&flag=&";

#[derive(Debug, Default)]
Expand Down Expand Up @@ -1609,7 +1632,7 @@ mod tests {
.sign_request(&ctx, &mut parts, Some(&credential), None)
.await?;
assert_eq!(parts.headers[header::AUTHORIZATION], expected);
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
}

assert_eq!(http.calls.load(Ordering::SeqCst), 2);
Expand All @@ -1635,7 +1658,7 @@ mod tests {
.sign_request(&ctx, &mut parts, Some(&credential), None)
.await?;
assert_eq!(parts.headers[header::AUTHORIZATION], "Bearer short-lived");
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
assert_eq!(http.calls.load(Ordering::SeqCst), 1);
Ok(())
}
Expand All @@ -1661,7 +1684,7 @@ mod tests {
.await
.expect_err("token shorter than operation headroom must be rejected");
assert_eq!(err.kind(), ErrorKind::CredentialInvalid);
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
assert_eq!(http.calls.load(Ordering::SeqCst), 1);
Ok(())
}
Expand Down Expand Up @@ -1744,7 +1767,7 @@ mod tests {
first.await.expect("first task must not panic")?;
second.await.expect("second task must not panic")?;
assert_eq!(http.calls.load(Ordering::SeqCst), 2);
assert_eq!(signer.cache_len().await, 2);
assert_eq!(signer.cache_len(), 2);
assert_eq!(signer.refresh_lock_len(), 0);
Ok(())
}
Expand Down Expand Up @@ -1777,7 +1800,7 @@ mod tests {
assert_eq!(err.kind(), ErrorKind::Unexpected);
assert!(err.is_retryable());
assert!(!format!("{err:?}").contains("sensitive-body"));
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
assert_eq!(signer.refresh_lock_len(), 0);

signer
Expand All @@ -1787,7 +1810,7 @@ mod tests {
parts.headers[header::AUTHORIZATION],
"Bearer recovered-token"
);
assert_eq!(signer.cache_len().await, 1);
assert_eq!(signer.cache_len(), 1);
assert_eq!(http.calls.load(Ordering::SeqCst), 2);
Ok(())
}
Expand Down Expand Up @@ -1847,7 +1870,7 @@ mod tests {
.expect_err("task must be cancelled")
.is_cancelled()
);
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
assert_eq!(signer.refresh_lock_len(), 0);

http.release.release(1);
Expand All @@ -1865,7 +1888,7 @@ mod tests {
parts.headers[header::AUTHORIZATION],
"Bearer after-cancel-token"
);
assert_eq!(signer.cache_len().await, 1);
assert_eq!(signer.cache_len(), 1);
assert_eq!(signer.refresh_lock_len(), 0);
Ok(())
}
Expand Down Expand Up @@ -1957,7 +1980,7 @@ mod tests {
}

assert_eq!(http.calls.load(Ordering::SeqCst), 1);
assert_eq!(signer.cache_len().await, 1);
assert_eq!(signer.cache_len(), 1);
Ok(())
}

Expand Down Expand Up @@ -1992,7 +2015,7 @@ mod tests {
.contains("X-Goog-Signature=")
);
assert_eq!(http.calls.load(Ordering::SeqCst), 0);
assert_eq!(signer.cache_len().await, 0);
assert_eq!(signer.cache_len(), 0);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion services/huaweicloud-obs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-huaweicloud-obs"
version = "3.0.9"
version = "3.1.0"

description = "Huawei Cloud OBS signing implementation for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-oracle"
version = "3.0.9"
version = "3.1.0"

description = "Oracle Cloud signing implementation for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/tencent-cos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-tencent-cos"
version = "3.0.9"
version = "3.1.0"

description = "Tencent Cloud COS signing implementation for reqsign."

Expand Down
2 changes: 1 addition & 1 deletion services/volcengine-tos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

[package]
name = "reqsign-volcengine-tos"
version = "3.1.5"
version = "3.2.0"

description = "Volcengine TOS signing implementation for reqsign."

Expand Down
Loading