Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(storage/cos): Signature not match while query has upper cases #434

Merged
merged 1 commit into from
Apr 8, 2024
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
2 changes: 1 addition & 1 deletion src/tencent/cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn build_signature(
.map(|(k, v)| {
(
utf8_percent_encode(&k.to_lowercase(), &TENCENT_URI_ENCODE_SET).to_string(),
utf8_percent_encode(&v.to_lowercase(), &TENCENT_URI_ENCODE_SET).to_string(),
utf8_percent_encode(v, &TENCENT_URI_ENCODE_SET).to_string(),
)
})
.collect::<Vec<_>>();
Expand Down
35 changes: 35 additions & 0 deletions tests/tencent/cos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,38 @@ async fn test_list_bucket() -> Result<()> {
assert_eq!(StatusCode::OK, status);
Ok(())
}

#[tokio::test]
async fn test_list_bucket_with_upper_cases() -> Result<()> {
let signer = init_signer();
if signer.is_none() {
warn!("REQSIGN_TENCENT_COS_TEST is not set, skipped");
return Ok(());
}
let (loader, signer) = signer.unwrap();
let cred = loader.load().await?.unwrap();

let url = &env::var("REQSIGN_TENCENT_COS_URL").expect("env REQSIGN_TENCENT_COS_URL must set");

let mut req = Request::new("");
*req.method_mut() = http::Method::GET;
*req.uri_mut() = http::Uri::from_str(&format!("{url}?prefix=stage/1712557668-ZgPY8Ql4"))?;

signer
.sign(&mut req, &cred)
.expect("sign request must success");

debug!("signed request: {:?}", req);

let client = Client::new();
let resp = client
.execute(req.try_into()?)
.await
.expect("request must success");

let status = resp.status();
debug!("got response: {:?}", resp);
debug!("got response content: {}", resp.text().await?);
assert_eq!(StatusCode::OK, status);
Ok(())
}
Loading