Skip to content

Commit

Permalink
Add Rule::Other to cover newly defined flags. #682 (#685)
Browse files Browse the repository at this point in the history
Fix bug of unhandled newly defined flags when call acl_getuser.
  • Loading branch information
garyhai committed Sep 28, 2022
1 parent 79fde68 commit c14b73f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions redis/src/acl.rs
Expand Up @@ -63,6 +63,11 @@ pub enum Rule {
/// Performs the following actions: `resetpass`, `resetkeys`, `off`, `-@all`.
/// The user returns to the same state it has immediately after its creation.
Reset,

/// Raw text of [`ACL rule`][1] that not enumerated above.
///
/// [1]: https://redis.io/docs/manual/security/acl
Other(String),
}

impl ToRedisArgs for Rule {
Expand Down Expand Up @@ -95,6 +100,8 @@ impl ToRedisArgs for Rule {
ResetKeys => out.write_arg(b"resetkeys"),

Reset => out.write_arg(b"reset"),

Other(rule) => out.write_arg(rule.as_bytes()),
};
}
}
Expand Down Expand Up @@ -162,7 +169,7 @@ impl FromRedisValue for AclInfo {
b"allkeys" => Ok(Rule::AllKeys),
b"allcommands" => Ok(Rule::AllCommands),
b"nopass" => Ok(Rule::NoPass),
_ => Err(not_convertible_error!(flag, "Expect a valid ACL flag")),
other => Ok(Rule::Other(String::from_utf8_lossy(other).into_owned())),
},
_ => Err(not_convertible_error!(
flag,
Expand Down Expand Up @@ -269,13 +276,17 @@ mod tests {
assert_args!(AllKeys, b"allkeys");
assert_args!(ResetKeys, b"resetkeys");
assert_args!(Reset, b"reset");
assert_args!(Other("resetchannels".to_owned()), b"resetchannels");
}

#[test]
fn test_from_redis_value() {
let redis_value = Value::Bulk(vec![
Value::Data("flags".into()),
Value::Bulk(vec![Value::Data("on".into())]),
Value::Bulk(vec![
Value::Data("on".into()),
Value::Data("allchannels".into()),
]),
Value::Data("passwords".into()),
Value::Bulk(vec![]),
Value::Data("commands".into()),
Expand All @@ -288,7 +299,7 @@ mod tests {
assert_eq!(
acl_info,
AclInfo {
flags: vec![Rule::On],
flags: vec![Rule::On, Rule::Other("allchannels".into())],
passwords: vec![],
commands: vec![
Rule::RemoveCategory("all".to_owned()),
Expand Down

0 comments on commit c14b73f

Please sign in to comment.