简体   繁体   English

如何在Play2上使用OpenId对应用程序进行功能测试?

[英]How to functionally test an application with OpenId on Play2?

Let's say the app is protected with OpenId login (and only OpenId). 假设该应用受OpenId登录(仅OpenId)保护。 Once the user has successfully authenticated via OpenId, I set an attribute in the session like this : 一旦用户通过OpenId成功进行身份验证,就可以在会话中设置如下属性:

 Redirect(routes.Application.index).withSession('email -> userinfo.email)

Now, since a lot of the apps functionality relies on Javascript, the tests must be run on Selenium/Fluentlenium. 现在,由于许多应用程序功能都依赖Javascript,因此测试必须在Selenium / Fluentlenium上运行。 How can I fake a connected user in my tests? 如何在测试中伪造连接的用户?

EDIT : As answered below, creating a user in the OpenId provider is not really an answer for two reasons: 编辑:正如下面回答的那样,出于两个原因,在OpenId提供程序中创建用户并不是真正的答案:

  1. The OpenID provider is Google and Google only. OpenID提供程序仅适用于Google和Google。
  2. I do not want to test if Google's OpenId is working as they probably test it way better than I ever could, I want to test the functionality of my app. 我不想测试Google的OpenId是否正常工作,因为他们可能会比以往更好地测试它,我想测试我的应用程序的功能。

I would rather like to fake a connected user by manually setting the email attribute in session in fluentlenium but I have found no API to do this. 我想通过在fluentlenium中的会话中手动设置email属性来伪造已连接的用户,但我发现没有API可以做到这一点。

We have done this by extracting the OpenId integration into a trait which has got a real implementation (google) and a dummy one, in our case with a hardcoded user that gets logged in, this has also been useful to be able to use the app in devel mode without actually having to log in for real. 为此,我们将OpenId集成提取为一个特征,该特征具有一个实际的实现(google)和一个虚拟的特征(在我们的示例中,该用户具有已登录的硬编码用户),这对于能够使用该应用程序也非常有用在开发模式下,无需实际登录。

The actual trait is as simple as this: 实际特征就是这样简单:

sealed trait AuthLogic {
  def login: Action[AnyContent]
  def callback: Action[AnyContent]
}

Which is then implemented by the google one and the dummy, the actual instance used is decided upon first access (lazy val) by a configuration flag. 然后由google和假人实现,使用的实际实例由配置标志在首次访问(延迟val)时决定。 All the dummy one does is redirect directly from login to callback, and then faking a login inside the callback implementation. 虚拟用户所做的所有事情就是直接从登录名重定向到回调,然后在回调实现中伪造一个登录名。

Hope this helped! 希望这对您有所帮助!

Why don't you create test account in OpenId supplier and use its username/password in your selenium scripts? 为什么不在OpenId供应商中创建测试帐户,并在硒脚本中使用其用户名/密码?

Testing in selenium/Fluentlenium concludes that your application is quite integrated (OpenID is setup as you mentioned, I suspect that DB is connected as well). 在selenium / Fluentlenium中进行的测试得出的结论是您的应用程序已完全集成(如您提到的那样设置了OpenID,我怀疑DB也已连接)。

I've never used fluentlenium, but I assume you have access to the underlying selenium webdriver? 我从未使用过fluentlenium,但我想您可以访问底层的硒webdriver? If so, can't you just set a cookie? 如果是这样,您是否不能设置cookie? You'll just need to save a valid, signed session cookie. 您只需要保存一个有效的,已签名的会话cookie。

http://docs.seleniumhq.org/docs/03_webdriver.jsp#cookies http://docs.seleniumhq.org/docs/03_webdriver.jsp#cookies

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM