omniauth-identity2 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ describe(OmniAuth::Identity::Models::ActiveRecord, :db => true) do
2
+ class TestIdentity < OmniAuth::Identity::Models::ActiveRecord; end
3
+
4
+ describe "model", type: :model do
5
+ subject { TestIdentity }
6
+
7
+ it 'should delegate locate to the where query method' do
8
+ allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
9
+ expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
10
+ end
11
+
12
+ it 'should not use STI rules for its table name' do
13
+ expect(subject.table_name).to eq('test_identities')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ describe(OmniAuth::Identity::Models::CouchPotatoModule, :db => true) do
2
+ class CouchPotatoTestIdentity
3
+ include CouchPotato::Persistence
4
+ include OmniAuth::Identity::Models::CouchPotatoModule
5
+ auth_key :ham_sandwich
6
+ end
7
+
8
+ describe 'model', type: :model do
9
+ subject { CouchPotatoTestIdentity }
10
+
11
+ it 'should delegate locate to the where query method' do
12
+ allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
13
+ expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ describe(OmniAuth::Identity::Models::DataMapper, :db => true) do
2
+ class DataMapperTestIdentity
3
+ include DataMapper::Resource
4
+ include OmniAuth::Identity::Models::DataMapper
5
+
6
+ property :id, Serial
7
+ auth_key :ham_sandwich
8
+ end
9
+
10
+
11
+ before :all do
12
+ DataMapper.finalize
13
+ @resource = DataMapperTestIdentity.new
14
+ end
15
+
16
+ describe 'model', type: :model do
17
+ subject { DataMapperTestIdentity }
18
+
19
+ it 'should delegate locate to the all query method' do
20
+ allow(subject).to receive(:all).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
21
+ expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ describe(OmniAuth::Identity::Models::Mongoid, :db => true) do
2
+ class MongoidTestIdentity
3
+ include Mongoid::Document
4
+ include OmniAuth::Identity::Models::Mongoid
5
+ auth_key :ham_sandwich
6
+ store_in database: 'db1', collection: 'mongoid_test_identities', client: 'secondary'
7
+ end
8
+
9
+ describe "model", type: :model do
10
+ subject { MongoidTestIdentity }
11
+
12
+ it { is_expected.to be_mongoid_document }
13
+
14
+ it 'does not munge collection name' do
15
+ is_expected.to be_stored_in(database: 'db1', collection: 'mongoid_test_identities', client: 'secondary')
16
+ end
17
+
18
+ it 'should delegate locate to the where query method' do
19
+ allow(subject).to receive(:where).with('ham_sandwich' => 'open faced', 'category' => 'sandwiches').and_return(['wakka'])
20
+ expect(subject.locate('ham_sandwich' => 'open faced', 'category' => 'sandwiches')).to eq('wakka')
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ class HasTheMethod
2
+ def self.has_secure_password; end
3
+ end
4
+
5
+ class DoesNotHaveTheMethod
6
+ end
7
+
8
+ describe OmniAuth::Identity::SecurePassword do
9
+ it 'should extend with the class methods if it does not have the method' do
10
+ expect(DoesNotHaveTheMethod).to receive(:extend).with(OmniAuth::Identity::SecurePassword::ClassMethods)
11
+ DoesNotHaveTheMethod.send(:include, OmniAuth::Identity::SecurePassword)
12
+ end
13
+
14
+ it 'should not extend if the method is already defined' do
15
+ expect(HasTheMethod).not_to receive(:extend)
16
+ HasTheMethod.send(:include, OmniAuth::Identity::SecurePassword)
17
+ end
18
+
19
+ it 'should respond to has_secure_password afterwards' do
20
+ [HasTheMethod,DoesNotHaveTheMethod].each do |klass|
21
+ klass.send(:include, OmniAuth::Identity::SecurePassword)
22
+ expect(klass).to be_respond_to(:has_secure_password)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,141 @@
1
+ class MockIdentity; end
2
+
3
+ describe OmniAuth::Strategies::Identity do
4
+ attr_accessor :app
5
+
6
+ let(:auth_hash){ last_response.headers['env']['omniauth.auth'] }
7
+ let(:identity_hash){ last_response.headers['env']['omniauth.identity'] }
8
+
9
+ # customize rack app for testing, if block is given, reverts to default
10
+ # rack app after testing is done
11
+ def set_app!(identity_options = {})
12
+ identity_options = {:model => MockIdentity}.merge(identity_options)
13
+ old_app = self.app
14
+ self.app = Rack::Builder.app do
15
+ use Rack::Session::Cookie, secret: '1234567890qwertyuiop'
16
+ use OmniAuth::Strategies::Identity, identity_options
17
+ run lambda{|env| [404, {'env' => env}, ["HELLO!"]]}
18
+ end
19
+ if block_given?
20
+ yield
21
+ self.app = old_app
22
+ end
23
+ self.app
24
+ end
25
+
26
+ before(:all) do
27
+ set_app!
28
+ end
29
+
30
+ describe '#request_phase' do
31
+ it 'should display a form' do
32
+ get '/auth/identity'
33
+ expect(last_response.body).to be_include("<form")
34
+ end
35
+ end
36
+
37
+ describe '#callback_phase' do
38
+ let(:user){ double(:uid => 'user1', :info => {'name' => 'Rockefeller'})}
39
+
40
+ context 'with valid credentials' do
41
+ before do
42
+ allow(MockIdentity).to receive('auth_key').and_return('email')
43
+ expect(MockIdentity).to receive('authenticate').with({'email' => 'john'},'awesome').and_return(user)
44
+ post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
45
+ end
46
+
47
+ it 'should populate the auth hash' do
48
+ expect(auth_hash).to be_kind_of(Hash)
49
+ end
50
+
51
+ it 'should populate the uid' do
52
+ expect(auth_hash['uid']).to eq('user1')
53
+ end
54
+
55
+ it 'should populate the info hash' do
56
+ expect(auth_hash['info']).to eq({'name' => 'Rockefeller'})
57
+ end
58
+ end
59
+
60
+ context 'with invalid credentials' do
61
+ before do
62
+ allow(MockIdentity).to receive('auth_key').and_return('email')
63
+ OmniAuth.config.on_failure = lambda{|env| [401, {}, [env['omniauth.error.type'].inspect]]}
64
+ expect(MockIdentity).to receive(:authenticate).with({'email' => 'wrong'},'login').and_return(false)
65
+ post '/auth/identity/callback', :auth_key => 'wrong', :password => 'login'
66
+ end
67
+
68
+ it 'should fail with :invalid_credentials' do
69
+ expect(last_response.body).to eq(':invalid_credentials')
70
+ end
71
+ end
72
+
73
+ context 'with auth scopes' do
74
+
75
+ it 'should evaluate and pass through conditions proc' do
76
+ allow(MockIdentity).to receive('auth_key').and_return('email')
77
+ set_app!( :locate_conditions => lambda{|req| {model.auth_key => req['auth_key'], 'user_type' => 'admin'} } )
78
+ expect(MockIdentity).to receive('authenticate').with( {'email' => 'john', 'user_type' => 'admin'}, 'awesome' ).and_return(user)
79
+ post '/auth/identity/callback', :auth_key => 'john', :password => 'awesome'
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#registration_form' do
85
+ it 'should trigger from /auth/identity/register by default' do
86
+ get '/auth/identity/register'
87
+ expect(last_response.body).to be_include("Register Identity")
88
+ end
89
+ end
90
+
91
+ describe '#registration_phase' do
92
+ context 'with successful creation' do
93
+ let(:properties){ {
94
+ :name => 'Awesome Dude',
95
+ :email => 'awesome@example.com',
96
+ :password => 'face',
97
+ :password_confirmation => 'face'
98
+ } }
99
+
100
+ before do
101
+ allow(MockIdentity).to receive('auth_key').and_return('email')
102
+ m = double(:uid => 'abc', :name => 'Awesome Dude', :email => 'awesome@example.com', :info => {:name => 'DUUUUDE!'}, :persisted? => true)
103
+ expect(MockIdentity).to receive(:create).with(properties).and_return(m)
104
+ end
105
+
106
+ it 'should set the auth hash' do
107
+ post '/auth/identity/register', properties
108
+ expect(auth_hash['uid']).to eq('abc')
109
+ end
110
+ end
111
+
112
+ context 'with invalid identity' do
113
+ let(:properties) { {
114
+ :name => 'Awesome Dude',
115
+ :email => 'awesome@example.com',
116
+ :password => 'NOT',
117
+ :password_confirmation => 'MATCHING'
118
+ } }
119
+
120
+ before do
121
+ expect(MockIdentity).to receive(:create).with(properties).and_return(double(:persisted? => false))
122
+ end
123
+
124
+ context 'default' do
125
+ it 'should show registration form' do
126
+ post '/auth/identity/register', properties
127
+ expect(last_response.body).to be_include("Register Identity")
128
+ end
129
+ end
130
+
131
+ context 'custom on_failed_registration endpoint' do
132
+ it 'should set the identity hash' do
133
+ set_app!(:on_failed_registration => lambda{|env| [404, {'env' => env}, ["HELLO!"]]}) do
134
+ post '/auth/identity/register', properties
135
+ expect(identity_hash).not_to be_nil
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup :default, :development, :test
4
+
5
+ # Third party gems to help with testing
6
+ require 'simplecov'
7
+ SimpleCov.start
8
+
9
+ require 'rack/test'
10
+ require 'mongoid-rspec'
11
+ require 'byebug'
12
+
13
+ # This gem
14
+ require 'omniauth/identity'
15
+
16
+ RSpec.configure do |config|
17
+ config.include Rack::Test::Methods
18
+ config.include Mongoid::Matchers, type: :model
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,264 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-identity2
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.0'
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Roberts
8
+ - Michael Bleigh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2020-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bcrypt
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: maruku
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: simplecov
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rack-test
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3'
112
+ - !ruby/object:Gem::Dependency
113
+ name: activerecord
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: mongoid
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: datamapper
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: bson_ext
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: byebug
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: couch_potato
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ description: Internal authentication handlers for OmniAuth. A modern version of the
197
+ Omniauth Identity strategy.
198
+ email:
199
+ - andy.roberts.uk@gmail.com
200
+ executables: []
201
+ extensions: []
202
+ extra_rdoc_files: []
203
+ files:
204
+ - ".gitignore"
205
+ - ".rspec"
206
+ - CHANGELOG.md
207
+ - Gemfile
208
+ - Guardfile
209
+ - LICENSE
210
+ - README.markdown
211
+ - Rakefile
212
+ - lib/omniauth-identity.rb
213
+ - lib/omniauth-identity/version.rb
214
+ - lib/omniauth/identity.rb
215
+ - lib/omniauth/identity/model.rb
216
+ - lib/omniauth/identity/models/active_record.rb
217
+ - lib/omniauth/identity/models/couch_potato.rb
218
+ - lib/omniauth/identity/models/data_mapper.rb
219
+ - lib/omniauth/identity/models/mongoid.rb
220
+ - lib/omniauth/identity/secure_password.rb
221
+ - lib/omniauth/strategies/identity.rb
222
+ - omniauth-identity.gemspec
223
+ - spec/omniauth/identity/model_spec.rb
224
+ - spec/omniauth/identity/models/active_record_spec.rb
225
+ - spec/omniauth/identity/models/couch_potato_spec.rb
226
+ - spec/omniauth/identity/models/data_mapper_spec.rb
227
+ - spec/omniauth/identity/models/mongoid_spec.rb
228
+ - spec/omniauth/identity/secure_password_spec.rb
229
+ - spec/omniauth/strategies/identity_spec.rb
230
+ - spec/spec_helper.rb
231
+ homepage: https://github.com/Jellybooks/omniauth-identity2
232
+ licenses:
233
+ - MIT
234
+ metadata: {}
235
+ post_install_message:
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ required_rubygems_version: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: 1.3.6
249
+ requirements: []
250
+ rubyforge_project:
251
+ rubygems_version: 2.7.10
252
+ signing_key:
253
+ specification_version: 4
254
+ summary: Internal authentication handlers for OmniAuth. A modern version of the Omniauth
255
+ Identity strategy.
256
+ test_files:
257
+ - spec/omniauth/identity/model_spec.rb
258
+ - spec/omniauth/identity/models/active_record_spec.rb
259
+ - spec/omniauth/identity/models/couch_potato_spec.rb
260
+ - spec/omniauth/identity/models/data_mapper_spec.rb
261
+ - spec/omniauth/identity/models/mongoid_spec.rb
262
+ - spec/omniauth/identity/secure_password_spec.rb
263
+ - spec/omniauth/strategies/identity_spec.rb
264
+ - spec/spec_helper.rb