mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: define captcha_exists interface
This commit is contained in:
2
Makefile
2
Makefile
@@ -96,7 +96,7 @@ test: frontend-test frontend ## Run all available tests
|
|||||||
cd db/db-sqlx-postgres &&\
|
cd db/db-sqlx-postgres &&\
|
||||||
DATABASE_URL=${POSTGRES_DATABASE_URL}\
|
DATABASE_URL=${POSTGRES_DATABASE_URL}\
|
||||||
cargo test --no-fail-fast
|
cargo test --no-fail-fast
|
||||||
#./scripts/tests.sh
|
./scripts/tests.sh
|
||||||
# cargo test --all-features --no-fail-fast
|
# cargo test --all-features --no-fail-fast
|
||||||
|
|
||||||
xml-test-coverage: migrate ## Generate code coverage report in XML format
|
xml-test-coverage: migrate ## Generate code coverage report in XML format
|
||||||
|
|||||||
@@ -144,6 +144,13 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
captcha_key: &str,
|
captcha_key: &str,
|
||||||
levels: &[Level],
|
levels: &[Level],
|
||||||
) -> DBResult<()>;
|
) -> DBResult<()>;
|
||||||
|
|
||||||
|
/// check if captcha exists
|
||||||
|
async fn captcha_exists(
|
||||||
|
&self,
|
||||||
|
username: Option<&str>,
|
||||||
|
captcha_key: &str,
|
||||||
|
) -> DBResult<bool>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
||||||
|
|||||||
@@ -35,12 +35,12 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||||||
db.register(p).await.unwrap();
|
db.register(p).await.unwrap();
|
||||||
|
|
||||||
// testing get secret
|
// testing get secret
|
||||||
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
|
// testing update secret: setting secret = username
|
||||||
db.update_secret(p.username, p.username).await.unwrap();
|
db.update_secret(p.username, p.username).await.unwrap();
|
||||||
let secret = db.get_secret(&p.username).await.unwrap();
|
let secret = db.get_secret(p.username).await.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
secret.secret, p.username,
|
secret.secret, p.username,
|
||||||
"user secret matches username; as set by previous step"
|
"user secret matches username; as set by previous step"
|
||||||
@@ -131,6 +131,8 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||||||
"user was with empty email but email is set; so email should exsit"
|
"user was with empty email but email is set; so email should exsit"
|
||||||
);
|
);
|
||||||
|
|
||||||
db.create_captcha(&p.username, c).await.unwrap();
|
db.create_captcha(p.username, c).await.unwrap();
|
||||||
|
assert!(db.captcha_exists(None, c.key).await.unwrap());
|
||||||
|
assert!(db.captcha_exists(Some(p.username), c.key).await.unwrap());
|
||||||
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user