mirror of
https://github.com/omniauth/omniauth.git
synced 2022-11-09 12:31:49 -05:00
Fix RuboCop offenses
This commit is contained in:
parent
e8f5c67627
commit
d9683a8880
21 changed files with 592 additions and 555 deletions
|
|
@ -17,7 +17,7 @@ module OmniAuth
|
|||
autoload :FailureEndpoint, 'omniauth/failure_endpoint'
|
||||
|
||||
def self.strategies
|
||||
@@strategies ||= []
|
||||
@strategies ||= []
|
||||
end
|
||||
|
||||
class Configuration
|
||||
|
|
@ -25,39 +25,29 @@ module OmniAuth
|
|||
|
||||
def self.default_logger
|
||||
logger = Logger.new(STDOUT)
|
||||
logger.progname = "omniauth"
|
||||
logger.progname = 'omniauth'
|
||||
logger
|
||||
end
|
||||
|
||||
@@defaults = {
|
||||
:camelizations => {},
|
||||
:path_prefix => '/auth',
|
||||
:on_failure => OmniAuth::FailureEndpoint,
|
||||
:failure_raise_out_environments => ['development'],
|
||||
:before_request_phase => nil,
|
||||
:before_callback_phase => nil,
|
||||
:before_options_phase => nil,
|
||||
:form_css => Form::DEFAULT_CSS,
|
||||
:test_mode => false,
|
||||
:logger => default_logger,
|
||||
:allowed_request_methods => [:get, :post],
|
||||
:mock_auth => {
|
||||
:default => AuthHash.new(
|
||||
'provider' => 'default',
|
||||
'uid' => '1234',
|
||||
'info' => {
|
||||
'name' => 'Bob Example'
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def self.defaults
|
||||
@@defaults
|
||||
@defaults ||= {
|
||||
:camelizations => {},
|
||||
:path_prefix => '/auth',
|
||||
:on_failure => OmniAuth::FailureEndpoint,
|
||||
:failure_raise_out_environments => ['development'],
|
||||
:before_request_phase => nil,
|
||||
:before_callback_phase => nil,
|
||||
:before_options_phase => nil,
|
||||
:form_css => Form::DEFAULT_CSS,
|
||||
:test_mode => false,
|
||||
:logger => default_logger,
|
||||
:allowed_request_methods => [:get, :post],
|
||||
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Bob Example'})}
|
||||
}
|
||||
end
|
||||
|
||||
def initialize
|
||||
@@defaults.each_pair{|k,v| self.send("#{k}=",v)}
|
||||
self.class.defaults.each_pair { |k, v| send("#{k}=", v) }
|
||||
end
|
||||
|
||||
def on_failure(&block)
|
||||
|
|
@ -92,7 +82,7 @@ module OmniAuth
|
|||
end
|
||||
end
|
||||
|
||||
def add_mock(provider, mock={})
|
||||
def add_mock(provider, mock = {})
|
||||
# Stringify keys recursively one level.
|
||||
mock.keys.each do |key|
|
||||
mock[key.to_s] = mock.delete(key)
|
||||
|
|
@ -106,11 +96,11 @@ module OmniAuth
|
|||
end
|
||||
|
||||
# Merge with the default mock and ensure provider is correct.
|
||||
mock = self.mock_auth[:default].dup.merge(mock)
|
||||
mock["provider"] = provider.to_s
|
||||
mock = mock_auth[:default].dup.merge(mock)
|
||||
mock['provider'] = provider.to_s
|
||||
|
||||
# Add it to the mocks.
|
||||
self.mock_auth[provider.to_sym] = mock
|
||||
mock_auth[provider.to_sym] = mock
|
||||
end
|
||||
|
||||
# This is a convenience method to be used by strategy authors
|
||||
|
|
@ -120,7 +110,7 @@ module OmniAuth
|
|||
# @param name [String] The underscored name, e.g. `oauth`
|
||||
# @param camelized [String] The properly camelized name, e.g. 'OAuth'
|
||||
def add_camelization(name, camelized)
|
||||
self.camelizations[name.to_s] = camelized.to_s
|
||||
camelizations[name.to_s] = camelized.to_s
|
||||
end
|
||||
|
||||
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
|
||||
|
|
@ -154,8 +144,8 @@ module OmniAuth
|
|||
target = hash.dup
|
||||
|
||||
other_hash.keys.each do |key|
|
||||
if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash
|
||||
target[key] = deep_merge(target[key],other_hash[key])
|
||||
if other_hash[key].is_a?(::Hash) && hash[key].is_a?(::Hash)
|
||||
target[key] = deep_merge(target[key], other_hash[key])
|
||||
next
|
||||
end
|
||||
|
||||
|
|
@ -169,7 +159,7 @@ module OmniAuth
|
|||
return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
|
||||
|
||||
if first_letter_in_uppercase
|
||||
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
||||
word.to_s.gsub(/\/(.?)/) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
|
||||
else
|
||||
word.first + camelize(word)[1..-1]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ module OmniAuth
|
|||
# is able to provide into the InfoHash (stored as the `'info'`
|
||||
# key).
|
||||
class AuthHash < Hashie::Mash
|
||||
def self.subkey_class; Hashie::Mash end
|
||||
def self.subkey_class
|
||||
Hashie::Mash
|
||||
end
|
||||
|
||||
# Tells you if this is considered to be a valid
|
||||
# OmniAuth AuthHash. The requirements for that
|
||||
|
|
@ -25,7 +27,9 @@ module OmniAuth
|
|||
end
|
||||
|
||||
class InfoHash < Hashie::Mash
|
||||
def self.subkey_class; Hashie::Mash end
|
||||
def self.subkey_class
|
||||
Hashie::Mash
|
||||
end
|
||||
|
||||
def name
|
||||
return self[:name] if self[:name]
|
||||
|
|
@ -35,11 +39,10 @@ module OmniAuth
|
|||
nil
|
||||
end
|
||||
|
||||
def name?; !!name end
|
||||
|
||||
def valid?
|
||||
name?
|
||||
def name?
|
||||
!!name
|
||||
end
|
||||
alias_method :valid?, :name?
|
||||
|
||||
def to_hash
|
||||
hash = super
|
||||
|
|
|
|||
|
|
@ -22,22 +22,22 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def raise_out!
|
||||
raise env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type'])
|
||||
fail(env['omniauth.error'] || OmniAuth::Error.new(env['omniauth.error.type']))
|
||||
end
|
||||
|
||||
def redirect_to_failure
|
||||
message_key = env['omniauth.error.type']
|
||||
new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{message_key}#{origin_query_param}#{strategy_name_query_param}"
|
||||
Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish
|
||||
Rack::Response.new(['302 Moved'], 302, 'Location' => new_path).finish
|
||||
end
|
||||
|
||||
def strategy_name_query_param
|
||||
return "" unless env['omniauth.error.strategy']
|
||||
return '' unless env['omniauth.error.strategy']
|
||||
"&strategy=#{env['omniauth.error.strategy'].name}"
|
||||
end
|
||||
|
||||
def origin_query_param
|
||||
return "" unless env['omniauth.origin']
|
||||
return '' unless env['omniauth.origin']
|
||||
"&origin=#{Rack::Utils.escape(env['omniauth.origin'])}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
81
lib/omniauth/form.css
Normal file
81
lib/omniauth/form.css
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
body {
|
||||
background: #ccc;
|
||||
font-family: "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin: 30px auto 0px;
|
||||
font-size: 18px;
|
||||
padding: 10px 10px 15px;
|
||||
background: #555;
|
||||
color: white;
|
||||
width: 320px;
|
||||
border: 10px solid #444;
|
||||
border-bottom: 0;
|
||||
-moz-border-radius-topleft: 10px;
|
||||
-moz-border-radius-topright: 10px;
|
||||
-webkit-border-top-left-radius: 10px;
|
||||
-webkit-border-top-right-radius: 10px;
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
h1, form {
|
||||
-moz-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
|
||||
-webkit-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
form {
|
||||
background: white;
|
||||
border: 10px solid #eee;
|
||||
border-top: 0;
|
||||
padding: 20px;
|
||||
margin: 0px auto 40px;
|
||||
width: 300px;
|
||||
-moz-border-radius-bottomleft: 10px;
|
||||
-moz-border-radius-bottomright: 10px;
|
||||
-webkit-border-bottom-left-radius: 10px;
|
||||
-webkit-border-bottom-right-radius: 10px;
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
input {
|
||||
font-size: 18px;
|
||||
padding: 4px 8px;
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
input#identifier, input#openid_url {
|
||||
background: url(http://openid.net/login-bg.gif) no-repeat;
|
||||
background-position: 0 50%;
|
||||
padding-left: 18px;
|
||||
}
|
||||
|
||||
button {
|
||||
font-size: 22px;
|
||||
padding: 4px 8px;
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
border: 1px solid #ccc;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
fieldset input {
|
||||
width: 260px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
|
@ -1,103 +1,21 @@
|
|||
module OmniAuth
|
||||
class Form
|
||||
DEFAULT_CSS = <<-CSS
|
||||
body {
|
||||
background: #ccc;
|
||||
font-family: "Lucida Grande", "Lucida Sans", Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin: 30px auto 0px;
|
||||
font-size: 18px;
|
||||
padding: 10px 10px 15px;
|
||||
background: #555;
|
||||
color: white;
|
||||
width: 320px;
|
||||
border: 10px solid #444;
|
||||
border-bottom: 0;
|
||||
-moz-border-radius-topleft: 10px;
|
||||
-moz-border-radius-topright: 10px;
|
||||
-webkit-border-top-left-radius: 10px;
|
||||
-webkit-border-top-right-radius: 10px;
|
||||
border-top-left-radius: 10px;
|
||||
border-top-right-radius: 10px;
|
||||
}
|
||||
|
||||
h1, form {
|
||||
-moz-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
|
||||
-webkit-box-shadow: 2px 2px 7px rgba(0,0,0,0.3);
|
||||
}
|
||||
|
||||
form {
|
||||
background: white;
|
||||
border: 10px solid #eee;
|
||||
border-top: 0;
|
||||
padding: 20px;
|
||||
margin: 0px auto 40px;
|
||||
width: 300px;
|
||||
-moz-border-radius-bottomleft: 10px;
|
||||
-moz-border-radius-bottomright: 10px;
|
||||
-webkit-border-bottom-left-radius: 10px;
|
||||
-webkit-border-bottom-right-radius: 10px;
|
||||
border-bottom-left-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
input {
|
||||
font-size: 18px;
|
||||
padding: 4px 8px;
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
width: 280px;
|
||||
}
|
||||
|
||||
input#identifier, input#openid_url {
|
||||
background: url(http://openid.net/login-bg.gif) no-repeat;
|
||||
background-position: 0 50%;
|
||||
padding-left: 18px;
|
||||
}
|
||||
|
||||
button {
|
||||
font-size: 22px;
|
||||
padding: 4px 8px;
|
||||
display: block;
|
||||
margin: 20px auto 0;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
border: 1px solid #ccc;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
fieldset input {
|
||||
width: 260px;
|
||||
font-size: 16px;
|
||||
}
|
||||
CSS
|
||||
class Form # rubocop:disable ClassLength
|
||||
DEFAULT_CSS = File.read(File.expand_path('../form.css', __FILE__))
|
||||
|
||||
attr_accessor :options
|
||||
|
||||
def initialize(options = {})
|
||||
options[:title] ||= "Authentication Info Required"
|
||||
options[:header_info] ||= ""
|
||||
options[:title] ||= 'Authentication Info Required'
|
||||
options[:header_info] ||= ''
|
||||
self.options = options
|
||||
|
||||
@html = ""
|
||||
@html = ''
|
||||
@with_custom_button = false
|
||||
@footer = nil
|
||||
header(options[:title],options[:header_info])
|
||||
header(options[:title], options[:header_info])
|
||||
end
|
||||
|
||||
def self.build(options = {},&block)
|
||||
def self.build(options = {}, &block)
|
||||
form = OmniAuth::Form.new(options)
|
||||
if block.arity > 0
|
||||
yield form
|
||||
|
|
@ -140,12 +58,12 @@ module OmniAuth
|
|||
|
||||
def fieldset(legend, options = {}, &block)
|
||||
@html << "\n<fieldset#{" style='#{options[:style]}'" if options[:style]}#{" id='#{options[:id]}'" if options[:id]}>\n <legend>#{legend}</legend>\n"
|
||||
self.instance_eval(&block)
|
||||
instance_eval(&block)
|
||||
@html << "\n</fieldset>"
|
||||
self
|
||||
end
|
||||
|
||||
def header(title,header_info)
|
||||
def header(title, header_info)
|
||||
@html << <<-HTML
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
|
@ -181,10 +99,10 @@ module OmniAuth
|
|||
|
||||
def to_response
|
||||
footer
|
||||
Rack::Response.new(@html, 200, {"content-type" => "text/html"}).finish
|
||||
Rack::Response.new(@html, 200, 'content-type' => 'text/html').finish
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def css
|
||||
"\n<style type='text/css'>#{OmniAuth.config.form_css}</style>"
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ module OmniAuth
|
|||
option :uid_field, :email
|
||||
|
||||
def request_phase
|
||||
form = OmniAuth::Form.new(:title => "User Info", :url => callback_path)
|
||||
form = OmniAuth::Form.new(:title => 'User Info', :url => callback_path)
|
||||
options.fields.each do |field|
|
||||
form.text_field field.to_s.capitalize.gsub("_", " "), field.to_s
|
||||
form.text_field field.to_s.capitalize.gsub('_', ' '), field.to_s
|
||||
end
|
||||
form.button "Sign In"
|
||||
form.button 'Sign In'
|
||||
form.to_response
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ module OmniAuth
|
|||
return
|
||||
end
|
||||
existing = superclass.respond_to?(:args) ? superclass.args : []
|
||||
return (instance_variable_defined?(:@args) && @args) || existing
|
||||
(instance_variable_defined?(:@args) && @args) || existing
|
||||
end
|
||||
|
||||
%w(uid info extra credentials).each do |fetcher|
|
||||
|
|
@ -140,7 +140,7 @@ module OmniAuth
|
|||
end
|
||||
|
||||
# Make sure that all of the args have been dealt with, otherwise error out.
|
||||
raise ArgumentError, "Received wrong number of arguments. #{args.inspect}" unless args.empty?
|
||||
fail(ArgumentError, "Received wrong number of arguments. #{args.inspect}") unless args.empty?
|
||||
|
||||
yield options if block_given?
|
||||
end
|
||||
|
|
@ -169,14 +169,16 @@ module OmniAuth
|
|||
# the request path is recognized.
|
||||
#
|
||||
# @param env [Hash] The Rack environment.
|
||||
def call!(env)
|
||||
raise OmniAuth::NoSessionError.new("You must provide a session to use OmniAuth.") unless env['rack.session']
|
||||
def call!(env) # rubocop:disable CyclomaticComplexity
|
||||
unless env['rack.session']
|
||||
error = OmniAuth::NoSessionError.new('You must provide a session to use OmniAuth.')
|
||||
fail(error)
|
||||
end
|
||||
|
||||
@env = env
|
||||
@env['omniauth.strategy'] = self if on_auth_path?
|
||||
|
||||
return mock_call!(env) if OmniAuth.config.test_mode
|
||||
|
||||
return options_call if on_auth_path? && options_request?
|
||||
return request_call if on_request_path? && OmniAuth.config.allowed_request_methods.include?(request.request_method.downcase.to_sym)
|
||||
return callback_call if on_callback_path?
|
||||
|
|
@ -186,27 +188,23 @@ module OmniAuth
|
|||
|
||||
# Responds to an OPTIONS request.
|
||||
def options_call
|
||||
OmniAuth.config.before_options_phase.call(self.env) if OmniAuth.config.before_options_phase
|
||||
verbs = OmniAuth.config.allowed_request_methods.map(&:to_s).map(&:upcase).join(', ')
|
||||
return [ 200, { 'Allow' => verbs }, [] ]
|
||||
OmniAuth.config.before_options_phase.call(env) if OmniAuth.config.before_options_phase
|
||||
verbs = OmniAuth.config.allowed_request_methods.collect(&:to_s).collect(&:upcase).join(', ')
|
||||
[200, {'Allow' => verbs}, []]
|
||||
end
|
||||
|
||||
# Performs the steps necessary to run the request phase of a strategy.
|
||||
def request_call
|
||||
def request_call # rubocop:disable CyclomaticComplexity, MethodLength
|
||||
setup_phase
|
||||
|
||||
log :info, "Request phase initiated."
|
||||
|
||||
#store query params from the request url, extracted in the callback_phase
|
||||
log :info, 'Request phase initiated.'
|
||||
# store query params from the request url, extracted in the callback_phase
|
||||
session['omniauth.params'] = request.params
|
||||
|
||||
OmniAuth.config.before_request_phase.call(self.env) if OmniAuth.config.before_request_phase
|
||||
|
||||
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
||||
if options.form.respond_to?(:call)
|
||||
log :info, "Rendering form from supplied Rack endpoint."
|
||||
log :info, 'Rendering form from supplied Rack endpoint.'
|
||||
options.form.call(env)
|
||||
elsif options.form
|
||||
log :info, "Rendering form from underlying application."
|
||||
log :info, 'Rendering form from underlying application.'
|
||||
call_app!
|
||||
else
|
||||
if request.params['origin']
|
||||
|
|
@ -221,7 +219,7 @@ module OmniAuth
|
|||
# Performs the steps necessary to run the callback phase of a strategy.
|
||||
def callback_call
|
||||
setup_phase
|
||||
log :info, "Callback phase initiated."
|
||||
log :info, 'Callback phase initiated.'
|
||||
@env['omniauth.origin'] = session.delete('omniauth.origin')
|
||||
@env['omniauth.origin'] = nil if env['omniauth.origin'] == ''
|
||||
@env['omniauth.params'] = session.delete('omniauth.params') || {}
|
||||
|
|
@ -268,7 +266,7 @@ module OmniAuth
|
|||
setup_phase
|
||||
|
||||
session['omniauth.params'] = request.params
|
||||
OmniAuth.config.before_request_phase.call(self.env) if OmniAuth.config.before_request_phase
|
||||
OmniAuth.config.before_request_phase.call(env) if OmniAuth.config.before_request_phase
|
||||
if request.params['origin']
|
||||
@env['rack.session']['omniauth.origin'] = request.params['origin']
|
||||
elsif env['HTTP_REFERER'] && !env['HTTP_REFERER'].match(/#{request_path}$/)
|
||||
|
|
@ -299,10 +297,10 @@ module OmniAuth
|
|||
# underlying application. This will default to `/auth/:provider/setup`.
|
||||
def setup_phase
|
||||
if options[:setup].respond_to?(:call)
|
||||
log :info, "Setup endpoint detected, running now."
|
||||
log :info, 'Setup endpoint detected, running now.'
|
||||
options[:setup].call(env)
|
||||
elsif options.setup?
|
||||
log :info, "Calling through to underlying application for setup."
|
||||
log :info, 'Calling through to underlying application for setup.'
|
||||
setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET')
|
||||
call_app!(setup_env)
|
||||
end
|
||||
|
|
@ -312,7 +310,7 @@ module OmniAuth
|
|||
# perform any information gathering you need to be able to authenticate
|
||||
# the user in this phase.
|
||||
def request_phase
|
||||
raise NotImplementedError
|
||||
fail(NotImplementedError)
|
||||
end
|
||||
|
||||
def uid
|
||||
|
|
@ -360,7 +358,7 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def callback_phase
|
||||
self.env['omniauth.auth'] = auth_hash
|
||||
env['omniauth.auth'] = auth_hash
|
||||
call_app!
|
||||
end
|
||||
|
||||
|
|
@ -387,6 +385,7 @@ module OmniAuth
|
|||
path ||= current_path if options[:callback_path].respond_to?(:call) && options[:callback_path].call(env)
|
||||
path ||= custom_path(:request_path)
|
||||
path ||= "#{path_prefix}/#{name}/callback"
|
||||
path
|
||||
end
|
||||
|
||||
def setup_path
|
||||
|
|
@ -394,11 +393,11 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def current_path
|
||||
request.path_info.downcase.sub(/\/$/,'')
|
||||
request.path_info.downcase.sub(/\/$/, '')
|
||||
end
|
||||
|
||||
def query_string
|
||||
request.query_string.empty? ? "" : "?#{request.query_string}"
|
||||
request.query_string.empty? ? '' : "?#{request.query_string}"
|
||||
end
|
||||
|
||||
def call_app!(env = @env)
|
||||
|
|
@ -414,12 +413,13 @@ module OmniAuth
|
|||
else
|
||||
# in Rack 1.3.x, request.url explodes if scheme is nil
|
||||
if request.scheme && request.url.match(URI::ABS_URI)
|
||||
uri = URI.parse(request.url.gsub(/\?.*$/,''))
|
||||
uri = URI.parse(request.url.gsub(/\?.*$/, ''))
|
||||
uri.path = ''
|
||||
#sometimes the url is actually showing http inside rails because the other layers (like nginx) have handled the ssl termination.
|
||||
uri.scheme = 'https' if ssl?
|
||||
# sometimes the url is actually showing http inside rails because the
|
||||
# other layers (like nginx) have handled the ssl termination.
|
||||
uri.scheme = 'https' if ssl? # rubocop:disable BlockNesting
|
||||
uri.to_s
|
||||
else ""
|
||||
else ''
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -457,12 +457,14 @@ module OmniAuth
|
|||
r.finish
|
||||
end
|
||||
|
||||
def user_info; {} end
|
||||
def user_info
|
||||
{}
|
||||
end
|
||||
|
||||
def fail!(message_key, exception = nil)
|
||||
self.env['omniauth.error'] = exception
|
||||
self.env['omniauth.error.type'] = message_key.to_sym
|
||||
self.env['omniauth.error.strategy'] = self
|
||||
env['omniauth.error'] = exception
|
||||
env['omniauth.error.type'] = message_key.to_sym
|
||||
env['omniauth.error.strategy'] = self
|
||||
|
||||
if exception
|
||||
log :error, "Authentication failure! #{message_key}: #{exception.class.to_s}, #{exception.message}"
|
||||
|
|
@ -470,16 +472,20 @@ module OmniAuth
|
|||
log :error, "Authentication failure! #{message_key} encountered."
|
||||
end
|
||||
|
||||
OmniAuth.config.on_failure.call(self.env)
|
||||
OmniAuth.config.on_failure.call(env)
|
||||
end
|
||||
|
||||
class Options < Hashie::Mash; end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def merge_stack(stack)
|
||||
stack.inject({}){|c,h| c.merge!(h); c}
|
||||
stack.inject({}) do |a, e|
|
||||
a.merge!(e)
|
||||
a
|
||||
end
|
||||
end
|
||||
|
||||
def ssl?
|
||||
request.env['HTTPS'] == 'on' ||
|
||||
request.env['HTTP_X_FORWARDED_SSL'] == 'on' ||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
module OmniAuth
|
||||
|
||||
# Support for testing OmniAuth strategies.
|
||||
module Test
|
||||
|
||||
autoload :PhonySession, 'omniauth/test/phony_session'
|
||||
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
|
||||
autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
class OmniAuth::Test::PhonySession
|
||||
def initialize(app); @app = app end
|
||||
def initialize(app)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@session ||= (env['rack.session'] || {})
|
||||
env['rack.session'] = @session
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
module OmniAuth
|
||||
|
||||
module Test
|
||||
|
||||
module StrategyMacros
|
||||
|
||||
def sets_an_auth_hash
|
||||
it "sets an auth hash" do
|
||||
it 'sets an auth hash' do
|
||||
expect(last_request.env['omniauth.auth']).to be_kind_of(Hash)
|
||||
end
|
||||
end
|
||||
|
|
@ -28,7 +25,5 @@ module OmniAuth
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ require 'rack'
|
|||
require 'omniauth/test'
|
||||
|
||||
module OmniAuth
|
||||
|
||||
module Test
|
||||
|
||||
# Support for testing OmniAuth strategies.
|
||||
#
|
||||
# @example Usage
|
||||
|
|
@ -19,15 +17,14 @@ module OmniAuth
|
|||
# end
|
||||
# end
|
||||
module StrategyTestCase
|
||||
|
||||
def app
|
||||
strat = self.strategy
|
||||
resp = self.app_response
|
||||
Rack::Builder.new {
|
||||
use OmniAuth::Test::PhonySession
|
||||
use *strat
|
||||
run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
|
||||
}.to_app
|
||||
strat = strategy
|
||||
resp = app_response
|
||||
Rack::Builder.new do
|
||||
use(OmniAuth::Test::PhonySession)
|
||||
use(*strat)
|
||||
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
|
||||
end.to_app
|
||||
end
|
||||
|
||||
def app_response
|
||||
|
|
@ -39,11 +36,9 @@ module OmniAuth
|
|||
end
|
||||
|
||||
def strategy
|
||||
raise NotImplementedError.new('Including specs must define #strategy')
|
||||
error = NotImplementedError.new('Including specs must define #strategy')
|
||||
fail(error)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
module OmniAuth
|
||||
VERSION = "1.1.4" unless defined?(OmniAuth::VERSION)
|
||||
VERSION = '1.1.4' unless defined?(OmniAuth::VERSION)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@ Gem::Specification.new do |spec|
|
|||
spec.description = %q{A generalized Rack framework for multiple-provider authentication.}
|
||||
spec.email = ['michael@intridea.com', 'sferik@gmail.com']
|
||||
spec.files = %w(.yardopts LICENSE.md README.md Rakefile omniauth.gemspec)
|
||||
spec.files += Dir.glob("lib/**/*.rb")
|
||||
spec.files += Dir.glob("spec/**/*")
|
||||
spec.files += Dir.glob('lib/**/*.rb')
|
||||
spec.files += Dir.glob('spec/**/*')
|
||||
spec.homepage = 'http://github.com/intridea/omniauth'
|
||||
spec.licenses = ['MIT']
|
||||
spec.name = 'omniauth'
|
||||
spec.require_paths = ['lib']
|
||||
spec.required_rubygems_version = '>= 1.3.5'
|
||||
spec.signing_key = File.expand_path("~/.gem/private_key.pem") if $0 =~ /gem\z/
|
||||
spec.signing_key = File.expand_path('~/.gem/private_key.pem') if $PROGRAM_NAME =~ /gem\z/
|
||||
spec.summary = spec.description
|
||||
spec.test_files = Dir.glob("spec/**/*")
|
||||
spec.test_files = Dir.glob('spec/**/*')
|
||||
spec.version = OmniAuth::VERSION
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require 'rack/test'
|
|||
require 'omniauth'
|
||||
require 'omniauth/test'
|
||||
|
||||
OmniAuth.config.logger = Logger.new("/dev/null")
|
||||
OmniAuth.config.logger = Logger.new('/dev/null')
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include Rack::Test::Methods
|
||||
|
|
@ -24,23 +24,29 @@ end
|
|||
|
||||
class ExampleStrategy
|
||||
include OmniAuth::Strategy
|
||||
option :name, 'test'
|
||||
def call(env); self.call!(env) end
|
||||
attr_reader :last_env
|
||||
option :name, 'test'
|
||||
|
||||
def call(env)
|
||||
self.call!(env)
|
||||
end
|
||||
|
||||
def initialize(*args, &block)
|
||||
super
|
||||
@fail = nil
|
||||
end
|
||||
|
||||
def request_phase
|
||||
@fail = fail!(options[:failure]) if options[:failure]
|
||||
@last_env = env
|
||||
return @fail if @fail
|
||||
raise "Request Phase"
|
||||
fail('Request Phase')
|
||||
end
|
||||
|
||||
def callback_phase
|
||||
@fail = fail!(options[:failure]) if options[:failure]
|
||||
@last_env = env
|
||||
return @fail if @fail
|
||||
raise "Callback Phase"
|
||||
fail('Callback Phase')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,106 +1,109 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth::AuthHash do
|
||||
subject{ OmniAuth::AuthHash.new }
|
||||
it "converts a supplied info key into an InfoHash object" do
|
||||
subject { OmniAuth::AuthHash.new }
|
||||
it 'converts a supplied info key into an InfoHash object' do
|
||||
subject.info = {:first_name => 'Awesome'}
|
||||
expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
|
||||
expect(subject.info.first_name).to eq('Awesome')
|
||||
end
|
||||
|
||||
describe "#valid?" do
|
||||
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
||||
describe '#valid?' do
|
||||
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
||||
|
||||
it "is valid with the right parameters" do
|
||||
it 'is valid with the right parameters' do
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
it "requires a uid" do
|
||||
it 'requires a uid' do
|
||||
subject.uid = nil
|
||||
expect(subject).not_to be_valid
|
||||
end
|
||||
|
||||
it "requires a provider" do
|
||||
it 'requires a provider' do
|
||||
subject.provider = nil
|
||||
expect(subject).not_to be_valid
|
||||
end
|
||||
|
||||
it "requires a name in the user info hash" do
|
||||
it 'requires a name in the user info hash' do
|
||||
subject.info.name = nil
|
||||
expect(subject).not_to be_valid?
|
||||
end
|
||||
end
|
||||
|
||||
describe "#name" do
|
||||
subject{ OmniAuth::AuthHash.new(
|
||||
:info => {
|
||||
:name => 'Phillip J. Fry',
|
||||
:first_name => 'Phillip',
|
||||
:last_name => 'Fry',
|
||||
:nickname => 'meatbag',
|
||||
:email => 'fry@planetexpress.com'
|
||||
})}
|
||||
describe '#name' do
|
||||
subject do
|
||||
OmniAuth::AuthHash.new(
|
||||
:info => {
|
||||
:name => 'Phillip J. Fry',
|
||||
:first_name => 'Phillip',
|
||||
:last_name => 'Fry',
|
||||
:nickname => 'meatbag',
|
||||
:email => 'fry@planetexpress.com',
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
it "defaults to the name key" do
|
||||
it 'defaults to the name key' do
|
||||
expect(subject.info.name).to eq('Phillip J. Fry')
|
||||
end
|
||||
|
||||
it "falls back to go to first_name last_name concatenation" do
|
||||
it 'falls back to go to first_name last_name concatenation' do
|
||||
subject.info.name = nil
|
||||
expect(subject.info.name).to eq('Phillip Fry')
|
||||
end
|
||||
|
||||
it "displays only a first or last name if only that is available" do
|
||||
it 'displays only a first or last name if only that is available' do
|
||||
subject.info.name = nil
|
||||
subject.info.first_name = nil
|
||||
expect(subject.info.name).to eq('Fry')
|
||||
end
|
||||
|
||||
it "displays the nickname if no name, first, or last is available" do
|
||||
it 'displays the nickname if no name, first, or last is available' do
|
||||
subject.info.name = nil
|
||||
%w(first_name last_name).each{|k| subject.info[k] = nil}
|
||||
%w(first_name last_name).each { |k| subject.info[k] = nil }
|
||||
expect(subject.info.name).to eq('meatbag')
|
||||
end
|
||||
|
||||
it "displays the email if no name, first, last, or nick is available" do
|
||||
it 'displays the email if no name, first, last, or nick is available' do
|
||||
subject.info.name = nil
|
||||
%w(first_name last_name nickname).each{|k| subject.info[k] = nil}
|
||||
%w(first_name last_name nickname).each { |k| subject.info[k] = nil }
|
||||
expect(subject.info.name).to eq('fry@planetexpress.com')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#to_hash" do
|
||||
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Bob Example')}
|
||||
let(:hash){ subject.to_hash }
|
||||
describe '#to_hash' do
|
||||
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Bob Example') }
|
||||
let(:hash) { subject.to_hash }
|
||||
|
||||
it "is a plain old hash" do
|
||||
it 'is a plain old hash' do
|
||||
expect(hash.class).to eq(::Hash)
|
||||
end
|
||||
|
||||
it "has string keys" do
|
||||
it 'has string keys' do
|
||||
expect(hash.keys).to be_include('uid')
|
||||
end
|
||||
|
||||
it "converts an info hash as well" do
|
||||
it 'converts an info hash as well' do
|
||||
subject.info = {:first_name => 'Bob', :last_name => 'Example'}
|
||||
expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
|
||||
expect(subject.to_hash['info'].class).to eq(::Hash)
|
||||
end
|
||||
|
||||
it "supplies the calculated name in the converted hash" do
|
||||
it 'supplies the calculated name in the converted hash' do
|
||||
subject.info = {:first_name => 'Bob', :last_name => 'Examplar'}
|
||||
expect(hash['info']['name']).to eq('Bob Examplar')
|
||||
end
|
||||
|
||||
it "does not pollute the URL hash with 'name' etc" do
|
||||
subject.info = {'urls' => {'Homepage' => "http://homepage.com"}}
|
||||
expect(subject.to_hash['info']['urls']).to eq({'Homepage' => "http://homepage.com"})
|
||||
subject.info = {'urls' => {'Homepage' => 'http://homepage.com'}}
|
||||
expect(subject.to_hash['info']['urls']).to eq('Homepage' => 'http://homepage.com')
|
||||
end
|
||||
end
|
||||
|
||||
describe OmniAuth::AuthHash::InfoHash do
|
||||
describe "#valid?" do
|
||||
it "is valid if there is a name" do
|
||||
describe '#valid?' do
|
||||
it 'is valid if there is a name' do
|
||||
expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth::Builder do
|
||||
describe "#provider" do
|
||||
it "translates a symbol to a constant" do
|
||||
describe '#provider' do
|
||||
it 'translates a symbol to a constant' do
|
||||
OmniAuth::Strategies.should_receive(:const_get).with('MyStrategy').and_return(Class.new)
|
||||
OmniAuth::Builder.new(nil) do
|
||||
provider :my_strategy
|
||||
end
|
||||
end
|
||||
|
||||
it "accepts a class" do
|
||||
it 'accepts a class' do
|
||||
class ::ExampleClass; end
|
||||
|
||||
expect{
|
||||
expect do
|
||||
OmniAuth::Builder.new(nil) do
|
||||
provider ::ExampleClass
|
||||
end
|
||||
}.not_to raise_error
|
||||
end.not_to raise_error
|
||||
end
|
||||
|
||||
it "raises a helpful LoadError message if it can't find the class" do
|
||||
expect {
|
||||
expect do
|
||||
OmniAuth::Builder.new(nil) do
|
||||
provider :lorax
|
||||
end
|
||||
}.to raise_error(LoadError, "Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).")
|
||||
end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#options" do
|
||||
it "merges provided options in" do
|
||||
describe '#options' do
|
||||
it 'merges provided options in' do
|
||||
k = Class.new
|
||||
b = OmniAuth::Builder.new(nil)
|
||||
b.should_receive(:use).with(k, :foo => 'bar', :baz => 'tik')
|
||||
|
|
@ -38,7 +38,7 @@ describe OmniAuth::Builder do
|
|||
b.provider k, :baz => 'tik'
|
||||
end
|
||||
|
||||
it "adds an argument if no options are provided" do
|
||||
it 'adds an argument if no options are provided' do
|
||||
k = Class.new
|
||||
b = OmniAuth::Builder.new(nil)
|
||||
b.should_receive(:use).with(k, :foo => 'bar')
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth::FailureEndpoint do
|
||||
subject{ OmniAuth::FailureEndpoint }
|
||||
subject { OmniAuth::FailureEndpoint }
|
||||
|
||||
context "raise-out environment" do
|
||||
context 'raise-out environment' do
|
||||
before do
|
||||
@rack_env = ENV['RACK_ENV']
|
||||
ENV['RACK_ENV'] = 'test'
|
||||
|
|
@ -12,14 +12,14 @@ describe OmniAuth::FailureEndpoint do
|
|||
OmniAuth.config.failure_raise_out_environments = ['test']
|
||||
end
|
||||
|
||||
it "raises out the error" do
|
||||
it 'raises out the error' do
|
||||
expect do
|
||||
subject.call('omniauth.error' => StandardError.new("Blah"))
|
||||
end.to raise_error(StandardError, "Blah")
|
||||
subject.call('omniauth.error' => StandardError.new('Blah'))
|
||||
end.to raise_error(StandardError, 'Blah')
|
||||
end
|
||||
|
||||
it "raises out an OmniAuth::Error if no omniauth.error is set" do
|
||||
expect{ subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, "example")
|
||||
it 'raises out an OmniAuth::Error if no omniauth.error is set' do
|
||||
expect { subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, 'example')
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
@ -28,27 +28,28 @@ describe OmniAuth::FailureEndpoint do
|
|||
end
|
||||
end
|
||||
|
||||
context "non-raise-out environment" do
|
||||
let(:env){ {'omniauth.error.type' => 'invalid_request',
|
||||
'omniauth.error.strategy' => ExampleStrategy.new({}) } }
|
||||
context 'non-raise-out environment' do
|
||||
let(:env) do
|
||||
{'omniauth.error.type' => 'invalid_request', 'omniauth.error.strategy' => ExampleStrategy.new({})}
|
||||
end
|
||||
|
||||
it "is a redirect" do
|
||||
it 'is a redirect' do
|
||||
status, _, _ = *subject.call(env)
|
||||
expect(status).to eq(302)
|
||||
end
|
||||
|
||||
it "includes the SCRIPT_NAME" do
|
||||
it 'includes the SCRIPT_NAME' do
|
||||
_, head, _ = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
|
||||
expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
|
||||
end
|
||||
|
||||
it "respects the configured path prefix" do
|
||||
it 'respects the configured path prefix' do
|
||||
allow(OmniAuth.config).to receive(:path_prefix).and_return('/boo')
|
||||
_, head, _ = *subject.call(env)
|
||||
expect(head["Location"]).to eq('/boo/failure?message=invalid_request&strategy=test')
|
||||
expect(head['Location']).to eq('/boo/failure?message=invalid_request&strategy=test')
|
||||
end
|
||||
|
||||
it "includes the origin (escaped) if one is provided" do
|
||||
it 'includes the origin (escaped) if one is provided' do
|
||||
env.merge! 'omniauth.origin' => '/origin-example'
|
||||
_, head, _ = *subject.call(env)
|
||||
expect(head['Location']).to be_include('&origin=%2Forigin-example')
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth::Form do
|
||||
describe ".build" do
|
||||
it "yields the instance when called with a block and argument" do
|
||||
OmniAuth::Form.build{|f| expect(f).to be_kind_of(OmniAuth::Form)}
|
||||
describe '.build' do
|
||||
it 'yields the instance when called with a block and argument' do
|
||||
OmniAuth::Form.build { |f| expect(f).to be_kind_of(OmniAuth::Form) }
|
||||
end
|
||||
|
||||
it "evaluates in the instance when called with a block and no argument" do
|
||||
OmniAuth::Form.build{|f| expect(f.class).to eq(OmniAuth::Form)}
|
||||
it 'evaluates in the instance when called with a block and no argument' do
|
||||
OmniAuth::Form.build { |f| expect(f.class).to eq(OmniAuth::Form) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#initialize" do
|
||||
it "sets the form action to the passed :url option" do
|
||||
describe '#initialize' do
|
||||
it 'sets the form action to the passed :url option' do
|
||||
expect(OmniAuth::Form.new(:url => '/awesome').to_html).to be_include("action='/awesome'")
|
||||
end
|
||||
|
||||
it "sets an H1 tag from the passed :title option" do
|
||||
it 'sets an H1 tag from the passed :title option' do
|
||||
expect(OmniAuth::Form.new(:title => 'Something Cool').to_html).to be_include('<h1>Something Cool</h1>')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,67 +1,71 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth::Strategies::Developer do
|
||||
let(:app){ Rack::Builder.new do |b|
|
||||
b.use Rack::Session::Cookie, {:secret => "abc123"}
|
||||
b.use OmniAuth::Strategies::Developer
|
||||
b.run lambda{|env| [200, {}, ['Not Found']]}
|
||||
end.to_app }
|
||||
let(:app) do
|
||||
Rack::Builder.new do |b|
|
||||
b.use Rack::Session::Cookie, :secret => 'abc123'
|
||||
b.use OmniAuth::Strategies::Developer
|
||||
b.run lambda { |env| [200, {}, ['Not Found']] }
|
||||
end.to_app
|
||||
end
|
||||
|
||||
context "request phase" do
|
||||
before(:each){ get '/auth/developer' }
|
||||
context 'request phase' do
|
||||
before(:each) { get '/auth/developer' }
|
||||
|
||||
it "displays a form" do
|
||||
it 'displays a form' do
|
||||
expect(last_response.status).to eq(200)
|
||||
expect(last_response.body).to be_include("<form")
|
||||
expect(last_response.body).to be_include('<form')
|
||||
end
|
||||
|
||||
it "has the callback as the action for the form" do
|
||||
it 'has the callback as the action for the form' do
|
||||
expect(last_response.body).to be_include("action='/auth/developer/callback'")
|
||||
end
|
||||
|
||||
it "has a text field for each of the fields" do
|
||||
it 'has a text field for each of the fields' do
|
||||
expect(last_response.body.scan('<input').size).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
context "callback phase" do
|
||||
let(:auth_hash){ last_request.env['omniauth.auth'] }
|
||||
context 'callback phase' do
|
||||
let(:auth_hash) { last_request.env['omniauth.auth'] }
|
||||
|
||||
context "with default options" do
|
||||
context 'with default options' do
|
||||
before do
|
||||
post '/auth/developer/callback', :name => 'Example User', :email => 'user@example.com'
|
||||
end
|
||||
|
||||
it "sets the name in the auth hash" do
|
||||
it 'sets the name in the auth hash' do
|
||||
expect(auth_hash.info.name).to eq('Example User')
|
||||
end
|
||||
|
||||
it "sets the email in the auth hash" do
|
||||
it 'sets the email in the auth hash' do
|
||||
expect(auth_hash.info.email).to eq('user@example.com')
|
||||
end
|
||||
|
||||
it "sets the uid to the email" do
|
||||
it 'sets the uid to the email' do
|
||||
expect(auth_hash.uid).to eq('user@example.com')
|
||||
end
|
||||
end
|
||||
|
||||
context "with custom options" do
|
||||
let(:app){ Rack::Builder.new do |b|
|
||||
b.use Rack::Session::Cookie, {:secret => "abc123"}
|
||||
b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
|
||||
b.run lambda{|env| [200, {}, ['Not Found']]}
|
||||
end.to_app }
|
||||
context 'with custom options' do
|
||||
let(:app) do
|
||||
Rack::Builder.new do |b|
|
||||
b.use Rack::Session::Cookie, :secret => 'abc123'
|
||||
b.use OmniAuth::Strategies::Developer, :fields => [:first_name, :last_name], :uid_field => :last_name
|
||||
b.run lambda { |env| [200, {}, ['Not Found']] }
|
||||
end.to_app
|
||||
end
|
||||
|
||||
before do
|
||||
@options = {:uid_field => :last_name, :fields => [:first_name, :last_name]}
|
||||
post '/auth/developer/callback', :first_name => 'Example', :last_name => 'User'
|
||||
end
|
||||
|
||||
it "sets info fields properly" do
|
||||
it 'sets info fields properly' do
|
||||
expect(auth_hash.info.name).to eq('Example User')
|
||||
end
|
||||
|
||||
it "sets the uid properly" do
|
||||
it 'sets the uid properly' do
|
||||
expect(auth_hash.uid).to eq('User')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,11 +10,17 @@ def make_env(path = '/auth/test', props = {})
|
|||
end
|
||||
|
||||
describe OmniAuth::Strategy do
|
||||
let(:app){ lambda{|env| [404, {}, ['Awesome']]}}
|
||||
let(:fresh_strategy){ c = Class.new; c.send :include, OmniAuth::Strategy; c}
|
||||
let(:app) do
|
||||
lambda { |env| [404, {}, ['Awesome']] }
|
||||
end
|
||||
|
||||
describe ".default_options" do
|
||||
it "is inherited from a parent class" do
|
||||
let(:fresh_strategy) do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
end
|
||||
|
||||
describe '.default_options' do
|
||||
it 'is inherited from a parent class' do
|
||||
superklass = Class.new
|
||||
superklass.send :include, OmniAuth::Strategy
|
||||
superklass.configure do |c|
|
||||
|
|
@ -26,14 +32,18 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".configure" do
|
||||
subject { klass = Class.new; klass.send :include, OmniAuth::Strategy; klass }
|
||||
context "when block is passed" do
|
||||
it "allows for default options setting" do
|
||||
describe '.configure' do
|
||||
subject do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
end
|
||||
|
||||
context 'when block is passed' do
|
||||
it 'allows for default options setting' do
|
||||
subject.configure do |c|
|
||||
c.wakka = 'doo'
|
||||
end
|
||||
expect(subject.default_options["wakka"]).to eq("doo")
|
||||
expect(subject.default_options['wakka']).to eq('doo')
|
||||
end
|
||||
|
||||
it "works when block doesn't evaluate to true" do
|
||||
|
|
@ -42,82 +52,88 @@ describe OmniAuth::Strategy do
|
|||
c.abc = '123'
|
||||
c.hgi = environment_variable
|
||||
end
|
||||
expect(subject.default_options["abc"]).to eq("123")
|
||||
expect(subject.default_options['abc']).to eq('123')
|
||||
end
|
||||
end
|
||||
|
||||
it "takes a hash and deep merge it" do
|
||||
it 'takes a hash and deep merge it' do
|
||||
subject.configure :abc => {:def => 123}
|
||||
subject.configure :abc => {:hgi => 456}
|
||||
expect(subject.default_options['abc']).to eq({'def' => 123, 'hgi' => 456})
|
||||
expect(subject.default_options['abc']).to eq('def' => 123, 'hgi' => 456)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#skip_info?" do
|
||||
it "is true if options.skip_info is true" do
|
||||
describe '#skip_info?' do
|
||||
it 'is true if options.skip_info is true' do
|
||||
expect(ExampleStrategy.new(app, :skip_info => true)).to be_skip_info
|
||||
end
|
||||
|
||||
it "is false if options.skip_info is false" do
|
||||
it 'is false if options.skip_info is false' do
|
||||
expect(ExampleStrategy.new(app, :skip_info => false)).not_to be_skip_info
|
||||
end
|
||||
|
||||
it "is false by default" do
|
||||
it 'is false by default' do
|
||||
expect(ExampleStrategy.new(app)).not_to be_skip_info
|
||||
end
|
||||
|
||||
it "is true if options.skip_info is a callable that evaluates to truthy" do
|
||||
instance = ExampleStrategy.new(app, :skip_info => lambda{|uid| uid})
|
||||
it 'is true if options.skip_info is a callable that evaluates to truthy' do
|
||||
instance = ExampleStrategy.new(app, :skip_info => lambda { |uid| uid })
|
||||
instance.should_receive(:uid).and_return(true)
|
||||
expect(instance).to be_skip_info
|
||||
end
|
||||
end
|
||||
|
||||
describe ".option" do
|
||||
subject { klass = Class.new; klass.send :include, OmniAuth::Strategy; klass }
|
||||
it "sets a default value" do
|
||||
describe '.option' do
|
||||
subject do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
end
|
||||
it 'sets a default value' do
|
||||
subject.option :abc, 123
|
||||
expect(subject.default_options.abc).to eq(123)
|
||||
end
|
||||
|
||||
it "sets the default value to nil if none is provided" do
|
||||
it 'sets the default value to nil if none is provided' do
|
||||
subject.option :abc
|
||||
expect(subject.default_options.abc).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe ".args" do
|
||||
subject { c = Class.new; c.send :include, OmniAuth::Strategy; c }
|
||||
describe '.args' do
|
||||
subject do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
end
|
||||
|
||||
it "sets args to the specified argument if there is one" do
|
||||
it 'sets args to the specified argument if there is one' do
|
||||
subject.args [:abc, :def]
|
||||
expect(subject.args).to eq([:abc, :def])
|
||||
end
|
||||
|
||||
it "is inheritable" do
|
||||
it 'is inheritable' do
|
||||
subject.args [:abc, :def]
|
||||
c = Class.new(subject)
|
||||
expect(c.args).to eq([:abc, :def])
|
||||
end
|
||||
|
||||
it "accepts corresponding options as default arg values" do
|
||||
it 'accepts corresponding options as default arg values' do
|
||||
subject.args [:a, :b]
|
||||
subject.option :a, "1"
|
||||
subject.option :b, "2"
|
||||
subject.option :a, '1'
|
||||
subject.option :b, '2'
|
||||
|
||||
expect(subject.new(nil).options.a).to eq "1"
|
||||
expect(subject.new(nil).options.b).to eq "2"
|
||||
expect(subject.new(nil, "3", "4").options.b).to eq "4"
|
||||
expect(subject.new(nil, nil, "4").options.a).to eq nil
|
||||
expect(subject.new(nil).options.a).to eq '1'
|
||||
expect(subject.new(nil).options.b).to eq '2'
|
||||
expect(subject.new(nil, '3', '4').options.b).to eq '4'
|
||||
expect(subject.new(nil, nil, '4').options.a).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context "fetcher procs" do
|
||||
subject{ fresh_strategy }
|
||||
context 'fetcher procs' do
|
||||
subject { fresh_strategy }
|
||||
%w(uid info credentials extra).each do |fetcher|
|
||||
describe ".#{fetcher}" do
|
||||
it "sets and retrieve a proc" do
|
||||
proc = lambda{ "Hello" }
|
||||
it 'sets and retrieve a proc' do
|
||||
proc = lambda { 'Hello' }
|
||||
subject.send(fetcher, &proc)
|
||||
expect(subject.send(fetcher)).to eq(proc)
|
||||
end
|
||||
|
|
@ -125,14 +141,14 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
context "fetcher stacks" do
|
||||
subject{ fresh_strategy }
|
||||
context 'fetcher stacks' do
|
||||
subject { fresh_strategy }
|
||||
%w(uid info credentials extra).each do |fetcher|
|
||||
describe ".#{fetcher}_stack" do
|
||||
it "is an array of called ancestral procs" do
|
||||
fetchy = Proc.new{ "Hello" }
|
||||
it 'is an array of called ancestral procs' do
|
||||
fetchy = proc { 'Hello' }
|
||||
subject.send(fetcher, &fetchy)
|
||||
expect(subject.send("#{fetcher}_stack", subject.new(app))).to eq(["Hello"])
|
||||
expect(subject.send("#{fetcher}_stack", subject.new(app))).to eq(['Hello'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -140,30 +156,30 @@ describe OmniAuth::Strategy do
|
|||
|
||||
%w(request_phase).each do |abstract_method|
|
||||
context "#{abstract_method}" do
|
||||
it "raises a NotImplementedError" do
|
||||
it 'raises a NotImplementedError' do
|
||||
strat = Class.new
|
||||
strat.send :include, OmniAuth::Strategy
|
||||
expect{strat.new(app).send(abstract_method) }.to raise_error(NotImplementedError)
|
||||
expect { strat.new(app).send(abstract_method) }.to raise_error(NotImplementedError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#auth_hash" do
|
||||
describe '#auth_hash' do
|
||||
subject do
|
||||
klass = Class.new
|
||||
klass.send :include, OmniAuth::Strategy
|
||||
klass.option :name, 'auth_hasher'
|
||||
klass
|
||||
end
|
||||
let(:instance){ subject.new(app) }
|
||||
let(:instance) { subject.new(app) }
|
||||
|
||||
it "calls through to uid and info" do
|
||||
it 'calls through to uid and info' do
|
||||
instance.should_receive :uid
|
||||
instance.should_receive :info
|
||||
instance.auth_hash
|
||||
end
|
||||
|
||||
it "returns an AuthHash" do
|
||||
it 'returns an AuthHash' do
|
||||
allow(instance).to receive(:uid).and_return('123')
|
||||
allow(instance).to receive(:info).and_return(:name => 'Hal Awesome')
|
||||
hash = instance.auth_hash
|
||||
|
|
@ -173,21 +189,25 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#initialize" do
|
||||
context "options extraction" do
|
||||
it "is the last argument if the last argument is a Hash" do
|
||||
describe '#initialize' do
|
||||
context 'options extraction' do
|
||||
it 'is the last argument if the last argument is a Hash' do
|
||||
expect(ExampleStrategy.new(app, :abc => 123).options[:abc]).to eq(123)
|
||||
end
|
||||
|
||||
it "is the default options if any are provided" do
|
||||
it 'is the default options if any are provided' do
|
||||
allow(ExampleStrategy).to receive(:default_options).and_return(OmniAuth::Strategy::Options.new(:abc => 123))
|
||||
expect(ExampleStrategy.new(app).options.abc).to eq(123)
|
||||
end
|
||||
end
|
||||
|
||||
context "custom args" do
|
||||
subject{ c = Class.new; c.send :include, OmniAuth::Strategy; c }
|
||||
it "sets options based on the arguments if they are supplied" do
|
||||
context 'custom args' do
|
||||
subject do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
end
|
||||
|
||||
it 'sets options based on the arguments if they are supplied' do
|
||||
subject.args [:abc, :def]
|
||||
s = subject.new app, 123, 456
|
||||
expect(s.options[:abc]).to eq(123)
|
||||
|
|
@ -196,292 +216,300 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#call" do
|
||||
it "duplicates and calls" do
|
||||
describe '#call' do
|
||||
it 'duplicates and calls' do
|
||||
klass = Class.new
|
||||
klass.send :include, OmniAuth::Strategy
|
||||
instance = klass.new(app)
|
||||
instance.should_receive(:dup).and_return(instance)
|
||||
instance.call({'rack.session' => {}})
|
||||
instance.call('rack.session' => {})
|
||||
end
|
||||
end
|
||||
|
||||
describe "#inspect" do
|
||||
it "returns the class name" do
|
||||
describe '#inspect' do
|
||||
it 'returns the class name' do
|
||||
expect(ExampleStrategy.new(app).inspect).to eq('#<ExampleStrategy>')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#redirect" do
|
||||
it "uses javascript if :iframe is true" do
|
||||
response = ExampleStrategy.new(app, :iframe => true).redirect("http://abc.com")
|
||||
expect(response.last.body.first).to be_include("top.location.href")
|
||||
describe '#redirect' do
|
||||
it 'uses javascript if :iframe is true' do
|
||||
response = ExampleStrategy.new(app, :iframe => true).redirect('http://abc.com')
|
||||
expect(response.last.body.first).to be_include('top.location.href')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#callback_phase" do
|
||||
subject{ k = Class.new; k.send :include, OmniAuth::Strategy; k.new(app) }
|
||||
describe '#callback_phase' do
|
||||
subject do
|
||||
c = Class.new
|
||||
c.send(:include, OmniAuth::Strategy)
|
||||
c.new(app)
|
||||
end
|
||||
|
||||
it "sets the auth hash" do
|
||||
it 'sets the auth hash' do
|
||||
env = make_env
|
||||
allow(subject).to receive(:env).and_return(env)
|
||||
allow(subject).to receive(:auth_hash).and_return("AUTH HASH")
|
||||
allow(subject).to receive(:auth_hash).and_return('AUTH HASH')
|
||||
subject.callback_phase
|
||||
expect(env['omniauth.auth']).to eq("AUTH HASH")
|
||||
expect(env['omniauth.auth']).to eq('AUTH HASH')
|
||||
end
|
||||
end
|
||||
|
||||
describe "#full_host" do
|
||||
let(:strategy){ ExampleStrategy.new(app, {}) }
|
||||
it "remains calm when there is a pipe in the URL" do
|
||||
describe '#full_host' do
|
||||
let(:strategy) { ExampleStrategy.new(app, {}) }
|
||||
it 'remains calm when there is a pipe in the URL' do
|
||||
strategy.call!(make_env('/whatever', 'rack.url_scheme' => 'http', 'SERVER_NAME' => 'facebook.lame', 'QUERY_STRING' => 'code=asofibasf|asoidnasd', 'SCRIPT_NAME' => '', 'SERVER_PORT' => 80))
|
||||
expect{strategy.full_host }.not_to raise_error
|
||||
expect { strategy.full_host }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
describe "#uid" do
|
||||
subject{ fresh_strategy }
|
||||
describe '#uid' do
|
||||
subject { fresh_strategy }
|
||||
it "is the current class's uid if one exists" do
|
||||
subject.uid{ "Hi" }
|
||||
expect(subject.new(app).uid).to eq("Hi")
|
||||
subject.uid { 'Hi' }
|
||||
expect(subject.new(app).uid).to eq('Hi')
|
||||
end
|
||||
|
||||
it "inherits if it can" do
|
||||
subject.uid{ "Hi" }
|
||||
it 'inherits if it can' do
|
||||
subject.uid { 'Hi' }
|
||||
c = Class.new(subject)
|
||||
expect(c.new(app).uid).to eq("Hi")
|
||||
expect(c.new(app).uid).to eq('Hi')
|
||||
end
|
||||
end
|
||||
|
||||
%w(info credentials extra).each do |fetcher|
|
||||
subject{ fresh_strategy }
|
||||
subject { fresh_strategy }
|
||||
it "is the current class's proc call if one exists" do
|
||||
subject.send(fetcher){ {:abc => 123} }
|
||||
expect(subject.new(app).send(fetcher)).to eq({:abc => 123})
|
||||
subject.send(fetcher) { {:abc => 123} }
|
||||
expect(subject.new(app).send(fetcher)).to eq(:abc => 123)
|
||||
end
|
||||
|
||||
it "inherits by merging with preference for the latest class" do
|
||||
subject.send(fetcher){ {:abc => 123, :def => 456} }
|
||||
it 'inherits by merging with preference for the latest class' do
|
||||
subject.send(fetcher) { {:abc => 123, :def => 456} }
|
||||
c = Class.new(subject)
|
||||
c.send(fetcher){ {:abc => 789} }
|
||||
expect(c.new(app).send(fetcher)).to eq({:abc => 789, :def => 456})
|
||||
c.send(fetcher) { {:abc => 789} }
|
||||
expect(c.new(app).send(fetcher)).to eq(:abc => 789, :def => 456)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#call" do
|
||||
describe '#call' do
|
||||
before(:all) do
|
||||
@options = nil
|
||||
end
|
||||
|
||||
let(:strategy){ ExampleStrategy.new(app, @options || {}) }
|
||||
let(:strategy) { ExampleStrategy.new(app, @options || {}) }
|
||||
|
||||
context "omniauth.origin" do
|
||||
it "is set on the request phase" do
|
||||
expect{strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin')) }.to raise_error("Request Phase")
|
||||
context 'omniauth.origin' do
|
||||
it 'is set on the request phase' do
|
||||
expect { strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin')) }.to raise_error('Request Phase')
|
||||
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
||||
end
|
||||
|
||||
it "is turned into an env variable on the callback phase" do
|
||||
expect{strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'})) }.to raise_error("Callback Phase")
|
||||
it 'is turned into an env variable on the callback phase' do
|
||||
expect { strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'})) }.to raise_error('Callback Phase')
|
||||
expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/origin')
|
||||
end
|
||||
|
||||
it "sets from the params if provided" do
|
||||
expect{strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo')) }.to raise_error('Request Phase')
|
||||
it 'sets from the params if provided' do
|
||||
expect { strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo')) }.to raise_error('Request Phase')
|
||||
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('/foo')
|
||||
end
|
||||
|
||||
it "is set on the failure env" do
|
||||
OmniAuth.config.should_receive(:on_failure).and_return(lambda{|env| env})
|
||||
it 'is set on the failure env' do
|
||||
OmniAuth.config.should_receive(:on_failure).and_return(lambda { |env| env })
|
||||
@options = {:failure => :forced_fail}
|
||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => '/awesome'}))
|
||||
end
|
||||
|
||||
context "with script_name" do
|
||||
it "is set on the request phase, containing full path" do
|
||||
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri' }
|
||||
expect{strategy.call(make_env('/auth/test', env)) }.to raise_error("Request Phase")
|
||||
context 'with script_name' do
|
||||
it 'is set on the request phase, containing full path' do
|
||||
env = {'HTTP_REFERER' => 'http://example.com/sub_uri/origin', 'SCRIPT_NAME' => '/sub_uri'}
|
||||
expect { strategy.call(make_env('/auth/test', env)) }.to raise_error('Request Phase')
|
||||
expect(strategy.last_env['rack.session']['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
|
||||
end
|
||||
|
||||
it "is turned into an env variable on the callback phase, containing full path" do
|
||||
it 'is turned into an env variable on the callback phase, containing full path' do
|
||||
env = {
|
||||
'rack.session' => {'omniauth.origin' => 'http://example.com/sub_uri/origin'},
|
||||
'SCRIPT_NAME' => '/sub_uri'
|
||||
}
|
||||
|
||||
expect{strategy.call(make_env('/auth/test/callback', env)) }.to raise_error("Callback Phase")
|
||||
expect { strategy.call(make_env('/auth/test/callback', env)) }.to raise_error('Callback Phase')
|
||||
expect(strategy.last_env['omniauth.origin']).to eq('http://example.com/sub_uri/origin')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
context "default paths" do
|
||||
it "uses the default request path" do
|
||||
expect{strategy.call(make_env) }.to raise_error("Request Phase")
|
||||
context 'default paths' do
|
||||
it 'uses the default request path' do
|
||||
expect { strategy.call(make_env) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "is case insensitive on request path" do
|
||||
expect{strategy.call(make_env('/AUTH/Test'))}.to raise_error("Request Phase")
|
||||
it 'is case insensitive on request path' do
|
||||
expect { strategy.call(make_env('/AUTH/Test')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "is case insensitive on callback path" do
|
||||
expect{strategy.call(make_env('/AUTH/TeSt/CaLlBAck'))}.to raise_error("Callback Phase")
|
||||
it 'is case insensitive on callback path' do
|
||||
expect { strategy.call(make_env('/AUTH/TeSt/CaLlBAck')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
it "uses the default callback path" do
|
||||
expect{strategy.call(make_env('/auth/test/callback')) }.to raise_error("Callback Phase")
|
||||
it 'uses the default callback path' do
|
||||
expect { strategy.call(make_env('/auth/test/callback')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
it "strips trailing spaces on request" do
|
||||
expect{strategy.call(make_env('/auth/test/')) }.to raise_error("Request Phase")
|
||||
it 'strips trailing spaces on request' do
|
||||
expect { strategy.call(make_env('/auth/test/')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "strips trailing spaces on callback" do
|
||||
expect{strategy.call(make_env('/auth/test/callback/')) }.to raise_error("Callback Phase")
|
||||
it 'strips trailing spaces on callback' do
|
||||
expect { strategy.call(make_env('/auth/test/callback/')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
context "callback_url" do
|
||||
it "uses the default callback_path" do
|
||||
context 'callback_url' do
|
||||
it 'uses the default callback_path' do
|
||||
strategy.should_receive(:full_host).and_return('http://example.com')
|
||||
|
||||
expect{strategy.call(make_env) }.to raise_error("Request Phase")
|
||||
expect { strategy.call(make_env) }.to raise_error('Request Phase')
|
||||
|
||||
expect(strategy.callback_url).to eq('http://example.com/auth/test/callback')
|
||||
end
|
||||
|
||||
it "preserves the query parameters" do
|
||||
it 'preserves the query parameters' do
|
||||
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
||||
begin
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
||||
rescue RuntimeError; end
|
||||
rescue RuntimeError
|
||||
end
|
||||
expect(strategy.callback_url).to eq('http://example.com/auth/test/callback?id=5')
|
||||
end
|
||||
|
||||
it "consider script name" do
|
||||
it 'consider script name' do
|
||||
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
||||
begin
|
||||
strategy.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri'))
|
||||
rescue RuntimeError; end
|
||||
rescue RuntimeError
|
||||
end
|
||||
expect(strategy.callback_url).to eq('http://example.com/sub_uri/auth/test/callback')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ":form option" do
|
||||
it "calls through to the supplied form option if one exists" do
|
||||
strategy.options.form = lambda{|env| "Called me!"}
|
||||
expect(strategy.call(make_env('/auth/test'))).to eq("Called me!")
|
||||
context ':form option' do
|
||||
it 'calls through to the supplied form option if one exists' do
|
||||
strategy.options.form = lambda { |env| 'Called me!' }
|
||||
expect(strategy.call(make_env('/auth/test'))).to eq('Called me!')
|
||||
end
|
||||
|
||||
it "calls through to the app if :form => true is set as an option" do
|
||||
it 'calls through to the app if :form => true is set as an option' do
|
||||
strategy.options.form = true
|
||||
expect(strategy.call(make_env('/auth/test'))).to eq(app.call(make_env('/auth/test')))
|
||||
end
|
||||
end
|
||||
|
||||
context "dynamic paths" do
|
||||
it "runs the request phase if the custom request path evaluator is truthy" do
|
||||
@options = {:request_path => lambda{|env| true}}
|
||||
expect{strategy.call(make_env('/asoufibasfi')) }.to raise_error("Request Phase")
|
||||
context 'dynamic paths' do
|
||||
it 'runs the request phase if the custom request path evaluator is truthy' do
|
||||
@options = {:request_path => lambda { |env| true }}
|
||||
expect { strategy.call(make_env('/asoufibasfi')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "runs the callback phase if the custom callback path evaluator is truthy" do
|
||||
@options = {:callback_path => lambda{|env| true}}
|
||||
expect{strategy.call(make_env('/asoufiasod')) }.to raise_error("Callback Phase")
|
||||
it 'runs the callback phase if the custom callback path evaluator is truthy' do
|
||||
@options = {:callback_path => lambda { |env| true }}
|
||||
expect { strategy.call(make_env('/asoufiasod')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
it "provides a custom callback path if request_path evals to a string" do
|
||||
strategy_instance = fresh_strategy.new(nil, :request_path => lambda{|env| "/auth/boo/callback/22" })
|
||||
it 'provides a custom callback path if request_path evals to a string' do
|
||||
strategy_instance = fresh_strategy.new(nil, :request_path => lambda { |env| '/auth/boo/callback/22' })
|
||||
expect(strategy_instance.callback_path).to eq('/auth/boo/callback/22')
|
||||
end
|
||||
|
||||
it "correctly reports the callback path when the custom callback path evaluator is truthy" do
|
||||
it 'correctly reports the callback path when the custom callback path evaluator is truthy' do
|
||||
strategy_instance = ExampleStrategy.new(app,
|
||||
:callback_path => lambda{|env| env['PATH_INFO'] == "/auth/bish/bosh/callback"}
|
||||
:callback_path => lambda { |env| env['PATH_INFO'] == '/auth/bish/bosh/callback' }
|
||||
)
|
||||
|
||||
expect{strategy_instance.call(make_env('/auth/bish/bosh/callback')) }.to raise_error("Callback Phase")
|
||||
expect { strategy_instance.call(make_env('/auth/bish/bosh/callback')) }.to raise_error('Callback Phase')
|
||||
expect(strategy_instance.callback_path).to eq('/auth/bish/bosh/callback')
|
||||
end
|
||||
end
|
||||
|
||||
context "custom paths" do
|
||||
it "uses a custom request_path if one is provided" do
|
||||
context 'custom paths' do
|
||||
it 'uses a custom request_path if one is provided' do
|
||||
@options = {:request_path => '/awesome'}
|
||||
expect{strategy.call(make_env('/awesome')) }.to raise_error("Request Phase")
|
||||
expect { strategy.call(make_env('/awesome')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "uses a custom callback_path if one is provided" do
|
||||
it 'uses a custom callback_path if one is provided' do
|
||||
@options = {:callback_path => '/radical'}
|
||||
expect{strategy.call(make_env('/radical')) }.to raise_error("Callback Phase")
|
||||
expect { strategy.call(make_env('/radical')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
context "callback_url" do
|
||||
it "uses a custom callback_path if one is provided" do
|
||||
context 'callback_url' do
|
||||
it 'uses a custom callback_path if one is provided' do
|
||||
@options = {:callback_path => '/radical'}
|
||||
strategy.should_receive(:full_host).and_return('http://example.com')
|
||||
|
||||
expect{strategy.call(make_env('/radical')) }.to raise_error("Callback Phase")
|
||||
expect { strategy.call(make_env('/radical')) }.to raise_error('Callback Phase')
|
||||
|
||||
expect(strategy.callback_url).to eq('http://example.com/radical')
|
||||
end
|
||||
|
||||
it "preserves the query parameters" do
|
||||
it 'preserves the query parameters' do
|
||||
@options = {:callback_path => '/radical'}
|
||||
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
||||
begin
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
||||
rescue RuntimeError; end
|
||||
rescue RuntimeError
|
||||
end
|
||||
expect(strategy.callback_url).to eq('http://example.com/radical?id=5')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "custom prefix" do
|
||||
context 'custom prefix' do
|
||||
before do
|
||||
@options = {:path_prefix => '/wowzers'}
|
||||
end
|
||||
|
||||
it "uses a custom prefix for request" do
|
||||
expect{strategy.call(make_env('/wowzers/test')) }.to raise_error("Request Phase")
|
||||
it 'uses a custom prefix for request' do
|
||||
expect { strategy.call(make_env('/wowzers/test')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
it "uses a custom prefix for callback" do
|
||||
expect{strategy.call(make_env('/wowzers/test/callback')) }.to raise_error("Callback Phase")
|
||||
it 'uses a custom prefix for callback' do
|
||||
expect { strategy.call(make_env('/wowzers/test/callback')) }.to raise_error('Callback Phase')
|
||||
end
|
||||
|
||||
context "callback_url" do
|
||||
it "uses a custom prefix" do
|
||||
context 'callback_url' do
|
||||
it 'uses a custom prefix' do
|
||||
strategy.should_receive(:full_host).and_return('http://example.com')
|
||||
|
||||
expect{strategy.call(make_env('/wowzers/test')) }.to raise_error("Request Phase")
|
||||
expect { strategy.call(make_env('/wowzers/test')) }.to raise_error('Request Phase')
|
||||
|
||||
expect(strategy.callback_url).to eq('http://example.com/wowzers/test/callback')
|
||||
end
|
||||
|
||||
it "preserves the query parameters" do
|
||||
it 'preserves the query parameters' do
|
||||
allow(strategy).to receive(:full_host).and_return('http://example.com')
|
||||
begin
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'id=5'))
|
||||
rescue RuntimeError; end
|
||||
rescue RuntimeError
|
||||
end
|
||||
expect(strategy.callback_url).to eq('http://example.com/wowzers/test/callback?id=5')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "request method restriction" do
|
||||
context 'request method restriction' do
|
||||
before do
|
||||
OmniAuth.config.allowed_request_methods = [:post]
|
||||
end
|
||||
|
||||
it "does not allow a request method of the wrong type" do
|
||||
expect{strategy.call(make_env)}.not_to raise_error
|
||||
it 'does not allow a request method of the wrong type' do
|
||||
expect { strategy.call(make_env) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "allows a request method of the correct type" do
|
||||
expect{strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'POST'))}.to raise_error("Request Phase")
|
||||
it 'allows a request method of the correct type' do
|
||||
expect { strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'POST')) }.to raise_error('Request Phase')
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
@ -489,98 +517,98 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
context "receiving an OPTIONS request" do
|
||||
shared_examples_for "an OPTIONS request" do
|
||||
it "responds with 200" do
|
||||
context 'receiving an OPTIONS request' do
|
||||
shared_examples_for 'an OPTIONS request' do
|
||||
it 'responds with 200' do
|
||||
expect(response[0]).to eq(200)
|
||||
end
|
||||
|
||||
it "sets the Allow header properly" do
|
||||
expect(response[1]['Allow']).to eq("GET, POST")
|
||||
it 'sets the Allow header properly' do
|
||||
expect(response[1]['Allow']).to eq('GET, POST')
|
||||
end
|
||||
end
|
||||
|
||||
context "to the request path" do
|
||||
context 'to the request path' do
|
||||
let(:response) { strategy.call(make_env('/auth/test', 'REQUEST_METHOD' => 'OPTIONS')) }
|
||||
it_behaves_like "an OPTIONS request"
|
||||
it_behaves_like 'an OPTIONS request'
|
||||
end
|
||||
|
||||
context "to the request path" do
|
||||
context 'to the request path' do
|
||||
let(:response) { strategy.call(make_env('/auth/test/callback', 'REQUEST_METHOD' => 'OPTIONS')) }
|
||||
it_behaves_like "an OPTIONS request"
|
||||
it_behaves_like 'an OPTIONS request'
|
||||
end
|
||||
|
||||
context "to some other path" do
|
||||
it "does not short-circuit the request" do
|
||||
context 'to some other path' do
|
||||
it 'does not short-circuit the request' do
|
||||
env = make_env('/other', 'REQUEST_METHOD' => 'OPTIONS')
|
||||
expect(strategy.call(env)).to eq(app.call(env))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "test mode" do
|
||||
context 'test mode' do
|
||||
let(:app) do
|
||||
# In test mode, the underlying app shouldn't be called on request phase.
|
||||
lambda { |env| [404, {"Content-Type" => "text/html"}, []] }
|
||||
lambda { |env| [404, {'Content-Type' => 'text/html'}, []] }
|
||||
end
|
||||
|
||||
before do
|
||||
OmniAuth.config.test_mode = true
|
||||
end
|
||||
|
||||
it "short circuits the request phase entirely" do
|
||||
it 'short circuits the request phase entirely' do
|
||||
response = strategy.call(make_env)
|
||||
expect(response[0]).to eq(302)
|
||||
expect(response[1]['Location']).to eq('/auth/test/callback')
|
||||
end
|
||||
|
||||
it "is case insensitive on request path" do
|
||||
it 'is case insensitive on request path' do
|
||||
expect(strategy.call(make_env('/AUTH/Test'))[0]).to eq(302)
|
||||
end
|
||||
|
||||
it "respects SCRIPT_NAME (a.k.a. BaseURI)" do
|
||||
it 'respects SCRIPT_NAME (a.k.a. BaseURI)' do
|
||||
response = strategy.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri'))
|
||||
expect(response[1]['Location']).to eq('/sub_uri/auth/test/callback')
|
||||
end
|
||||
|
||||
it "redirects on failure" do
|
||||
it 'redirects on failure' do
|
||||
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'omniauth.error.type' => 'error'))
|
||||
expect(response[0]).to eq(302)
|
||||
expect(response[1]['Location']).to eq('/auth/failure?message=error')
|
||||
end
|
||||
|
||||
it "respects SCRIPT_NAME (a.k.a. BaseURI) on failure" do
|
||||
it 'respects SCRIPT_NAME (a.k.a. BaseURI) on failure' do
|
||||
response = OmniAuth.config.on_failure.call(make_env('/auth/test', 'SCRIPT_NAME' => '/sub_uri', 'omniauth.error.type' => 'error'))
|
||||
expect(response[0]).to eq(302)
|
||||
expect(response[1]['Location']).to eq('/sub_uri/auth/failure?message=error')
|
||||
end
|
||||
|
||||
it "is case insensitive on callback path" do
|
||||
it 'is case insensitive on callback path' do
|
||||
expect(strategy.call(make_env('/AUTH/TeSt/CaLlBAck')).first).to eq(strategy.call(make_env('/auth/test/callback')).first)
|
||||
end
|
||||
|
||||
it "maintains host and port" do
|
||||
response = strategy.call(make_env('/auth/test', 'rack.url_scheme' => "http", 'HTTP_HOST' => 'example.org', 'SERVER_PORT' => 3000))
|
||||
it 'maintains host and port' do
|
||||
response = strategy.call(make_env('/auth/test', 'rack.url_scheme' => 'http', 'HTTP_HOST' => 'example.org', 'SERVER_PORT' => 3000))
|
||||
expect(response[1]['Location']).to eq('http://example.org:3000/auth/test/callback')
|
||||
end
|
||||
|
||||
it "maintains query string parameters" do
|
||||
it 'maintains query string parameters' do
|
||||
response = strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'cheese=stilton'))
|
||||
expect(response[1]['Location']).to eq('/auth/test/callback?cheese=stilton')
|
||||
end
|
||||
|
||||
it "does not short circuit requests outside of authentication" do
|
||||
it 'does not short circuit requests outside of authentication' do
|
||||
expect(strategy.call(make_env('/'))).to eq(app.call(make_env('/')))
|
||||
end
|
||||
|
||||
it "responds with the default hash if none is set" do
|
||||
it 'responds with the default hash if none is set' do
|
||||
OmniAuth.config.mock_auth[:test] = nil
|
||||
|
||||
strategy.call make_env('/auth/test/callback')
|
||||
expect(strategy.env['omniauth.auth']['uid']).to eq('1234')
|
||||
end
|
||||
|
||||
it "responds with a provider-specific hash if one is set" do
|
||||
it 'responds with a provider-specific hash if one is set' do
|
||||
OmniAuth.config.mock_auth[:test] = {
|
||||
'uid' => 'abc'
|
||||
}
|
||||
|
|
@ -589,60 +617,60 @@ describe OmniAuth::Strategy do
|
|||
expect(strategy.env['omniauth.auth']['uid']).to eq('abc')
|
||||
end
|
||||
|
||||
it "simulates login failure if mocked data is set as a symbol" do
|
||||
it 'simulates login failure if mocked data is set as a symbol' do
|
||||
OmniAuth.config.mock_auth[:test] = :invalid_credentials
|
||||
|
||||
strategy.call make_env('/auth/test/callback')
|
||||
expect(strategy.env['omniauth.error.type']).to eq(:invalid_credentials)
|
||||
end
|
||||
|
||||
it "sets omniauth.origin on the request phase" do
|
||||
it 'sets omniauth.origin on the request phase' do
|
||||
strategy.call(make_env('/auth/test', 'HTTP_REFERER' => 'http://example.com/origin'))
|
||||
expect(strategy.env['rack.session']['omniauth.origin']).to eq('http://example.com/origin')
|
||||
end
|
||||
|
||||
it "sets omniauth.origin from the params if provided" do
|
||||
it 'sets omniauth.origin from the params if provided' do
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'origin=/foo'))
|
||||
expect(strategy.env['rack.session']['omniauth.origin']).to eq('/foo')
|
||||
end
|
||||
|
||||
it "turns omniauth.origin into an env variable on the callback phase" do
|
||||
it 'turns omniauth.origin into an env variable on the callback phase' do
|
||||
OmniAuth.config.mock_auth[:test] = {}
|
||||
|
||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
||||
expect(strategy.env['omniauth.origin']).to eq('http://example.com/origin')
|
||||
end
|
||||
|
||||
it "executes callback hook on the callback phase" do
|
||||
it 'executes callback hook on the callback phase' do
|
||||
OmniAuth.config.mock_auth[:test] = {}
|
||||
OmniAuth.config.before_callback_phase do |env|
|
||||
env['foobar']='baz'
|
||||
env['foobar'] = 'baz'
|
||||
end
|
||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.origin' => 'http://example.com/origin'}))
|
||||
expect(strategy.env['foobar']).to eq('baz')
|
||||
end
|
||||
|
||||
it "sets omniauth.params on the request phase" do
|
||||
it 'sets omniauth.params on the request phase' do
|
||||
OmniAuth.config.mock_auth[:test] = {}
|
||||
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
||||
expect(strategy.env['rack.session']['omniauth.params']).to eq({'foo' => 'bar'})
|
||||
expect(strategy.env['rack.session']['omniauth.params']).to eq('foo' => 'bar')
|
||||
end
|
||||
|
||||
it "executes request hook on the request phase" do
|
||||
it 'executes request hook on the request phase' do
|
||||
OmniAuth.config.mock_auth[:test] = {}
|
||||
OmniAuth.config.before_request_phase do |env|
|
||||
env['foobar']='baz'
|
||||
env['foobar'] = 'baz'
|
||||
end
|
||||
strategy.call(make_env('/auth/test', 'QUERY_STRING' => 'foo=bar'))
|
||||
expect(strategy.env['foobar']).to eq('baz')
|
||||
end
|
||||
|
||||
it "turns omniauth.params into an env variable on the callback phase" do
|
||||
it 'turns omniauth.params into an env variable on the callback phase' do
|
||||
OmniAuth.config.mock_auth[:test] = {}
|
||||
|
||||
strategy.call(make_env('/auth/test/callback', 'rack.session' => {'omniauth.params' => {'foo' => 'bar'}}))
|
||||
expect(strategy.env['omniauth.params']).to eq({'foo' => 'bar'})
|
||||
expect(strategy.env['omniauth.params']).to eq('foo' => 'bar')
|
||||
end
|
||||
|
||||
after do
|
||||
|
|
@ -650,18 +678,18 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
context "custom full_host" do
|
||||
context 'custom full_host' do
|
||||
before do
|
||||
OmniAuth.config.test_mode = true
|
||||
end
|
||||
|
||||
it "is the string when a string is there" do
|
||||
it 'is the string when a string is there' do
|
||||
OmniAuth.config.full_host = 'my.host.com'
|
||||
expect(strategy.full_host).to eq('my.host.com')
|
||||
end
|
||||
|
||||
it "runs the proc with the env when it is a proc" do
|
||||
OmniAuth.config.full_host = Proc.new{|env| env['HOST']}
|
||||
it 'runs the proc with the env when it is a proc' do
|
||||
OmniAuth.config.full_host = proc { |env| env['HOST'] }
|
||||
strategy.call(make_env('/auth/test', 'HOST' => 'my.host.net'))
|
||||
expect(strategy.full_host).to eq('my.host.net')
|
||||
end
|
||||
|
|
@ -672,9 +700,9 @@ describe OmniAuth::Strategy do
|
|||
expect(strategy.full_host).to eq('http://my.host.net')
|
||||
end
|
||||
|
||||
it "should honor HTTP_X_FORWARDED_PROTO if present" do
|
||||
it 'should honor HTTP_X_FORWARDED_PROTO if present' do
|
||||
OmniAuth.config.full_host = nil
|
||||
strategy.call(make_env('/whatever', 'HTTP_X_FORWARDED_PROTO' => 'https','rack.url_scheme' => 'http', 'SERVER_NAME' => 'my.host.net', 'SERVER_PORT' => 443))
|
||||
strategy.call(make_env('/whatever', 'HTTP_X_FORWARDED_PROTO' => 'https', 'rack.url_scheme' => 'http', 'SERVER_NAME' => 'my.host.net', 'SERVER_PORT' => 443))
|
||||
expect(strategy.full_host).to eq('https://my.host.net')
|
||||
end
|
||||
|
||||
|
|
@ -685,41 +713,49 @@ describe OmniAuth::Strategy do
|
|||
end
|
||||
end
|
||||
|
||||
context "setup phase" do
|
||||
context 'setup phase' do
|
||||
before do
|
||||
OmniAuth.config.test_mode = true
|
||||
end
|
||||
|
||||
context "when options[:setup] = true" do
|
||||
let(:strategy){ ExampleStrategy.new(app, :setup => true) }
|
||||
let(:app){lambda{|env| env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'; [404, {}, 'Awesome'] }}
|
||||
context 'when options[:setup] = true' do
|
||||
let(:strategy) do
|
||||
ExampleStrategy.new(app, :setup => true)
|
||||
end
|
||||
|
||||
it "calls through to /auth/:provider/setup" do
|
||||
let(:app) do
|
||||
lambda do |env|
|
||||
env['omniauth.strategy'].options[:awesome] = 'sauce' if env['PATH_INFO'] == '/auth/test/setup'
|
||||
[404, {}, 'Awesome']
|
||||
end
|
||||
end
|
||||
|
||||
it 'calls through to /auth/:provider/setup' do
|
||||
strategy.call(make_env('/auth/test'))
|
||||
expect(strategy.options[:awesome]).to eq('sauce')
|
||||
end
|
||||
|
||||
it "does not call through on a non-omniauth endpoint" do
|
||||
it 'does not call through on a non-omniauth endpoint' do
|
||||
strategy.call(make_env('/somewhere/else'))
|
||||
expect(strategy.options[:awesome]).not_to eq('sauce')
|
||||
end
|
||||
end
|
||||
|
||||
context "when options[:setup] is an app" do
|
||||
context 'when options[:setup] is an app' do
|
||||
let(:setup_proc) do
|
||||
Proc.new do |env|
|
||||
proc do |env|
|
||||
env['omniauth.strategy'].options[:awesome] = 'sauce'
|
||||
end
|
||||
end
|
||||
|
||||
let(:strategy) { ExampleStrategy.new(app, :setup => setup_proc) }
|
||||
|
||||
it "does not call the app on a non-omniauth endpoint" do
|
||||
it 'does not call the app on a non-omniauth endpoint' do
|
||||
strategy.call(make_env('/somehwere/else'))
|
||||
expect(strategy.options[:awesome]).not_to eq('sauce')
|
||||
end
|
||||
|
||||
it "calls the rack app" do
|
||||
it 'calls the rack app' do
|
||||
strategy.call(make_env('/auth/test'))
|
||||
expect(strategy.options[:awesome]).to eq('sauce')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
require 'helper'
|
||||
|
||||
describe OmniAuth do
|
||||
describe ".strategies" do
|
||||
it "increases when a new strategy is made" do
|
||||
expect{
|
||||
describe '.strategies' do
|
||||
it 'increases when a new strategy is made' do
|
||||
expect do
|
||||
class ExampleStrategy
|
||||
include OmniAuth::Strategy
|
||||
end
|
||||
}.to change(OmniAuth.strategies, :size).by(1)
|
||||
end.to change(OmniAuth.strategies, :size).by(1)
|
||||
expect(OmniAuth.strategies.last).to eq(ExampleStrategy)
|
||||
end
|
||||
end
|
||||
|
||||
context "configuration" do
|
||||
describe ".defaults" do
|
||||
it "is a hash of default configuration" do
|
||||
context 'configuration' do
|
||||
describe '.defaults' do
|
||||
it 'is a hash of default configuration' do
|
||||
expect(OmniAuth::Configuration.defaults).to be_kind_of(Hash)
|
||||
end
|
||||
end
|
||||
|
||||
it "is callable from .configure" do
|
||||
it 'is callable from .configure' do
|
||||
OmniAuth.configure do |c|
|
||||
expect(c).to be_kind_of(OmniAuth::Configuration)
|
||||
end
|
||||
|
|
@ -43,7 +43,7 @@ describe OmniAuth do
|
|||
end
|
||||
end
|
||||
|
||||
it "is able to set the path" do
|
||||
it 'is able to set the path' do
|
||||
OmniAuth.configure do |config|
|
||||
config.path_prefix = '/awesome'
|
||||
end
|
||||
|
|
@ -51,7 +51,7 @@ describe OmniAuth do
|
|||
expect(OmniAuth.config.path_prefix).to eq('/awesome')
|
||||
end
|
||||
|
||||
it "is able to set the on_failure rack app" do
|
||||
it 'is able to set the on_failure rack app' do
|
||||
OmniAuth.configure do |config|
|
||||
config.on_failure do
|
||||
'yoyo'
|
||||
|
|
@ -61,7 +61,7 @@ describe OmniAuth do
|
|||
expect(OmniAuth.config.on_failure.call).to eq('yoyo')
|
||||
end
|
||||
|
||||
it "is able to set hook on option_call" do
|
||||
it 'is able to set hook on option_call' do
|
||||
OmniAuth.configure do |config|
|
||||
config.before_options_phase do
|
||||
'yoyo'
|
||||
|
|
@ -70,7 +70,7 @@ describe OmniAuth do
|
|||
expect(OmniAuth.config.before_options_phase.call).to eq('yoyo')
|
||||
end
|
||||
|
||||
it "is able to set hook on request_call" do
|
||||
it 'is able to set hook on request_call' do
|
||||
OmniAuth.configure do |config|
|
||||
config.before_request_phase do
|
||||
'heyhey'
|
||||
|
|
@ -79,7 +79,7 @@ describe OmniAuth do
|
|||
expect(OmniAuth.config.before_request_phase.call).to eq('heyhey')
|
||||
end
|
||||
|
||||
it "is able to set hook on callback_call" do
|
||||
it 'is able to set hook on callback_call' do
|
||||
OmniAuth.configure do |config|
|
||||
config.before_callback_phase do
|
||||
'heyhey'
|
||||
|
|
@ -88,21 +88,21 @@ describe OmniAuth do
|
|||
expect(OmniAuth.config.before_callback_phase.call).to eq('heyhey')
|
||||
end
|
||||
|
||||
describe "mock auth" do
|
||||
describe 'mock auth' do
|
||||
before do
|
||||
OmniAuth.config.add_mock(:facebook, :uid => '12345',:info=>{:name=>'Joe', :email=>'joe@example.com'})
|
||||
OmniAuth.config.add_mock(:facebook, :uid => '12345', :info => {:name => 'Joe', :email => 'joe@example.com'})
|
||||
end
|
||||
it "default should be AuthHash" do
|
||||
it 'default should be AuthHash' do
|
||||
OmniAuth.configure do |config|
|
||||
expect(config.mock_auth[:default]).to be_kind_of(OmniAuth::AuthHash)
|
||||
end
|
||||
end
|
||||
it "facebook should be AuthHash" do
|
||||
it 'facebook should be AuthHash' do
|
||||
OmniAuth.configure do |config|
|
||||
expect(config.mock_auth[:facebook]).to be_kind_of(OmniAuth::AuthHash)
|
||||
end
|
||||
end
|
||||
it "sets facebook attributes" do
|
||||
it 'sets facebook attributes' do
|
||||
OmniAuth.configure do |config|
|
||||
expect(config.mock_auth[:facebook].uid).to eq('12345')
|
||||
expect(config.mock_auth[:facebook].info.name).to eq('Joe')
|
||||
|
|
@ -112,31 +112,31 @@ describe OmniAuth do
|
|||
end
|
||||
end
|
||||
|
||||
describe ".logger" do
|
||||
it "calls through to the configured logger" do
|
||||
allow(OmniAuth).to receive(:config).and_return(double(:logger => "foo"))
|
||||
expect(OmniAuth.logger).to eq("foo")
|
||||
describe '.logger' do
|
||||
it 'calls through to the configured logger' do
|
||||
allow(OmniAuth).to receive(:config).and_return(double(:logger => 'foo'))
|
||||
expect(OmniAuth.logger).to eq('foo')
|
||||
end
|
||||
end
|
||||
|
||||
describe "::Utils" do
|
||||
describe ".deep_merge" do
|
||||
it "combines hashes" do
|
||||
expect(OmniAuth::Utils.deep_merge({'abc' => {'def' => 123}}, {'abc' => {'foo' => 'bar'}})).to eq({'abc' => {'def' => 123, 'foo' => 'bar'}})
|
||||
describe '::Utils' do
|
||||
describe '.deep_merge' do
|
||||
it 'combines hashes' do
|
||||
expect(OmniAuth::Utils.deep_merge({'abc' => {'def' => 123}}, {'abc' => {'foo' => 'bar'}})).to eq('abc' => {'def' => 123, 'foo' => 'bar'})
|
||||
end
|
||||
end
|
||||
|
||||
describe ".camelize" do
|
||||
it "works on normal cases" do
|
||||
describe '.camelize' do
|
||||
it 'works on normal cases' do
|
||||
{
|
||||
'some_word' => 'SomeWord',
|
||||
'AnotherWord' => 'AnotherWord',
|
||||
'one' => 'One',
|
||||
'three_words_now' => 'ThreeWordsNow'
|
||||
}.each_pair{ |k,v| expect(OmniAuth::Utils.camelize(k)).to eq(v) }
|
||||
}.each_pair { |k, v| expect(OmniAuth::Utils.camelize(k)).to eq(v) }
|
||||
end
|
||||
|
||||
it "works in special cases that have been added" do
|
||||
it 'works in special cases that have been added' do
|
||||
OmniAuth.config.add_camelization('oauth', 'OAuth')
|
||||
expect(OmniAuth::Utils.camelize(:oauth)).to eq('OAuth')
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue