Skip to content

Commit

Permalink
Added very basic specs for OpenID and Hybrid Protocol.
Browse files Browse the repository at this point in the history
I've uncommented the working existing OpenID specs and added a few todos.
For Hybrid Protocol to work it needs access to oa-oauth, so I've added
it to oa-openid's Gemfile.
  • Loading branch information
boyvanamstel committed Jul 21, 2011
1 parent e6a2f33 commit 09068e0
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 129 deletions.
65 changes: 46 additions & 19 deletions oa-openid/spec/omniauth/strategies/google_hybrid_spec.rb
Expand Up @@ -2,35 +2,62 @@
require 'rack/openid'
require 'omniauth/openid'
require 'oauth'
require 'openid/store/filesystem'

describe OmniAuth::Strategies::GoogleHybrid, :type => :strategy do
describe "OmniAuth::Strategies::GoogleHybrid" do


include OmniAuth::Test::StrategyTestCase

def strategy
[OmniAuth::Strategies::GoogleHybrid, nil,
def app
Rack::Builder.new {
use OmniAuth::Test::PhonySession
use OmniAuth::Builder do
provider :google_hybrid, 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]']
:consumer_secret => '[your secret here]'
end
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
}.to_app
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)
def session
last_request.env['rack.session']
end

describe 'get /auth/google_hybrid' do
before do
get '/auth/google_hybrid'

def expired_query_string
'openid=consumer&janrain_nonce=2011-07-21T20%3A14%3A56ZJ8LP3T&openid.assoc_handle=%7BHMAC-SHA1%7D%7B4e284c39%7D%7B9nvQeg%3D%3D%7D&openid.claimed_id=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.identity=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.op_endpoint=http%3A%2F%2Flocalhost%3A1123%2Fserver%2F%3Fopenid.success%3Dtrue&openid.response_nonce=2011-07-21T20%3A14%3A56Zf9gC8S&openid.return_to=http%3A%2F%2Flocalhost%3A8888%2FDevelopment%2FWordpress%2Fwp_openid%2F%3Fopenid%3Dconsumer%26janrain_nonce%3D2011-07-21T20%253A14%253A56ZJ8LP3T&openid.sig=GufV13SUJt8VgmSZ92jGZCFBEvQ%3D&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned'
end

describe 'followed by /auth/google_hybrid/callback' do
context 'successful' do
#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)
# get '/auth/google_hybrid/callback'
#end

it "should set provider to google_hybrid"
it "should create auth_hash based on sreg"
it "should create auth_hash based on ax"

it "should exchange OAuth request token for access token"

#it 'should call through to the master app' do
# last_response.body.should == 'true'
#end
end
it 'should redirect to the Google OpenID login' do
#last_response.should be_redirect
#last_response.headers['Location'].should =~ %r{^#{@identifier_url}.*}

context 'unsuccessful' do
describe 'returning with expired credentials' do
before do
get '/auth/google_hybrid/callback?' + expired_query_string
end
it 'it should redirect to invalid credentials' do
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{invalid_credentials}
end
end
end
end
end
148 changes: 51 additions & 97 deletions oa-openid/spec/omniauth/strategies/open_id_spec.rb
Expand Up @@ -10,6 +10,10 @@ def strategy
[OmniAuth::Strategies::OpenID]
end

def expired_query_string
'openid=consumer&janrain_nonce=2011-07-21T20%3A14%3A56ZJ8LP3T&openid.assoc_handle=%7BHMAC-SHA1%7D%7B4e284c39%7D%7B9nvQeg%3D%3D%7D&openid.claimed_id=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.identity=http%3A%2F%2Flocalhost%3A1123%2Fjohn.doe%3Fopenid.success%3Dtrue&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.op_endpoint=http%3A%2F%2Flocalhost%3A1123%2Fserver%2F%3Fopenid.success%3Dtrue&openid.response_nonce=2011-07-21T20%3A14%3A56Zf9gC8S&openid.return_to=http%3A%2F%2Flocalhost%3A8888%2FDevelopment%2FWordpress%2Fwp_openid%2F%3Fopenid%3Dconsumer%26janrain_nonce%3D2011-07-21T20%253A14%253A56ZJ8LP3T&openid.sig=GufV13SUJt8VgmSZ92jGZCFBEvQ%3D&openid.signed=assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned'
end

describe '/auth/open_id without an identifier URL' do
before do
get '/auth/open_id'
Expand All @@ -28,106 +32,56 @@ def strategy
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
#describe '/auth/open_id with an identifier URL' do
# context 'successful' 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?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
#end

it 'should redirect to the OpenID identity URL' do
#last_response.should be_redirect
#last_response.headers['Location'].should =~ %r{^#{@identifier_url}.*}
end
describe 'followed by /auth/open_id/callback' do
context 'successful' 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

# 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
it "should set provider to open_id"
it "should create auth_hash based on sreg"
it "should create auth_hash based on ax"

end
#it 'should call through to the master app' do
# last_response.body.should == 'true'
#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
context 'unsuccessful' do
describe 'returning with expired credentials' do
before do
get '/auth/open_id/callback?' + expired_query_string
end
it 'it should redirect to invalid credentials' do
last_response.should be_redirect
last_response.headers['Location'].should =~ %r{invalid_credentials}
end
end
end
end

end

# require File.dirname(__FILE__) + '/../../spec_helper'
#
# 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{<input[^>]*#{OmniAuth::Strategies::OpenID::IDENTIFIER_URL_PARAMETER}}
# end
# end
#
# describe '/auth/open_id with an identifier URL' 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?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
13 changes: 0 additions & 13 deletions oa-openid/spec/spec_helper.rb
Expand Up @@ -12,16 +12,3 @@
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

0 comments on commit 09068e0

Please sign in to comment.