From fa55ee8c3fa2c653fd36e6d631ace4db9fce04f5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 19 Sep 2022 19:51:24 +0200 Subject: [PATCH] chore: add cloudflare test case (#1721) --- ethers-etherscan/src/errors.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ethers-etherscan/src/errors.rs b/ethers-etherscan/src/errors.rs index 2ff4d0c6..f840cc57 100644 --- a/ethers-etherscan/src/errors.rs +++ b/ethers-etherscan/src/errors.rs @@ -47,3 +47,15 @@ pub enum EtherscanError { pub(crate) fn is_blocked_by_cloudflare_response(txt: &str) -> bool { txt.to_lowercase().contains("sorry, you have been blocked") } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_cloudflare_response() { + let resp = "\n\n\n\n \n\nAttention Required! | Cloudflare\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n
Please enable cookies.
\n
\n
\n

Sorry, you have been blocked

\n

You are unable to access polygonscan.com

\n
\n\n
\n
\n
\n \n \n \n
\n
\n
\n\n
\n
\n
\n

Why have I been blocked?

\n\n

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

\n
\n\n
\n

What can I do to resolve this?

\n\n

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.

\n
\n
\n
\n\n \n\n\n
\n
\n\n \n\n\n\n"; + + assert!(is_blocked_by_cloudflare_response(resp)); + } +}