mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: fallabck to localhost when running tests
This commit is contained in:
@@ -42,7 +42,15 @@ pub async fn verify_pow(
|
|||||||
payload: web::Json<Work>,
|
payload: web::Json<Work>,
|
||||||
data: AppData,
|
data: AppData,
|
||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
|
#[cfg(not(test))]
|
||||||
let ip = req.connection_info().peer_addr().unwrap().to_string();
|
let ip = req.connection_info().peer_addr().unwrap().to_string();
|
||||||
|
// From actix-web docs:
|
||||||
|
// Will only return None when called in unit tests unless TestRequest::peer_addr is used.
|
||||||
|
//
|
||||||
|
// ref: https://docs.rs/actix-web/latest/actix_web/struct.HttpRequest.html#method.peer_addr
|
||||||
|
#[cfg(test)]
|
||||||
|
let ip = "127.0.1.1".into();
|
||||||
|
|
||||||
let key = payload.key.clone();
|
let key = payload.key.clone();
|
||||||
let res = data.captcha.verify_pow(payload.into_inner(), ip).await?;
|
let res = data.captcha.verify_pow(payload.into_inner(), ip).await?;
|
||||||
data.stats.record_solve(&data, &key).await?;
|
data.stats.record_solve(&data, &key).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user