redis master: rename mcaptcha

This commit is contained in:
Aravinth Manivannan 2021-07-19 16:56:24 +05:30
parent c02377d834
commit 22f1a4ccc0
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
4 changed files with 89 additions and 11 deletions

View file

@ -2,7 +2,7 @@
## Added:
- `Master` trait: provides methods to manage mcaptcha
- `Master` trait: provides methods to manage mCaptcha
- `MCaptcha::get_defense()`: returns the `MCaptcha` instance's defense
configuration

59
Cargo.lock generated
View file

@ -253,13 +253,14 @@ dependencies = [
[[package]]
name = "derive_more"
version = "0.99.14"
version = "0.99.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc7b9cef1e351660e5443924e4f43ab25fbbed3e9a5f052df3677deb4d6b320"
checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"rustc_version",
"syn",
]
@ -406,9 +407,9 @@ dependencies = [
[[package]]
name = "instant"
version = "0.1.9"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
checksum = "bee0328b1209d157ef001c94dd85b4f8f64139adb0eac2659f4b08382b2f474d"
dependencies = [
"cfg-if",
]
@ -427,9 +428,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.97"
version = "0.2.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790"
[[package]]
name = "libmcaptcha"
@ -631,6 +632,15 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pest"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
dependencies = [
"ucd-trie",
]
[[package]]
name = "pin-project-lite"
version = "0.2.7"
@ -783,6 +793,15 @@ version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "rustc_version"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee"
dependencies = [
"semver",
]
[[package]]
name = "ryu"
version = "1.0.5"
@ -795,6 +814,24 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "semver"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7"
dependencies = [
"pest",
]
[[package]]
name = "serde"
version = "1.0.126"
@ -909,9 +946,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.7.1"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fb2ed024293bb19f7a5dc54fe83bf86532a44c12a2bb8ba40d64a4509395ca2"
checksum = "98c8b05dc14c75ea83d63dd391100353789f5f24b8b3866542a5e85c8be8e985"
dependencies = [
"autocfg",
"bytes",
@ -945,6 +982,12 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ucd-trie"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicode-bidi"
version = "0.3.5"

View file

@ -28,7 +28,10 @@ pub mod redis;
#[cfg(feature = "full")]
/// Describes actor handler trait impls that are required by a cache implementation
pub trait Master:
actix::Actor + actix::Handler<messages::AddVisitor> + actix::Handler<messages::AddSite>
actix::Actor
+ actix::Handler<messages::AddVisitor>
+ actix::Handler<messages::AddSite>
+ actix::Handler<messages::Rename>
{
}

View file

@ -19,7 +19,7 @@ use actix::dev::*;
use tokio::sync::oneshot;
use crate::errors::*;
use crate::master::messages::{AddSite, AddVisitor};
use crate::master::messages::{AddSite, AddVisitor, Rename};
use crate::master::Master as MasterTrait;
use crate::redis::mcaptcha_redis::MCaptchaRedis;
use crate::redis::RedisConfig;
@ -76,10 +76,28 @@ impl Handler<AddSite> for Master {
}
}
impl Handler<Rename> for Master {
type Result = MessageResult<Rename>;
fn handle(&mut self, m: Rename, ctx: &mut Self::Context) -> Self::Result {
let (tx, rx) = oneshot::channel();
let con = self.redis.get_client();
let fut = async move {
let res = con.rename_captcha(&m.name, &m.rename_to).await;
let _ = tx.send(res);
}
.into_actor(self);
ctx.wait(fut);
MessageResult(rx)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::master::embedded::counter::tests::get_mcaptcha;
use crate::master::messages::RenameBuilder;
use crate::master::redis::master::Master;
use crate::redis::RedisConfig;
@ -88,6 +106,8 @@ mod tests {
#[actix_rt::test]
async fn redis_master_works() {
const CAPTCHA_NAME: &str = "REDIS_MASTER_CAPTCHA_TEST";
const RENAME_CAPTCHA_NAME: &str = "RENAME_REDIS_MASTER_CAPTCHA_TEST";
let master = Master::new(RedisConfig::Single(REDIS_URL.into())).await;
let sec_master = Master::new(RedisConfig::Single(REDIS_URL.into())).await;
let r = sec_master.unwrap().redis.get_client();
@ -96,6 +116,11 @@ mod tests {
let master = master.unwrap();
{
let _ = master.redis.get_client().delete_captcha(CAPTCHA_NAME).await;
let _ = master
.redis
.get_client()
.delete_captcha(RENAME_CAPTCHA_NAME)
.await;
}
let addr = master.start();
@ -118,6 +143,13 @@ mod tests {
actix::clock::sleep(timer_expire).await;
let visitors = r.get_visitors(CAPTCHA_NAME).await.unwrap();
assert_eq!(visitors, 0);
let rename = RenameBuilder::default()
.name(CAPTCHA_NAME.into())
.rename_to(RENAME_CAPTCHA_NAME.into())
.build()
.unwrap();
assert!(addr.send(rename).await.is_ok());
}
#[actix_rt::test]