Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimfeldblum committed Nov 3, 2024
1 parent a2451d1 commit 3388925
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/include/redismodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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<String> = 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;
Expand Down

0 comments on commit 3388925

Please sign in to comment.