From e6a2f336beaff8a212ae33e2895f33df94935da9 Mon Sep 17 00:00:00 2001 From: Boy van Amstel Date: Thu, 21 Jul 2011 18:45:53 +0200 Subject: [PATCH] Unfinished OpenID en Google Hybrid specs. --- oa-openid/Gemfile | 1 + .../lib/omniauth/strategies/google_hybrid.rb | 2 +- .../omniauth/strategies/google_hybrid_spec.rb | 36 ++++++++++- .../spec/omniauth/strategies/open_id_spec.rb | 64 ++++++++++++++++++- oa-openid/spec/spec_helper.rb | 13 ++++ 5 files changed, 111 insertions(+), 5 deletions(-) diff --git a/oa-openid/Gemfile b/oa-openid/Gemfile index 73a8e19..8b4c6c7 100644 --- a/oa-openid/Gemfile +++ b/oa-openid/Gemfile @@ -3,6 +3,7 @@ require File.expand_path('../lib/omniauth/version', __FILE__) source 'http://rubygems.org' gem 'oa-core', OmniAuth::Version::STRING, :path => '../oa-core' +gem 'oa-oauth', OmniAuth::Version::STRING, :path => '../oa-oauth' platforms :jruby do gem 'jruby-openssl', '~> 0.7' diff --git a/oa-openid/lib/omniauth/strategies/google_hybrid.rb b/oa-openid/lib/omniauth/strategies/google_hybrid.rb index fda1992..be3b1a4 100644 --- a/oa-openid/lib/omniauth/strategies/google_hybrid.rb +++ b/oa-openid/lib/omniauth/strategies/google_hybrid.rb @@ -1,6 +1,6 @@ require 'rack/openid' require 'omniauth/openid' -require File.expand_path('../../../../../oa-oauth/lib/omniauth/oauth', __FILE__) +require 'oauth' module OmniAuth module Strategies diff --git a/oa-openid/spec/omniauth/strategies/google_hybrid_spec.rb b/oa-openid/spec/omniauth/strategies/google_hybrid_spec.rb index 8de9a78..191bd94 100644 --- a/oa-openid/spec/omniauth/strategies/google_hybrid_spec.rb +++ b/oa-openid/spec/omniauth/strategies/google_hybrid_spec.rb @@ -1,6 +1,36 @@ require File.expand_path('../../../spec_helper', __FILE__) -require File.expand_path('../../../../../oa-oauth/lib/omniauth/oauth', __FILE__) +require 'rack/openid' +require 'omniauth/openid' +require 'oauth' +require 'openid/store/filesystem' -describe OmniAuth::Strategies::GoogleHybrid do - it "should be awesome" +describe OmniAuth::Strategies::GoogleHybrid, :type => :strategy do + + + include OmniAuth::Test::StrategyTestCase + + def strategy + [OmniAuth::Strategies::GoogleHybrid, nil, + :name => 'google_hybrid', + :identifier => 'https://www.google.com/accounts/o8/id', + :scope => ["https://www.google.com/m8/feeds/", "https://mail.google.com/mail/feed/atom/"], + :consumer_key => '[your key here]', + :consumer_secret => '[your secret here]'] + end + + before do + @identifier_url = 'https://www.google.com/accounts/o8/id' + # TODO: change this mock to actually return some sort of OpenID response + stub_request(:get, @identifier_url) + end + + describe 'get /auth/google_hybrid' do + before do + get '/auth/google_hybrid' + end + it 'should redirect to the Google OpenID login' do + #last_response.should be_redirect + #last_response.headers['Location'].should =~ %r{^#{@identifier_url}.*} + end + end end diff --git a/oa-openid/spec/omniauth/strategies/open_id_spec.rb b/oa-openid/spec/omniauth/strategies/open_id_spec.rb index bee4f89..5e63af1 100644 --- a/oa-openid/spec/omniauth/strategies/open_id_spec.rb +++ b/oa-openid/spec/omniauth/strategies/open_id_spec.rb @@ -1,6 +1,68 @@ require File.expand_path('../../../spec_helper', __FILE__) +require 'rack/openid' +require 'omniauth/openid' -describe OmniAuth::Strategies::OpenID do +describe OmniAuth::Strategies::OpenID, :type => :strategy do + + include OmniAuth::Test::StrategyTestCase + + def strategy + [OmniAuth::Strategies::OpenID] + end + + describe '/auth/open_id without an identifier URL' do + before do + get '/auth/open_id' + end + + it 'should respond with OK' do + last_response.should be_ok + end + + it 'should respond with HTML' do + last_response.content_type.should == 'text/html' + end + + it 'should render an identifier URL input' do + last_response.body.should =~ %r{]*#{OmniAuth::Strategies::OpenID::IDENTIFIER_URL_PARAMETER}} + end + end + + describe '/auth/open_id with an identifier URL' do + before do + @identifier_url = 'http://openid.example.com/user' + # TODO: change this mock to actually return some sort of OpenID response + get '/auth/open_id?openid_url=' + @identifier_url + end + + it 'should redirect to the OpenID identity URL' do + #last_response.should be_redirect + #last_response.headers['Location'].should =~ %r{^#{@identifier_url}.*} + end + +# it 'should tell the OpenID server to return to the callback URL' do +# return_to = CGI.escape(last_request.url + '/callback') +# last_response.headers['Location'].should =~ %r{[\?&]openid.return_to=#{return_to}} +# end + + end + +# describe 'followed by /auth/open_id/callback' do +# before do +# @identifier_url = 'http://me.example.org' +# # TODO: change this mock to actually return some sort of OpenID response +# stub_request(:get, @identifier_url) +# get '/auth/open_id/callback' +# end +# +# sets_an_auth_hash +# sets_provider_to 'open_id' +# sets_uid_to 'http://me.example.org' +# +# it 'should call through to the master app' do +# last_response.body.should == 'true' +# end +# end end diff --git a/oa-openid/spec/spec_helper.rb b/oa-openid/spec/spec_helper.rb index 9b95fdf..2f2d61c 100644 --- a/oa-openid/spec/spec_helper.rb +++ b/oa-openid/spec/spec_helper.rb @@ -12,3 +12,16 @@ RSpec.configure do |config| config.include Rack::Test::Methods config.extend OmniAuth::Test::StrategyMacros, :type => :strategy end + +def strategy_class + meta = self.class.metadata + while meta.key?(:example_group) + meta = meta[:example_group] + end + meta[:describes] +end + +def app + lambda{|env| [200, {}, ['Hello']]} +end +