|
11 | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | | -use rabbitmq_http_client::requests::VirtualHostParams; |
15 | | -use rabbitmq_http_client::responses; |
16 | 14 | use rabbitmq_http_client::api::Client; |
| 15 | +use rabbitmq_http_client::requests; |
17 | 16 | use rabbitmq_http_client::requests::Permissions; |
| 17 | +use rabbitmq_http_client::requests::VirtualHostParams; |
| 18 | +use rabbitmq_http_client::responses; |
18 | 19 |
|
19 | 20 | mod test_helpers; |
20 | 21 | use crate::test_helpers::{PASSWORD, USERNAME, endpoint}; |
@@ -180,7 +181,95 @@ async fn test_async_list_topic_permissions_of() { |
180 | 181 | assert!(result1.is_ok()); |
181 | 182 |
|
182 | 183 | let result = rc.list_topic_permissions_of("guest").await; |
183 | | - assert!(result.is_ok(), "list_topic_permissions_of returned {result:?}"); |
| 184 | + assert!( |
| 185 | + result.is_ok(), |
| 186 | + "list_topic_permissions_of returned {result:?}" |
| 187 | + ); |
| 188 | + |
| 189 | + rc.delete_vhost(vh_params.name, false).await.unwrap(); |
| 190 | +} |
| 191 | + |
| 192 | +#[tokio::test] |
| 193 | +async fn test_async_declare_topic_permissions() { |
| 194 | + let endpoint = endpoint(); |
| 195 | + let rc = Client::new(&endpoint, USERNAME, PASSWORD); |
| 196 | + |
| 197 | + let vh_params = VirtualHostParams::named("test_declare_topic_permissions"); |
| 198 | + let _ = rc.delete_vhost(vh_params.name, false).await; |
| 199 | + let result1 = rc.create_vhost(&vh_params).await; |
| 200 | + assert!(result1.is_ok()); |
| 201 | + |
| 202 | + let params = requests::TopicPermissions { |
| 203 | + user: "guest", |
| 204 | + vhost: vh_params.name, |
| 205 | + exchange: "amq.topic", |
| 206 | + read: ".*", |
| 207 | + write: ".*", |
| 208 | + }; |
| 209 | + let result = rc.declare_topic_permissions(¶ms).await; |
| 210 | + assert!( |
| 211 | + result.is_ok(), |
| 212 | + "declare_topic_permissions returned {result:?}" |
| 213 | + ); |
| 214 | + |
| 215 | + // Verify that the topic permissions are set |
| 216 | + let topic_permissions = rc.list_topic_permissions_of("guest").await.unwrap(); |
| 217 | + assert!(topic_permissions.iter().any(|p| p.vhost == vh_params.name |
| 218 | + && p.exchange == "amq.topic" |
| 219 | + && p.read == ".*" |
| 220 | + && p.write == ".*")); |
| 221 | + |
| 222 | + rc.delete_vhost(vh_params.name, false).await.unwrap(); |
| 223 | +} |
| 224 | + |
| 225 | +#[tokio::test] |
| 226 | +async fn test_async_clear_topic_permissions() { |
| 227 | + let endpoint = endpoint(); |
| 228 | + let rc = Client::new(&endpoint, USERNAME, PASSWORD); |
| 229 | + |
| 230 | + let vh_params = VirtualHostParams::named("test_clear_topic_permissions"); |
| 231 | + let _ = rc.delete_vhost(vh_params.name, false).await; |
| 232 | + let result1 = rc.create_vhost(&vh_params).await; |
| 233 | + assert!(result1.is_ok()); |
| 234 | + |
| 235 | + let params = requests::TopicPermissions { |
| 236 | + user: "guest", |
| 237 | + vhost: vh_params.name, |
| 238 | + exchange: "amq.topic", |
| 239 | + read: ".*", |
| 240 | + write: ".*", |
| 241 | + }; |
| 242 | + let result = rc.declare_topic_permissions(¶ms).await; |
| 243 | + assert!( |
| 244 | + result.is_ok(), |
| 245 | + "declare_topic_permissions returned {result:?}" |
| 246 | + ); |
| 247 | + |
| 248 | + // Verify that the topic permissions are set |
| 249 | + let topic_permissions = rc.list_topic_permissions_of("guest").await.unwrap(); |
| 250 | + assert!(topic_permissions.iter().any(|p| p.vhost == vh_params.name |
| 251 | + && p.exchange == "amq.topic" |
| 252 | + && p.read == ".*" |
| 253 | + && p.write == ".*")); |
| 254 | + |
| 255 | + let result2 = rc |
| 256 | + .clear_topic_permissions(vh_params.name, "guest", false) |
| 257 | + .await; |
| 258 | + assert!( |
| 259 | + result2.is_ok(), |
| 260 | + "clear_topic_permissions returned {result2:?}" |
| 261 | + ); |
| 262 | + |
| 263 | + // Verify that the topic permissions are cleared |
| 264 | + let topic_permissions_after_clear = rc.list_topic_permissions_of("guest").await.unwrap(); |
| 265 | + assert!( |
| 266 | + !topic_permissions_after_clear |
| 267 | + .iter() |
| 268 | + .any(|p| p.vhost == vh_params.name |
| 269 | + && p.exchange == "amq.topic" |
| 270 | + && p.read == ".*" |
| 271 | + && p.write == ".*") |
| 272 | + ); |
184 | 273 |
|
185 | 274 | rc.delete_vhost(vh_params.name, false).await.unwrap(); |
186 | 275 | } |
0 commit comments