diff options
author | Alex <alex@adnab.me> | 2024-03-04 14:39:06 +0000 |
---|---|---|
committer | Alex <alex@adnab.me> | 2024-03-04 14:39:06 +0000 |
commit | a08ac4a3fd402c47013c3631505b0ec424cbb795 (patch) | |
tree | a1c7ae17e5100624349cf59fc6c86a6f6f234821 /src/garage | |
parent | e28599497702ab541f652d9d5ae097049b3b804d (diff) | |
parent | 2eb114f42225faec3f70d498fdd51a6e8952a396 (diff) | |
download | garage-main-0.8.x.tar.gz garage-main-0.8.x.zip |
Merge pull request 'Garage v0.8.7' (#758) from fix-presigned-0.8 into main-0.8.xmain-0.8.x
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/758
Diffstat (limited to 'src/garage')
-rw-r--r-- | src/garage/Cargo.toml | 2 | ||||
-rw-r--r-- | src/garage/tests/common/custom_requester.rs | 4 | ||||
-rw-r--r-- | src/garage/tests/s3/mod.rs | 1 | ||||
-rw-r--r-- | src/garage/tests/s3/presigned.rs | 71 |
4 files changed, 77 insertions, 1 deletions
diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml index cf214686..fb5d458b 100644 --- a/src/garage/Cargo.toml +++ b/src/garage/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "garage" -version = "0.8.6" +version = "0.8.7" authors = ["Alex Auvolat <alex@adnab.me>"] edition = "2018" license = "AGPL-3.0" diff --git a/src/garage/tests/common/custom_requester.rs b/src/garage/tests/common/custom_requester.rs index c931f6ef..f527557f 100644 --- a/src/garage/tests/common/custom_requester.rs +++ b/src/garage/tests/common/custom_requester.rs @@ -59,6 +59,10 @@ impl CustomRequester { vhost_style: false, } } + + pub fn client(&self) -> &Client<HttpConnector, Body> { + &self.client + } } pub struct RequestBuilder<'a> { diff --git a/src/garage/tests/s3/mod.rs b/src/garage/tests/s3/mod.rs index 623eb665..4ebc4914 100644 --- a/src/garage/tests/s3/mod.rs +++ b/src/garage/tests/s3/mod.rs @@ -1,6 +1,7 @@ mod list; mod multipart; mod objects; +mod presigned; mod simple; mod streaming_signature; mod website; diff --git a/src/garage/tests/s3/presigned.rs b/src/garage/tests/s3/presigned.rs new file mode 100644 index 00000000..cd720b3b --- /dev/null +++ b/src/garage/tests/s3/presigned.rs @@ -0,0 +1,71 @@ +use std::time::{Duration, SystemTime}; + +use crate::common; +use aws_sdk_s3::presigning::PresigningConfig; +use bytes::Bytes; +use hyper::{Body, Request}; + +const STD_KEY: &str = "hello world"; +const BODY: &[u8; 62] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + +#[tokio::test] +async fn test_presigned_url() { + let ctx = common::context(); + let bucket = ctx.create_bucket("presigned"); + + let etag = "\"46cf18a9b447991b450cad3facf5937e\""; + let body = Bytes::from(BODY.to_vec()); + + let psc = PresigningConfig::builder() + .start_time(SystemTime::now() - Duration::from_secs(60)) + .expires_in(Duration::from_secs(3600)) + .build() + .unwrap(); + + { + // PutObject + let req = ctx + .client + .put_object() + .bucket(&bucket) + .key(STD_KEY) + .presigned(psc.clone()) + .await + .unwrap(); + + let client = ctx.custom_request.client(); + let req = Request::builder() + .method("PUT") + .uri(req.uri()) + .body(body.clone().into()) + .unwrap(); + let res = client.request(req).await.unwrap(); + assert_eq!(res.status(), 200); + assert_eq!(res.headers().get("etag").unwrap(), etag); + } + + { + // GetObject + let req = ctx + .client + .get_object() + .bucket(&bucket) + .key(STD_KEY) + .presigned(psc) + .await + .unwrap(); + + let client = ctx.custom_request.client(); + let req = Request::builder() + .method("GET") + .uri(req.uri()) + .body(Body::empty()) + .unwrap(); + let res = client.request(req).await.unwrap(); + assert_eq!(res.status(), 200); + assert_eq!(res.headers().get("etag").unwrap(), etag); + + let body2 = hyper::body::to_bytes(res.into_body()).await.unwrap(); + assert_eq!(body, body2); + } +} |