From 21825582e535d9e25a295f4d9a2561cc5f8ac918 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Tue, 9 Aug 2022 16:29:24 +0530 Subject: [PATCH] feat: fallabck to localhost when running tests --- src/api/v1/pow/verify_pow.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/api/v1/pow/verify_pow.rs b/src/api/v1/pow/verify_pow.rs index b8bfff46..94b9b038 100644 --- a/src/api/v1/pow/verify_pow.rs +++ b/src/api/v1/pow/verify_pow.rs @@ -42,7 +42,15 @@ pub async fn verify_pow( payload: web::Json, data: AppData, ) -> ServiceResult { + #[cfg(not(test))] 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 res = data.captcha.verify_pow(payload.into_inner(), ip).await?; data.stats.record_solve(&data, &key).await?;