mirror of
https://git.deuxfleurs.fr/Deuxfleurs/garage.git
synced 2024-11-22 08:01:02 +00:00
[test-presigned] Add API test for presigned requests
This commit is contained in:
parent
70622d02f8
commit
f5b245729f
3 changed files with 76 additions and 0 deletions
|
@ -59,6 +59,10 @@ impl CustomRequester {
|
||||||
vhost_style: false,
|
vhost_style: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn client(&self) -> &Client<HttpConnector, Body> {
|
||||||
|
&self.client
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RequestBuilder<'a> {
|
pub struct RequestBuilder<'a> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
mod list;
|
mod list;
|
||||||
mod multipart;
|
mod multipart;
|
||||||
mod objects;
|
mod objects;
|
||||||
|
mod presigned;
|
||||||
mod simple;
|
mod simple;
|
||||||
mod streaming_signature;
|
mod streaming_signature;
|
||||||
mod website;
|
mod website;
|
||||||
|
|
71
src/garage/tests/s3/presigned.rs
Normal file
71
src/garage/tests/s3/presigned.rs
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue