Skip to content

Commit c14b73f

Browse files
authored
Add Rule::Other to cover newly defined flags. redis-rs#682 (redis-rs#685)
Fix bug of unhandled newly defined flags when call acl_getuser.
1 parent 79fde68 commit c14b73f

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

redis/src/acl.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ pub enum Rule {
6363
/// Performs the following actions: `resetpass`, `resetkeys`, `off`, `-@all`.
6464
/// The user returns to the same state it has immediately after its creation.
6565
Reset,
66+
67+
/// Raw text of [`ACL rule`][1] that not enumerated above.
68+
///
69+
/// [1]: https://redis.io/docs/manual/security/acl
70+
Other(String),
6671
}
6772

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

97102
Reset => out.write_arg(b"reset"),
103+
104+
Other(rule) => out.write_arg(rule.as_bytes()),
98105
};
99106
}
100107
}
@@ -162,7 +169,7 @@ impl FromRedisValue for AclInfo {
162169
b"allkeys" => Ok(Rule::AllKeys),
163170
b"allcommands" => Ok(Rule::AllCommands),
164171
b"nopass" => Ok(Rule::NoPass),
165-
_ => Err(not_convertible_error!(flag, "Expect a valid ACL flag")),
172+
other => Ok(Rule::Other(String::from_utf8_lossy(other).into_owned())),
166173
},
167174
_ => Err(not_convertible_error!(
168175
flag,
@@ -269,13 +276,17 @@ mod tests {
269276
assert_args!(AllKeys, b"allkeys");
270277
assert_args!(ResetKeys, b"resetkeys");
271278
assert_args!(Reset, b"reset");
279+
assert_args!(Other("resetchannels".to_owned()), b"resetchannels");
272280
}
273281

274282
#[test]
275283
fn test_from_redis_value() {
276284
let redis_value = Value::Bulk(vec![
277285
Value::Data("flags".into()),
278-
Value::Bulk(vec![Value::Data("on".into())]),
286+
Value::Bulk(vec![
287+
Value::Data("on".into()),
288+
Value::Data("allchannels".into()),
289+
]),
279290
Value::Data("passwords".into()),
280291
Value::Bulk(vec![]),
281292
Value::Data("commands".into()),
@@ -288,7 +299,7 @@ mod tests {
288299
assert_eq!(
289300
acl_info,
290301
AclInfo {
291-
flags: vec![Rule::On],
302+
flags: vec![Rule::On, Rule::Other("allchannels".into())],
292303
passwords: vec![],
293304
commands: vec![
294305
Rule::RemoveCategory("all".to_owned()),

0 commit comments

Comments
 (0)