aboutsummaryrefslogtreecommitdiff
path: root/src/garage/tests/bucket.rs
blob: 0dec3cfa89ca2dc3cb829866238d9e6f903fc3c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::common;
use crate::common::ext::CommandExt;
use aws_sdk_s3::model::BucketLocationConstraint;
use aws_sdk_s3::output::DeleteBucketOutput;

#[tokio::test]
async fn test_bucket_all() {
	let ctx = common::context();
	let bucket_name = "hello";

	{
		// Check bucket cannot be created if not authorized
		ctx.garage
			.command()
			.args(["key", "deny"])
			.args(["--create-bucket", &ctx.key.id])
			.quiet()
			.expect_success_output("Could not deny key to create buckets");

		// Try create bucket, should fail
		let r = ctx.client.create_bucket().bucket(bucket_name).send().await;
		assert!(r.is_err());
	}
	{
		// Now allow key to create bucket
		ctx.garage
			.command()
			.args(["key", "allow"])
			.args(["--create-bucket", &ctx.key.id])
			.quiet()
			.expect_success_output("Could not deny key to create buckets");

		// Create bucket
		//@TODO check with an invalid bucket name + with an already existing bucket
		let r = ctx
			.client
			.create_bucket()
			.bucket(bucket_name)
			.send()
			.await
			.unwrap();

		assert_eq!(r.location.unwrap(), "/hello");
	}
	{
		// List buckets
		let r = ctx.client.list_buckets().send().await.unwrap();
		assert!(r
			.buckets
			.as_ref()
			.unwrap()
			.iter()
			.filter(|x| x.name.as_ref().is_some())
			.any(|x| x.name.as_ref().unwrap() == "hello"));
	}
	{
		// Get its location
		let r = ctx
			.client
			.get_bucket_location()
			.bucket(bucket_name)
			.send()
			.await
			.unwrap();

		match r.location_constraint.unwrap() {
			BucketLocationConstraint::Unknown(v) if v.as_str() == "garage-integ-test" => (),
			_ => unreachable!("wrong region"),
		}
	}
	{
		// (Stub) check GetVersioning
		let r = ctx
			.client
			.get_bucket_versioning()
			.bucket(bucket_name)
			.send()
			.await
			.unwrap();

		assert!(r.status.is_none());
	}
	{
		// Delete bucket
		// @TODO add a check with a non-empty bucket and check failure
		let r = ctx
			.client
			.delete_bucket()
			.bucket(bucket_name)
			.send()
			.await
			.unwrap();

		assert_eq!(r, DeleteBucketOutput::builder().build());
	}
	{
		// Check bucket is deleted with List buckets
		let r = ctx.client.list_buckets().send().await.unwrap();
		assert!(!r
			.buckets
			.as_ref()
			.unwrap()
			.iter()
			.filter(|x| x.name.as_ref().is_some())
			.any(|x| x.name.as_ref().unwrap() == "hello"));
	}
}