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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
use crate::common;
use hyper::{Method, StatusCode};
#[tokio::test]
async fn test_error_codes() {
let ctx = common::context();
let bucket = ctx.create_bucket("test-k2v-error-codes");
// Regular insert should work (code 204)
let res = ctx
.k2v
.request
.builder(bucket.clone())
.method(Method::PUT)
.path("root")
.query_param("sort_key", Some("test1"))
.body(b"Hello, world!".to_vec())
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::NO_CONTENT);
// Insert with trash causality token: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.method(Method::PUT)
.path("root")
.query_param("sort_key", Some("test1"))
.signed_header("x-garage-causality-token", "tra$sh")
.body(b"Hello, world!".to_vec())
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Search without partition key: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{},
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Search with start that is not in prefix: invalid request
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{"partition_key": "root", "prefix": "a", "start": "bx"},
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Search with invalid json: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.query_param("search", Option::<&str>::None)
.body(
br#"[
{"partition_key": "root"
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Batch insert with invalid causality token: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.body(
br#"[
{"pk": "root", "sk": "a", "ct": "tra$h", "v": "aGVsbG8sIHdvcmxkCg=="}
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Batch insert with invalid data: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.body(
br#"[
{"pk": "root", "sk": "a", "ct": null, "v": "aGVsbG8sIHdvcmx$Cg=="}
]"#
.to_vec(),
)
.method(Method::POST)
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
// Poll with invalid causality token: 400
let res = ctx
.k2v
.request
.builder(bucket.clone())
.path("root")
.query_param("sort_key", Some("test1"))
.query_param("causality_token", Some("tra$h"))
.query_param("timeout", Some("10"))
.signed_header("accept", "application/octet-stream")
.send()
.await
.unwrap();
assert_eq!(res.status(), StatusCode::BAD_REQUEST);
}
|