如何使用 Spring Security 在应用程序中模拟功能测试的身份验证?
我为我正在开发的 Web 应用程序提供了一套 Selenium 驱动的功能测试。我最近与 Spring Security 集成作为处理身份验证的方法。我的所有功能测试现在自然都会失败,因为现在每个请求都被发送到登录屏幕而不是最初请求的页面。
当然,我可以采取很多方法来解决这个问题,但没有一种方法看起来特别有吸引力。将虚拟凭据硬编码到我的测试代码中,然后作为每个测试用例的一部分进行登录,这看起来丑陋、脆弱且不安全。添加某种应用程序级别开关来禁用出于测试目的的身份验证同样似乎是一个坏主意 - 任何可能在生产中禁用安全性的机会都是不可取的。
当然我不是第一个遇到这个问题的人。使用 Spring Security 为应用程序编写功能测试时处理身份验证的最佳方法是什么?
I have a suite of Selenium-driven functional tests for a web application I'm developing. I've recently integrated with Spring Security as a means of handling authentication. All of my functional tests now fail, naturally, given that every request is now taken to a login screen rather than the page that was originally requested.
There are many ways I can go about tackling this problem, of course, but none of them seem particularly appealing. Hard coding in dummy credentials into my testing code and then logging in as part of every test case seems ugly, fragile, and insecure. Adding in some kind of application level switch to disable authentication for test purposes likewise seems like a bad idea- any chance that security could be disabled in production is undesirable.
Surely I am not the first person to encounter this issue. What is the best means of handling authentication when writing functional tests for an application using Spring Security?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论