使用 open_id_authentication 插件时,如何在 RSpec 用户故事/Cucumber 中伪造 OpenID 登录 [英] How do I fake OpenID login in RSpec user story/Cucumber when using open_id_authentication plugin

查看:23
本文介绍了使用 open_id_authentication 插件时,如何在 RSpec 用户故事/Cucumber 中伪造 OpenID 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 Cucumber 场景,该场景要求我有一个登录用户——这通常很简单,但我只使用 OpenID 身份验证(对身份验证插件的简化).然而,在深入研究了 open_id_authentication 插件的胆量之后,我不确定如何在 Cucumber 中实现这一目标.

I'm trying to write a Cucumber scenario that requires me to have a logged in user - that would normally be quite simple but I'm only using OpenID authentication (curtosy of the authentication plugin). However after digging through the open_id_authentication plugins guts I'm not sure how I could achieve this within Cucumber.

推荐答案

我想出了一个办法,如果你把它放在你的 features/support/env.rb 中:

I've figured out a way, if you place this in your features/support/env.rb:

ActionController::Base.class_eval do
  private

  def begin_open_id_authentication(identity_url, options = {})
    yield OpenIdAuthentication::Result.new(:successful), identity_url, nil
  end 
end

然后您可以在适当的步骤中执行以下操作:

Then you can just do something like this in your appropriate step:

Given /^I am logged in as "(.*)"$/ do |name|
  user = User.find_by_name(user)
  post '/session', :openid_url => user.identity_url
  # Some assertions just to make sure our hack in env.rb is still working
  response.should redirect_to('/')
  flash[:notice].should eql('Logged in successfully')
end

我只是完全破坏了黄瓜功能的开放 id 身份验证,显然,如果我需要登录失败的实例,我可以根据提供的 identity_url 执行此操作.

I'm just completely clobbering the open id auth for the cucumber features, obviously if I need instances where there is failed login I could do that based on the supplied identity_url.

这篇关于使用 open_id_authentication 插件时,如何在 RSpec 用户故事/Cucumber 中伪造 OpenID 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆