Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rule::Other to cover newly defined flags. #682 #685

Merged
merged 5 commits into from Sep 28, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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_fmt(format_args!("{}", rule)),
garyhai marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
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).to_string())),
garyhai marked this conversation as resolved.
Show resolved Hide resolved
},
_ => 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