From d4a080b5fc91c0ac7ebc44bd869aeb30477f8435 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 12 May 2022 10:20:41 +0530 Subject: [PATCH] feat: define interface for updating user secret --- db/db-core/src/lib.rs | 3 +++ db/db-core/src/tests.rs | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/db/db-core/src/lib.rs b/db/db-core/src/lib.rs index 5447e648..0ec37061 100644 --- a/db/db-core/src/lib.rs +++ b/db/db-core/src/lib.rs @@ -128,6 +128,9 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase { /// get a user's secret async fn get_secret(&self, username: &str) -> DBResult; + + /// update a user's secret + async fn update_secret(&self, username: &str, secret: &str) -> DBResult<()>; } #[derive(Clone, Debug, Deserialize, Serialize)] diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index a45f728e..3ef9548d 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -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(); 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 // with username