From 3388925029df5f9ad030f388a786c8f54e62ce65 Mon Sep 17 00:00:00 2001 From: Ephraim Feldblum Date: Sun, 3 Nov 2024 18:20:58 +0200 Subject: [PATCH] tests --- src/include/redismodule.h | 1 + src/macros.rs | 4 ++-- test.sh | 2 +- tests/integration.rs | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/include/redismodule.h b/src/include/redismodule.h index b65a552b..d0597755 100644 --- a/src/include/redismodule.h +++ b/src/include/redismodule.h @@ -1326,6 +1326,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(CreateSubcommand); REDISMODULE_GET_API(SetCommandInfo); REDISMODULE_GET_API(SetCommandACLCategories); + REDISMODULE_GET_API(AddACLCategory); REDISMODULE_GET_API(SetModuleAttribs); REDISMODULE_GET_API(IsModuleNameBusy); REDISMODULE_GET_API(WrongArity); diff --git a/src/macros.rs b/src/macros.rs index 99ed2297..c8aac1bb 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -95,7 +95,7 @@ macro_rules! redis_command { } else if $mandatory_acl_categories != "" { $crate::raw::redis_log( $ctx, - "Warning: Redis version does not support ACL categories", + "Error: Redis version does not support ACL categories", ); return $crate::raw::Status::Err as c_int; } @@ -307,8 +307,8 @@ macro_rules! redis_module { )* $( - let categories = CString::new($module_acl_categories).unwrap(); if let Some(RM_AddACLCategory) = raw::RedisModule_AddACLCategory { + let categories = CString::new($module_acl_categories).unwrap(); if RM_AddACLCategory(ctx, categories.as_ptr()) == raw::Status::Err as c_int { raw::redis_log(ctx, &format!("Error: failed to add ACL categories `{}`", $module_acl_categories)); return raw::Status::Err as c_int; diff --git a/test.sh b/test.sh index cc391715..89e605c5 100755 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ #!/usr/bin/env sh -cargo test --all --all-targets --no-default-features +cargo test --all --all-targets --no-default-features --features min-redis-compatibility-version-7-4 diff --git a/tests/integration.rs b/tests/integration.rs index 114da8fc..8492c84b 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -329,6 +329,40 @@ fn test_get_current_user() -> Result<()> { Ok(()) } +#[test] +#[cfg( + feature = "min-redis-compatibility-version-7-4", +)] +fn test_set_acl_categories() -> Result<()> { + let port: u16 = 6490; + let _guards = vec![start_redis_server_with_module("acl", port) + .with_context(|| "failed to start redis server")?]; + let mut con = + get_redis_connection(port).with_context(|| "failed to connect to redis server")?; + + let res: Vec = redis::cmd("ACL").arg("CAT").query(&mut con)?; + assert!(res.contains(&"acl".to_owned())); + + Ok(()) +} + +#[test] +#[cfg( + feature = "min-redis-compatibility-version-8-0", +)] +fn test_set_acl_categories_commands() -> Result<()> { + let port: u16 = 6490; + let _guards = vec![start_redis_server_with_module("acl", port) + .with_context(|| "failed to start redis server")?]; + let mut con = + get_redis_connection(port).with_context(|| "failed to connect to redis server")?; + + let res: Vec = redis::cmd("ACL").arg("CAT").arg("acl").query(&mut con)?; + assert!(res.contains(&"verify_key_access_for_user".to_owned()) && res.contains(&"get_current_user".to_owned())); + + Ok(()) +} + #[test] fn test_verify_acl_on_user() -> Result<()> { let port: u16 = 6491;