omniauth 1.1.4 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of omniauth might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +82 -0
- data/.travis.yml +42 -0
- data/Gemfile +37 -0
- data/Gemfile.rack-1.3.x +24 -0
- data/Guardfile +10 -0
- data/README.md +4 -4
- data/Rakefile +12 -1
- data/certs/sferik.pem +20 -0
- data/lib/omniauth.rb +51 -33
- data/lib/omniauth/auth_hash.rb +9 -6
- data/lib/omniauth/builder.rb +12 -2
- data/lib/omniauth/failure_endpoint.rb +5 -5
- data/lib/omniauth/form.css +81 -0
- data/lib/omniauth/form.rb +11 -95
- data/lib/omniauth/strategies/developer.rb +3 -5
- data/lib/omniauth/strategy.rb +61 -47
- data/lib/omniauth/test.rb +0 -4
- data/lib/omniauth/test/phony_session.rb +4 -1
- data/lib/omniauth/test/strategy_macros.rb +1 -6
- data/lib/omniauth/test/strategy_test_case.rb +9 -14
- data/lib/omniauth/version.rb +1 -1
- data/omniauth.gemspec +5 -7
- data/spec/helper.rb +15 -6
- data/spec/omniauth/auth_hash_spec.rb +42 -39
- data/spec/omniauth/builder_spec.rb +13 -13
- data/spec/omniauth/failure_endpoint_spec.rb +22 -17
- data/spec/omniauth/form_spec.rb +8 -8
- data/spec/omniauth/strategies/developer_spec.rb +29 -25
- data/spec/omniauth/strategy_spec.rb +300 -219
- data/spec/omniauth_spec.rb +65 -31
- metadata +30 -20
- metadata.gz.sig +0 -0
data/lib/omniauth/test.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
module OmniAuth
|
2
|
-
|
3
2
|
# Support for testing OmniAuth strategies.
|
4
3
|
module Test
|
5
|
-
|
6
4
|
autoload :PhonySession, 'omniauth/test/phony_session'
|
7
5
|
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
|
8
6
|
autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
|
9
|
-
|
10
7
|
end
|
11
|
-
|
12
8
|
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module OmniAuth
|
2
|
-
|
3
2
|
module Test
|
4
|
-
|
5
3
|
module StrategyMacros
|
6
|
-
|
7
4
|
def sets_an_auth_hash
|
8
|
-
it
|
5
|
+
it 'sets an auth hash' do
|
9
6
|
expect(last_request.env['omniauth.auth']).to be_kind_of(Hash)
|
10
7
|
end
|
11
8
|
end
|
@@ -28,7 +25,5 @@ module OmniAuth
|
|
28
25
|
end
|
29
26
|
end
|
30
27
|
end
|
31
|
-
|
32
28
|
end
|
33
|
-
|
34
29
|
end
|
@@ -2,9 +2,7 @@ require 'rack'
|
|
2
2
|
require 'omniauth/test'
|
3
3
|
|
4
4
|
module OmniAuth
|
5
|
-
|
6
5
|
module Test
|
7
|
-
|
8
6
|
# Support for testing OmniAuth strategies.
|
9
7
|
#
|
10
8
|
# @example Usage
|
@@ -19,15 +17,14 @@ module OmniAuth
|
|
19
17
|
# end
|
20
18
|
# end
|
21
19
|
module StrategyTestCase
|
22
|
-
|
23
20
|
def app
|
24
|
-
strat =
|
25
|
-
resp =
|
26
|
-
Rack::Builder.new
|
27
|
-
use
|
28
|
-
use
|
29
|
-
run lambda {|env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
|
30
|
-
|
21
|
+
strat = strategy
|
22
|
+
resp = app_response
|
23
|
+
Rack::Builder.new do
|
24
|
+
use(OmniAuth::Test::PhonySession)
|
25
|
+
use(*strat)
|
26
|
+
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [resp || env.key?('omniauth.auth').to_s]] }
|
27
|
+
end.to_app
|
31
28
|
end
|
32
29
|
|
33
30
|
def app_response
|
@@ -39,11 +36,9 @@ module OmniAuth
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def strategy
|
42
|
-
|
39
|
+
error = NotImplementedError.new('Including specs must define #strategy')
|
40
|
+
fail(error)
|
43
41
|
end
|
44
|
-
|
45
42
|
end
|
46
|
-
|
47
43
|
end
|
48
|
-
|
49
44
|
end
|
data/lib/omniauth/version.rb
CHANGED
data/omniauth.gemspec
CHANGED
@@ -5,22 +5,20 @@ require 'omniauth/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.add_dependency 'hashie', ['>= 1.2', '< 3']
|
8
|
-
spec.add_dependency 'rack'
|
8
|
+
spec.add_dependency 'rack', '~> 1.0'
|
9
9
|
spec.add_development_dependency 'bundler', '~> 1.0'
|
10
10
|
spec.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
|
11
11
|
spec.cert_chain = %w(certs/sferik.pem)
|
12
12
|
spec.description = %q{A generalized Rack framework for multiple-provider authentication.}
|
13
13
|
spec.email = ['michael@intridea.com', 'sferik@gmail.com']
|
14
|
-
spec.files =
|
15
|
-
spec.files += Dir.glob("lib/**/*.rb")
|
16
|
-
spec.files += Dir.glob("spec/**/*")
|
14
|
+
spec.files = `git ls-files`.split($/)
|
17
15
|
spec.homepage = 'http://github.com/intridea/omniauth'
|
18
16
|
spec.licenses = ['MIT']
|
19
17
|
spec.name = 'omniauth'
|
20
18
|
spec.require_paths = ['lib']
|
21
|
-
spec.required_rubygems_version = '>= 1.3.
|
22
|
-
spec.signing_key = File.expand_path(
|
19
|
+
spec.required_rubygems_version = '>= 1.3.5'
|
20
|
+
spec.signing_key = File.expand_path('~/.gem/private_key.pem') if $PROGRAM_NAME =~ /gem\z/
|
23
21
|
spec.summary = spec.description
|
24
|
-
spec.test_files =
|
22
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
25
23
|
spec.version = OmniAuth::VERSION
|
26
24
|
end
|
data/spec/helper.rb
CHANGED
@@ -5,14 +5,17 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
|
5
5
|
SimpleCov::Formatter::HTMLFormatter,
|
6
6
|
Coveralls::SimpleCov::Formatter
|
7
7
|
]
|
8
|
-
SimpleCov.start
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/spec/'
|
10
|
+
minimum_coverage(93.05)
|
11
|
+
end
|
9
12
|
|
10
13
|
require 'rspec'
|
11
14
|
require 'rack/test'
|
12
15
|
require 'omniauth'
|
13
16
|
require 'omniauth/test'
|
14
17
|
|
15
|
-
OmniAuth.config.logger = Logger.new(
|
18
|
+
OmniAuth.config.logger = Logger.new('/dev/null')
|
16
19
|
|
17
20
|
RSpec.configure do |config|
|
18
21
|
config.include Rack::Test::Methods
|
@@ -24,23 +27,29 @@ end
|
|
24
27
|
|
25
28
|
class ExampleStrategy
|
26
29
|
include OmniAuth::Strategy
|
27
|
-
option :name, 'test'
|
28
|
-
def call(env); self.call!(env) end
|
29
30
|
attr_reader :last_env
|
31
|
+
option :name, 'test'
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
self.call!(env)
|
35
|
+
end
|
36
|
+
|
30
37
|
def initialize(*args, &block)
|
31
38
|
super
|
32
39
|
@fail = nil
|
33
40
|
end
|
41
|
+
|
34
42
|
def request_phase
|
35
43
|
@fail = fail!(options[:failure]) if options[:failure]
|
36
44
|
@last_env = env
|
37
45
|
return @fail if @fail
|
38
|
-
|
46
|
+
fail('Request Phase')
|
39
47
|
end
|
48
|
+
|
40
49
|
def callback_phase
|
41
50
|
@fail = fail!(options[:failure]) if options[:failure]
|
42
51
|
@last_env = env
|
43
52
|
return @fail if @fail
|
44
|
-
|
53
|
+
fail('Callback Phase')
|
45
54
|
end
|
46
55
|
end
|
@@ -1,106 +1,109 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::AuthHash do
|
4
|
-
subject{ OmniAuth::AuthHash.new }
|
5
|
-
it
|
4
|
+
subject { OmniAuth::AuthHash.new }
|
5
|
+
it 'converts a supplied info key into an InfoHash object' do
|
6
6
|
subject.info = {:first_name => 'Awesome'}
|
7
7
|
expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
|
8
8
|
expect(subject.info.first_name).to eq('Awesome')
|
9
9
|
end
|
10
10
|
|
11
|
-
describe
|
12
|
-
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
11
|
+
describe '#valid?' do
|
12
|
+
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
13
13
|
|
14
|
-
it
|
14
|
+
it 'is valid with the right parameters' do
|
15
15
|
expect(subject).to be_valid
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'requires a uid' do
|
19
19
|
subject.uid = nil
|
20
20
|
expect(subject).not_to be_valid
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'requires a provider' do
|
24
24
|
subject.provider = nil
|
25
25
|
expect(subject).not_to be_valid
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'requires a name in the user info hash' do
|
29
29
|
subject.info.name = nil
|
30
30
|
expect(subject).not_to be_valid?
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
describe
|
35
|
-
subject
|
36
|
-
|
37
|
-
:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
describe '#name' do
|
35
|
+
subject do
|
36
|
+
OmniAuth::AuthHash.new(
|
37
|
+
:info => {
|
38
|
+
:name => 'Phillip J. Fry',
|
39
|
+
:first_name => 'Phillip',
|
40
|
+
:last_name => 'Fry',
|
41
|
+
:nickname => 'meatbag',
|
42
|
+
:email => 'fry@planetexpress.com',
|
43
|
+
}
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'defaults to the name key' do
|
45
48
|
expect(subject.info.name).to eq('Phillip J. Fry')
|
46
49
|
end
|
47
50
|
|
48
|
-
it
|
51
|
+
it 'falls back to go to first_name last_name concatenation' do
|
49
52
|
subject.info.name = nil
|
50
53
|
expect(subject.info.name).to eq('Phillip Fry')
|
51
54
|
end
|
52
55
|
|
53
|
-
it
|
56
|
+
it 'displays only a first or last name if only that is available' do
|
54
57
|
subject.info.name = nil
|
55
58
|
subject.info.first_name = nil
|
56
59
|
expect(subject.info.name).to eq('Fry')
|
57
60
|
end
|
58
61
|
|
59
|
-
it
|
62
|
+
it 'displays the nickname if no name, first, or last is available' do
|
60
63
|
subject.info.name = nil
|
61
|
-
%w(first_name last_name).each{|k| subject.info[k] = nil}
|
64
|
+
%w(first_name last_name).each { |k| subject.info[k] = nil }
|
62
65
|
expect(subject.info.name).to eq('meatbag')
|
63
66
|
end
|
64
67
|
|
65
|
-
it
|
68
|
+
it 'displays the email if no name, first, last, or nick is available' do
|
66
69
|
subject.info.name = nil
|
67
|
-
%w(first_name last_name nickname).each{|k| subject.info[k] = nil}
|
70
|
+
%w(first_name last_name nickname).each { |k| subject.info[k] = nil }
|
68
71
|
expect(subject.info.name).to eq('fry@planetexpress.com')
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
describe
|
73
|
-
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => '
|
74
|
-
let(:hash){ subject.to_hash }
|
75
|
+
describe '#to_hash' do
|
76
|
+
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Example User') }
|
77
|
+
let(:hash) { subject.to_hash }
|
75
78
|
|
76
|
-
it
|
79
|
+
it 'is a plain old hash' do
|
77
80
|
expect(hash.class).to eq(::Hash)
|
78
81
|
end
|
79
82
|
|
80
|
-
it
|
83
|
+
it 'has string keys' do
|
81
84
|
expect(hash.keys).to be_include('uid')
|
82
85
|
end
|
83
86
|
|
84
|
-
it
|
85
|
-
subject.info = {:first_name => '
|
87
|
+
it 'converts an info hash as well' do
|
88
|
+
subject.info = {:first_name => 'Example', :last_name => 'User'}
|
86
89
|
expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
|
87
90
|
expect(subject.to_hash['info'].class).to eq(::Hash)
|
88
91
|
end
|
89
92
|
|
90
|
-
it
|
91
|
-
subject.info = {:first_name => '
|
92
|
-
expect(hash['info']['name']).to eq('
|
93
|
+
it 'supplies the calculated name in the converted hash' do
|
94
|
+
subject.info = {:first_name => 'Examplar', :last_name => 'User'}
|
95
|
+
expect(hash['info']['name']).to eq('Examplar User')
|
93
96
|
end
|
94
97
|
|
95
98
|
it "does not pollute the URL hash with 'name' etc" do
|
96
|
-
subject.info = {'urls' => {'Homepage' =>
|
97
|
-
expect(subject.to_hash['info']['urls']).to eq(
|
99
|
+
subject.info = {'urls' => {'Homepage' => 'http://homepage.com'}}
|
100
|
+
expect(subject.to_hash['info']['urls']).to eq('Homepage' => 'http://homepage.com')
|
98
101
|
end
|
99
102
|
end
|
100
103
|
|
101
104
|
describe OmniAuth::AuthHash::InfoHash do
|
102
|
-
describe
|
103
|
-
it
|
105
|
+
describe '#valid?' do
|
106
|
+
it 'is valid if there is a name' do
|
104
107
|
expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
|
105
108
|
end
|
106
109
|
end
|
@@ -1,47 +1,47 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::Builder do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
OmniAuth::Strategies.
|
4
|
+
describe '#provider' do
|
5
|
+
it 'translates a symbol to a constant' do
|
6
|
+
expect(OmniAuth::Strategies).to receive(:const_get).with('MyStrategy').and_return(Class.new)
|
7
7
|
OmniAuth::Builder.new(nil) do
|
8
8
|
provider :my_strategy
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
it
|
12
|
+
it 'accepts a class' do
|
13
13
|
class ::ExampleClass; end
|
14
14
|
|
15
|
-
expect
|
15
|
+
expect do
|
16
16
|
OmniAuth::Builder.new(nil) do
|
17
17
|
provider ::ExampleClass
|
18
18
|
end
|
19
|
-
|
19
|
+
end.not_to raise_error
|
20
20
|
end
|
21
21
|
|
22
22
|
it "raises a helpful LoadError message if it can't find the class" do
|
23
|
-
expect
|
23
|
+
expect do
|
24
24
|
OmniAuth::Builder.new(nil) do
|
25
25
|
provider :lorax
|
26
26
|
end
|
27
|
-
|
27
|
+
end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe
|
32
|
-
it
|
31
|
+
describe '#options' do
|
32
|
+
it 'merges provided options in' do
|
33
33
|
k = Class.new
|
34
34
|
b = OmniAuth::Builder.new(nil)
|
35
|
-
b.
|
35
|
+
expect(b).to receive(:use).with(k, :foo => 'bar', :baz => 'tik')
|
36
36
|
|
37
37
|
b.options :foo => 'bar'
|
38
38
|
b.provider k, :baz => 'tik'
|
39
39
|
end
|
40
40
|
|
41
|
-
it
|
41
|
+
it 'adds an argument if no options are provided' do
|
42
42
|
k = Class.new
|
43
43
|
b = OmniAuth::Builder.new(nil)
|
44
|
-
b.
|
44
|
+
expect(b).to receive(:use).with(k, :foo => 'bar')
|
45
45
|
|
46
46
|
b.options :foo => 'bar'
|
47
47
|
b.provider k
|
@@ -1,50 +1,55 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe OmniAuth::FailureEndpoint do
|
4
|
-
subject{ OmniAuth::FailureEndpoint }
|
4
|
+
subject { OmniAuth::FailureEndpoint }
|
5
5
|
|
6
|
-
context
|
6
|
+
context 'raise-out environment' do
|
7
7
|
before do
|
8
8
|
@rack_env = ENV['RACK_ENV']
|
9
|
-
ENV['RACK_ENV'] = '
|
9
|
+
ENV['RACK_ENV'] = 'test'
|
10
|
+
|
11
|
+
@default = OmniAuth.config.failure_raise_out_environments
|
12
|
+
OmniAuth.config.failure_raise_out_environments = ['test']
|
10
13
|
end
|
11
14
|
|
12
|
-
it
|
15
|
+
it 'raises out the error' do
|
13
16
|
expect do
|
14
|
-
subject.call('omniauth.error' => StandardError.new(
|
15
|
-
end.to raise_error(StandardError,
|
17
|
+
subject.call('omniauth.error' => StandardError.new('Blah'))
|
18
|
+
end.to raise_error(StandardError, 'Blah')
|
16
19
|
end
|
17
20
|
|
18
|
-
it
|
19
|
-
expect{ subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error,
|
21
|
+
it 'raises out an OmniAuth::Error if no omniauth.error is set' do
|
22
|
+
expect { subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, 'example')
|
20
23
|
end
|
21
24
|
|
22
25
|
after do
|
23
26
|
ENV['RACK_ENV'] = @rack_env
|
27
|
+
OmniAuth.config.failure_raise_out_environments = @default
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
context
|
28
|
-
let(:env)
|
29
|
-
|
31
|
+
context 'non-raise-out environment' do
|
32
|
+
let(:env) do
|
33
|
+
{'omniauth.error.type' => 'invalid_request', 'omniauth.error.strategy' => ExampleStrategy.new({})}
|
34
|
+
end
|
30
35
|
|
31
|
-
it
|
36
|
+
it 'is a redirect' do
|
32
37
|
status, _, _ = *subject.call(env)
|
33
38
|
expect(status).to eq(302)
|
34
39
|
end
|
35
40
|
|
36
|
-
it
|
41
|
+
it 'includes the SCRIPT_NAME' do
|
37
42
|
_, head, _ = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
|
38
43
|
expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
|
39
44
|
end
|
40
45
|
|
41
|
-
it
|
42
|
-
OmniAuth.config.
|
46
|
+
it 'respects the configured path prefix' do
|
47
|
+
allow(OmniAuth.config).to receive(:path_prefix).and_return('/boo')
|
43
48
|
_, head, _ = *subject.call(env)
|
44
|
-
expect(head[
|
49
|
+
expect(head['Location']).to eq('/boo/failure?message=invalid_request&strategy=test')
|
45
50
|
end
|
46
51
|
|
47
|
-
it
|
52
|
+
it 'includes the origin (escaped) if one is provided' do
|
48
53
|
env.merge! 'omniauth.origin' => '/origin-example'
|
49
54
|
_, head, _ = *subject.call(env)
|
50
55
|
expect(head['Location']).to be_include('&origin=%2Forigin-example')
|