mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: define interface for update_captcha_key
This commit is contained in:
@@ -144,6 +144,14 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
p: &CreateCaptcha,
|
p: &CreateCaptcha,
|
||||||
) -> DBResult<()>;
|
) -> DBResult<()>;
|
||||||
|
|
||||||
|
/// update captcha key; doesn't change metadata
|
||||||
|
async fn update_captcha_key(
|
||||||
|
&self,
|
||||||
|
username: &str,
|
||||||
|
old_key: &str,
|
||||||
|
new_key: &str,
|
||||||
|
) -> DBResult<()>;
|
||||||
|
|
||||||
/// Add levels to captcha
|
/// Add levels to captcha
|
||||||
async fn add_captcha_levels(
|
async fn add_captcha_levels(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -148,7 +148,19 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||||||
c2.description = p.username;
|
c2.description = p.username;
|
||||||
db.update_captcha_metadata(p.username, &c2).await.unwrap();
|
db.update_captcha_metadata(p.username, &c2).await.unwrap();
|
||||||
|
|
||||||
// delete captcha
|
// update captcha key; set key = username;
|
||||||
db.delete_captcha(p.username, c.key).await.unwrap();
|
db.update_captcha_key(p.username, c.key, p.username)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
// checking for captcha with old key; shouldn't exist
|
||||||
|
assert!(!db.captcha_exists(Some(p.username), c.key).await.unwrap());
|
||||||
|
// checking for captcha with new key; shouldn exist
|
||||||
|
assert!(db
|
||||||
|
.captcha_exists(Some(p.username), p.username)
|
||||||
|
.await
|
||||||
|
.unwrap());
|
||||||
|
|
||||||
|
// delete captcha; updated key = p.username so invoke delete with it
|
||||||
|
db.delete_captcha(p.username, p.username).await.unwrap();
|
||||||
assert!(!db.captcha_exists(Some(p.username), c.key).await.unwrap());
|
assert!(!db.captcha_exists(Some(p.username), c.key).await.unwrap());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user