omniauth-rightsignature 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/omniauth/test.rb DELETED
@@ -1,8 +0,0 @@
1
- module OmniAuth
2
- # Support for testing OmniAuth strategies.
3
- module Test
4
- autoload :PhonySession, 'omniauth/test/phony_session'
5
- autoload :StrategyMacros, 'omniauth/test/strategy_macros'
6
- autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
7
- end
8
- end
@@ -1,3 +0,0 @@
1
- module OmniAuth
2
- VERSION = '1.2.2'
3
- end
data/lib/omniauth.rb DELETED
@@ -1,170 +0,0 @@
1
- require 'rack'
2
- require 'singleton'
3
- require 'logger'
4
-
5
- module OmniAuth
6
- class Error < StandardError; end
7
-
8
- module Strategies
9
- autoload :Developer, 'omniauth/strategies/developer'
10
- end
11
-
12
- autoload :Builder, 'omniauth/builder'
13
- autoload :Strategy, 'omniauth/strategy'
14
- autoload :Test, 'omniauth/test'
15
- autoload :Form, 'omniauth/form'
16
- autoload :AuthHash, 'omniauth/auth_hash'
17
- autoload :FailureEndpoint, 'omniauth/failure_endpoint'
18
-
19
- def self.strategies
20
- @strategies ||= []
21
- end
22
-
23
- class Configuration
24
- include Singleton
25
-
26
- def self.default_logger
27
- logger = Logger.new(STDOUT)
28
- logger.progname = 'omniauth'
29
- logger
30
- end
31
-
32
- def self.defaults
33
- @defaults ||= {
34
- :camelizations => {},
35
- :path_prefix => '/auth',
36
- :on_failure => OmniAuth::FailureEndpoint,
37
- :failure_raise_out_environments => ['development'],
38
- :before_request_phase => nil,
39
- :before_callback_phase => nil,
40
- :before_options_phase => nil,
41
- :form_css => Form::DEFAULT_CSS,
42
- :test_mode => false,
43
- :logger => default_logger,
44
- :allowed_request_methods => [:get, :post],
45
- :mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
46
- }
47
- end
48
-
49
- def initialize
50
- self.class.defaults.each_pair { |k, v| send("#{k}=", v) }
51
- end
52
-
53
- def on_failure(&block)
54
- if block_given?
55
- @on_failure = block
56
- else
57
- @on_failure
58
- end
59
- end
60
-
61
- def before_callback_phase(&block)
62
- if block_given?
63
- @before_callback_phase = block
64
- else
65
- @before_callback_phase
66
- end
67
- end
68
-
69
- def before_options_phase(&block)
70
- if block_given?
71
- @before_options_phase = block
72
- else
73
- @before_options_phase
74
- end
75
- end
76
-
77
- def before_request_phase(&block)
78
- if block_given?
79
- @before_request_phase = block
80
- else
81
- @before_request_phase
82
- end
83
- end
84
-
85
- def add_mock(provider, mock = {})
86
- # Stringify keys recursively one level.
87
- mock.keys.each do |key|
88
- mock[key.to_s] = mock.delete(key)
89
- end
90
- mock.each_pair do |_key, val|
91
- if val.is_a? Hash
92
- val.keys.each do |subkey|
93
- val[subkey.to_s] = val.delete(subkey)
94
- end
95
- else
96
- next
97
- end
98
- end
99
-
100
- # Merge with the default mock and ensure provider is correct.
101
- mock = mock_auth[:default].dup.merge(mock)
102
- mock['provider'] = provider.to_s
103
-
104
- # Add it to the mocks.
105
- mock_auth[provider.to_sym] = mock
106
- end
107
-
108
- # This is a convenience method to be used by strategy authors
109
- # so that they can add special cases to the camelization utility
110
- # method that allows OmniAuth::Builder to work.
111
- #
112
- # @param name [String] The underscored name, e.g. `oauth`
113
- # @param camelized [String] The properly camelized name, e.g. 'OAuth'
114
- def add_camelization(name, camelized)
115
- camelizations[name.to_s] = camelized.to_s
116
- end
117
-
118
- attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
119
- attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations, :logger
120
- end
121
-
122
- def self.config
123
- Configuration.instance
124
- end
125
-
126
- def self.configure
127
- yield config
128
- end
129
-
130
- def self.logger
131
- config.logger
132
- end
133
-
134
- def self.mock_auth_for(provider)
135
- config.mock_auth[provider.to_sym] || config.mock_auth[:default]
136
- end
137
-
138
- module Utils
139
- module_function
140
-
141
- def form_css
142
- "<style type='text/css'>#{OmniAuth.config.form_css}</style>"
143
- end
144
-
145
- def deep_merge(hash, other_hash)
146
- target = hash.dup
147
-
148
- other_hash.keys.each do |key|
149
- if other_hash[key].is_a?(::Hash) && hash[key].is_a?(::Hash)
150
- target[key] = deep_merge(target[key], other_hash[key])
151
- next
152
- end
153
-
154
- target[key] = other_hash[key]
155
- end
156
-
157
- target
158
- end
159
-
160
- def camelize(word, first_letter_in_uppercase = true)
161
- return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
162
-
163
- if first_letter_in_uppercase
164
- word.to_s.gsub(/\/(.?)/) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
165
- else
166
- word.first + camelize(word)[1..-1]
167
- end
168
- end
169
- end
170
- end
data/spec/helper.rb DELETED
@@ -1,55 +0,0 @@
1
- if RUBY_VERSION >= '1.9'
2
- require 'simplecov'
3
- require 'coveralls'
4
-
5
- SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
6
-
7
- SimpleCov.start do
8
- add_filter '/spec'
9
- minimum_coverage(93.05)
10
- end
11
- end
12
-
13
- require 'rspec'
14
- require 'rack/test'
15
- require 'omniauth'
16
- require 'omniauth/test'
17
-
18
- OmniAuth.config.logger = Logger.new('/dev/null')
19
-
20
- RSpec.configure do |config|
21
- config.include Rack::Test::Methods
22
- config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
23
- config.expect_with :rspec do |c|
24
- c.syntax = :expect
25
- end
26
- end
27
-
28
- class ExampleStrategy
29
- include OmniAuth::Strategy
30
- attr_reader :last_env
31
- option :name, 'test'
32
-
33
- def call(env)
34
- self.call!(env)
35
- end
36
-
37
- def initialize(*args, &block)
38
- super
39
- @fail = nil
40
- end
41
-
42
- def request_phase
43
- @fail = fail!(options[:failure]) if options[:failure]
44
- @last_env = env
45
- return @fail if @fail
46
- fail('Request Phase')
47
- end
48
-
49
- def callback_phase
50
- @fail = fail!(options[:failure]) if options[:failure]
51
- @last_env = env
52
- return @fail if @fail
53
- fail('Callback Phase')
54
- end
55
- end
@@ -1,109 +0,0 @@
1
- require 'helper'
2
-
3
- describe OmniAuth::AuthHash do
4
- subject { OmniAuth::AuthHash.new }
5
- it 'converts a supplied info key into an InfoHash object' do
6
- subject.info = {:first_name => 'Awesome'}
7
- expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
8
- expect(subject.info.first_name).to eq('Awesome')
9
- end
10
-
11
- describe '#valid?' do
12
- subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
13
-
14
- it 'is valid with the right parameters' do
15
- expect(subject).to be_valid
16
- end
17
-
18
- it 'requires a uid' do
19
- subject.uid = nil
20
- expect(subject).not_to be_valid
21
- end
22
-
23
- it 'requires a provider' do
24
- subject.provider = nil
25
- expect(subject).not_to be_valid
26
- end
27
-
28
- it 'requires a name in the user info hash' do
29
- subject.info.name = nil
30
- expect(subject).not_to be_valid
31
- end
32
- end
33
-
34
- describe '#name' do
35
- subject do
36
- OmniAuth::AuthHash.new(:info => {
37
- :name => 'Phillip J. Fry',
38
- :first_name => 'Phillip',
39
- :last_name => 'Fry',
40
- :nickname => 'meatbag',
41
- :email => 'fry@planetexpress.com',
42
- })
43
- end
44
-
45
- it 'defaults to the name key' do
46
- expect(subject.info.name).to eq('Phillip J. Fry')
47
- end
48
-
49
- it 'falls back to go to first_name last_name concatenation' do
50
- subject.info.name = nil
51
- expect(subject.info.name).to eq('Phillip Fry')
52
- end
53
-
54
- it 'displays only a first or last name if only that is available' do
55
- subject.info.name = nil
56
- subject.info.first_name = nil
57
- expect(subject.info.name).to eq('Fry')
58
- end
59
-
60
- it 'displays the nickname if no name, first, or last is available' do
61
- subject.info.name = nil
62
- %w(first_name last_name).each { |k| subject.info[k] = nil }
63
- expect(subject.info.name).to eq('meatbag')
64
- end
65
-
66
- it 'displays the email if no name, first, last, or nick is available' do
67
- subject.info.name = nil
68
- %w(first_name last_name nickname).each { |k| subject.info[k] = nil }
69
- expect(subject.info.name).to eq('fry@planetexpress.com')
70
- end
71
- end
72
-
73
- describe '#to_hash' do
74
- subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Example User') }
75
- let(:hash) { subject.to_hash }
76
-
77
- it 'is a plain old hash' do
78
- expect(hash.class).to eq(::Hash)
79
- end
80
-
81
- it 'has string keys' do
82
- expect(hash.keys).to be_include('uid')
83
- end
84
-
85
- it 'converts an info hash as well' do
86
- subject.info = {:first_name => 'Example', :last_name => 'User'}
87
- expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
88
- expect(subject.to_hash['info'].class).to eq(::Hash)
89
- end
90
-
91
- it 'supplies the calculated name in the converted hash' do
92
- subject.info = {:first_name => 'Examplar', :last_name => 'User'}
93
- expect(hash['info']['name']).to eq('Examplar User')
94
- end
95
-
96
- it "does not pollute the URL hash with 'name' etc" do
97
- subject.info = {'urls' => {'Homepage' => 'http://homepage.com'}}
98
- expect(subject.to_hash['info']['urls']).to eq('Homepage' => 'http://homepage.com')
99
- end
100
- end
101
-
102
- describe OmniAuth::AuthHash::InfoHash do
103
- describe '#valid?' do
104
- it 'is valid if there is a name' do
105
- expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
106
- end
107
- end
108
- end
109
- end
@@ -1,50 +0,0 @@
1
- require 'helper'
2
-
3
- describe OmniAuth::Builder do
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
- OmniAuth::Builder.new(nil) do
8
- provider :my_strategy
9
- end
10
- end
11
-
12
- it 'accepts a class' do
13
- class ExampleClass; end
14
-
15
- expect do
16
- OmniAuth::Builder.new(nil) do
17
- provider ::ExampleClass
18
- end
19
- end.not_to raise_error
20
- end
21
-
22
- it "raises a helpful LoadError message if it can't find the class" do
23
- expect do
24
- OmniAuth::Builder.new(nil) do
25
- provider :lorax
26
- end
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
- end
29
- end
30
-
31
- describe '#options' do
32
- it 'merges provided options in' do
33
- k = Class.new
34
- b = OmniAuth::Builder.new(nil)
35
- expect(b).to receive(:use).with(k, :foo => 'bar', :baz => 'tik')
36
-
37
- b.options :foo => 'bar'
38
- b.provider k, :baz => 'tik'
39
- end
40
-
41
- it 'adds an argument if no options are provided' do
42
- k = Class.new
43
- b = OmniAuth::Builder.new(nil)
44
- expect(b).to receive(:use).with(k, :foo => 'bar')
45
-
46
- b.options :foo => 'bar'
47
- b.provider k
48
- end
49
- end
50
- end
@@ -1,58 +0,0 @@
1
- require 'helper'
2
-
3
- describe OmniAuth::FailureEndpoint do
4
- subject { OmniAuth::FailureEndpoint }
5
-
6
- context 'raise-out environment' do
7
- before do
8
- @rack_env = 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']
13
- end
14
-
15
- it 'raises out the error' do
16
- expect do
17
- subject.call('omniauth.error' => StandardError.new('Blah'))
18
- end.to raise_error(StandardError, 'Blah')
19
- end
20
-
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')
23
- end
24
-
25
- after do
26
- ENV['RACK_ENV'] = @rack_env
27
- OmniAuth.config.failure_raise_out_environments = @default
28
- end
29
- end
30
-
31
- context 'non-raise-out environment' do
32
- let(:env) do
33
- {'omniauth.error.type' => 'invalid_request', 'omniauth.error.strategy' => ExampleStrategy.new({})}
34
- end
35
-
36
- it 'is a redirect' do
37
- status, _, _ = *subject.call(env)
38
- expect(status).to eq(302)
39
- end
40
-
41
- it 'includes the SCRIPT_NAME' do
42
- _, head, _ = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
43
- expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
44
- end
45
-
46
- it 'respects the configured path prefix' do
47
- allow(OmniAuth.config).to receive(:path_prefix).and_return('/boo')
48
- _, head, _ = *subject.call(env)
49
- expect(head['Location']).to eq('/boo/failure?message=invalid_request&strategy=test')
50
- end
51
-
52
- it 'includes the origin (escaped) if one is provided' do
53
- env.merge! 'omniauth.origin' => '/origin-example'
54
- _, head, _ = *subject.call(env)
55
- expect(head['Location']).to be_include('&origin=%2Forigin-example')
56
- end
57
- end
58
- end