mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-27 03:48:52 +03:00
feat: define interface for updating user secret
This commit is contained in:
parent
25b3d316db
commit
d4a080b5fc
2 changed files with 11 additions and 0 deletions
|
@ -128,6 +128,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||||
|
|
||||||
/// get a user's secret
|
/// get a user's secret
|
||||||
async fn get_secret(&self, username: &str) -> DBResult<Secret>;
|
async fn get_secret(&self, username: &str) -> DBResult<Secret>;
|
||||||
|
|
||||||
|
/// update a user's secret
|
||||||
|
async fn update_secret(&self, username: &str, secret: &str) -> DBResult<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
|
|
|
@ -33,6 +33,14 @@ pub async fn database_works<'a, T: MCDatabase>(db: &T, p: &Register<'a>) {
|
||||||
let secret = db.get_secret(&p.username).await.unwrap();
|
let secret = db.get_secret(&p.username).await.unwrap();
|
||||||
assert_eq!(secret.secret, p.secret, "user secret matches");
|
assert_eq!(secret.secret, p.secret, "user secret matches");
|
||||||
|
|
||||||
|
// testing update secret: setting secret = username
|
||||||
|
db.update_secret(p.username, p.username).await.unwrap();
|
||||||
|
let secret = db.get_secret(&p.username).await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
secret.secret, p.username,
|
||||||
|
"user secret matches username; as set by previous step"
|
||||||
|
);
|
||||||
|
|
||||||
// testing get_password
|
// testing get_password
|
||||||
|
|
||||||
// with username
|
// with username
|
||||||
|
|
Loading…
Reference in a new issue