-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.rs
More file actions
112 lines (91 loc) · 3.22 KB
/
Copy pathpatch.rs
File metadata and controls
112 lines (91 loc) · 3.22 KB
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
use binary_codec::{FromBytes, ToBytes};
use serde::{Deserialize, Serialize};
use serde_with::base64::{Base64, UrlSafe};
use serde_with::formats::Unpadded;
use serde_with::serde_as;
use crate::packets::body::post::BucketPermissions;
/// Change bucket permissions or ACL entries.
#[serde_as]
#[derive(FromBytes, ToBytes, Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct PatchRequestBody {
/// If toggled by flags, update the permissions of the bucket
#[toggled_by = "update_perm"]
permissions: Option<BucketPermissions>,
/// If toggled by flags, add the following ACL entries (user IDs/user certificate IDs) to the bucket (without overwriting existing ACL)
#[toggled_by = "acl_add"]
#[serde_as(as = "Option<Vec<Base64<UrlSafe, Unpadded>>>")]
#[dyn_length]
acl_add: Option<Vec<[u8; 16]>>,
/// If toggled by flags, remove the following ACL entries (user IDs/user certificate IDs) from the bucket
#[toggled_by = "acl_del"]
#[serde_as(as = "Option<Vec<Base64<UrlSafe, Unpadded>>>")]
#[dyn_length]
acl_del: Option<Vec<[u8; 16]>>,
}
#[cfg(test)]
mod tests {
use binary_codec::{BinaryDeserializer, BinarySerializer};
use crate::packets::request::PlabbleRequestPacket;
#[test]
fn can_serialize_and_deserialize_patch_request_permissions() {
let packet: PlabbleRequestPacket = toml::from_str(
r#"
version = 1
use_encryption = true
[header]
packet_type = "Patch"
id = "@test"
update_permissions = true
[body]
[body.permissions]
public_read = true
public_write = true
protected_delete = true
"#,
)
.unwrap();
let serialized = packet.to_bytes(None).unwrap();
let deserialized = PlabbleRequestPacket::from_bytes(&serialized, None).unwrap();
assert_eq!(packet, deserialized);
}
#[test]
fn can_serialize_and_deserialize_patch_request_acl_add() {
let packet: PlabbleRequestPacket = toml::from_str(
r#"
version = 1
use_encryption = true
[header]
packet_type = "Patch"
id = "@test"
add_to_acl = true
[body]
acl_add = ["AAAAAAAAAAAAAAAAAAAAAA"]
"#,
)
.unwrap();
let serialized = packet.to_bytes(None).unwrap();
let deserialized = PlabbleRequestPacket::from_bytes(&serialized, None).unwrap();
assert_eq!(packet, deserialized);
}
#[test]
fn can_serialize_and_deserialize_patch_request_acl_add_and_del() {
let packet: PlabbleRequestPacket = toml::from_str(
r#"
version = 1
use_encryption = true
[header]
packet_type = "Patch"
id = "@test"
add_to_acl = true
remove_from_acl = true
[body]
acl_add = ["AAAAAAAAAAAAAAAAAAAAAA"]
acl_del = ["AAAAAAAAAAAAAAAAAAAAAA"]
"#,
)
.unwrap();
let serialized = packet.to_bytes(None).unwrap();
let deserialized = PlabbleRequestPacket::from_bytes(&serialized, None).unwrap();
assert_eq!(packet, deserialized);
}
}