如何使用 phpunit test 输入验证码数据

发布于 2024-11-07 01:35:03 字数 215 浏览 0 评论 0原文

是否可以通过phpunit测试输入验证码信息?

类似的东西

$this->type("recaptcha_reponse_field", "里面的信息");

我知道验证码是为了防止此类事情而创建的,但我确信有人曾经必须自动测试一个系统,该系统在提交表单之前需要验证码信息。

谢谢 啊~~~

Is it possible to enter the captcha information with phpunit tests?

something like

$this->type("recaptcha_reponse_field", "information inside");

I understand that captcha were created to prevent this kind of things, but i'm sure some1 out there once had to test a system automatically which needs captcha information before submiting the form.

Thanks
D~~~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白云悠悠 2024-11-14 01:35:03

你不能这样做,除非你 OCR 验证码图像。但这不再是一个测试:)

通常在服务器端实现某种绕过。在伪代码中,它看起来像:

if ($config->bypass_captcha) {
   if ($recaptcha_response_field == 'correct') {
       // do what normally happens after submit
   } else { 
       // do what normally happens on incorrect captcha
   }
} else {
  // call recaptcha API to perform the real check
}

然后您需要确保“bypass_captcha”永远不会在您的公共服务器上启用。

当然,还有其他方法 - 例如禁用给定 IP 地址(属于运行测试的主机)的验证码检查

You can't do that, unless you OCR the captcha image. But then that is no longer a test :)

Usually some kind of bypass is implemented on server side. In pseudocode it would look like:

if ($config->bypass_captcha) {
   if ($recaptcha_response_field == 'correct') {
       // do what normally happens after submit
   } else { 
       // do what normally happens on incorrect captcha
   }
} else {
  // call recaptcha API to perform the real check
}

Then you need to ensure that "bypass_captcha" is never enabled on any on your public servers.

Of course, there are other ways too - like disabling captcha check for a given IP address (that belongs to the host from which you run the test from)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文