casino-activerecord_authenticator 3.0.0 → 4.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,8 @@ To use the ActiveRecord authenticator, configure it in your cas.yml:
24
24
  email: "email_database_column"
25
25
  fullname: "displayname_database_column"
26
26
 
27
+ Configuration examples for the `connection` part for other databases can be found [here](https://gist.github.com/erichurst/961978).
28
+
27
29
  ## Contributing to casino-activerecord_authenticator
28
30
 
29
31
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -26,6 +26,6 @@ Gem::Specification.new do |s|
26
26
  s.add_runtime_dependency 'activerecord', '~> 4.1.0'
27
27
  s.add_runtime_dependency 'unix-crypt', '~> 1.1'
28
28
  s.add_runtime_dependency 'bcrypt', '~> 3.0'
29
- s.add_runtime_dependency 'casino', '~> 3.0.0'
29
+ s.add_runtime_dependency 'casino', '>= 3.0.0', '< 5.0.0'
30
30
  s.add_runtime_dependency 'phpass-ruby', '~> 0.1'
31
31
  end
@@ -16,13 +16,24 @@ class CASino::ActiveRecordAuthenticator
16
16
  end
17
17
  @options = options.deep_symbolize_keys
18
18
  raise ArgumentError, "Table name is missing" unless @options[:table]
19
+ if @options[:model_name]
20
+ model_name = @options[:model_name]
21
+ else
22
+ model_name = @options[:table]
23
+ if @options[:connection][:database]
24
+ model_name = "#{@options[:connection][:database].gsub(/[^a-zA-Z]+/, '')}_#{model_name}"
25
+ end
26
+ model_name = model_name.classify
27
+ end
28
+ model_class_name = "#{self.class.to_s}::#{model_name}"
19
29
  eval <<-END
20
- class #{self.class.to_s}::#{@options[:table].classify} < AuthDatabase
30
+ class #{model_class_name} < AuthDatabase
21
31
  self.table_name = "#{@options[:table]}"
32
+ self.inheritance_column = :_type_disabled
22
33
  end
23
34
  END
24
35
 
25
- @model = "#{self.class.to_s}::#{@options[:table].classify}".constantize
36
+ @model = model_class_name.constantize
26
37
  @model.establish_connection @options[:connection]
27
38
  end
28
39
 
@@ -31,7 +42,7 @@ class CASino::ActiveRecordAuthenticator
31
42
  password_from_database = user.send(@options[:password_column])
32
43
 
33
44
  if valid_password?(password, password_from_database)
34
- { username: user.send(@options[:username_column]), extra_attributes: extra_attributes(user) }
45
+ user_data(user)
35
46
  else
36
47
  false
37
48
  end
@@ -40,7 +51,18 @@ class CASino::ActiveRecordAuthenticator
40
51
  false
41
52
  end
42
53
 
54
+ def load_user_data(username)
55
+ user = @model.send("find_by_#{@options[:username_column]}!", username)
56
+ user_data(user)
57
+ rescue ActiveRecord::RecordNotFound
58
+ nil
59
+ end
60
+
43
61
  private
62
+ def user_data(user)
63
+ { username: user.send(@options[:username_column]), extra_attributes: extra_attributes(user) }
64
+ end
65
+
44
66
  def valid_password?(password, password_from_database)
45
67
  return false if password_from_database.blank?
46
68
  magic = password_from_database.split('$')[1]
@@ -1,5 +1,5 @@
1
1
  module CASino
2
2
  class ActiveRecordAuthenticator
3
- VERSION = '3.0.0'
3
+ VERSION = '4.0.0.pre.1'
4
4
  end
5
5
  end
@@ -19,6 +19,7 @@ describe CASino::ActiveRecordAuthenticator do
19
19
  }
20
20
  end
21
21
  let(:faulty_options){ options.merge(table: nil) }
22
+ let(:user_class) { described_class::TmpcasinotestauthsqliteUser }
22
23
 
23
24
  subject { described_class.new(options) }
24
25
 
@@ -37,7 +38,7 @@ describe CASino::ActiveRecordAuthenticator do
37
38
  end
38
39
  end
39
40
 
40
- described_class::User.create!(
41
+ user_class.create!(
41
42
  username: 'test',
42
43
  password: '$5$cegeasjoos$vPX5AwDqOTGocGjehr7k1IYp6Kt.U4FmMUa.1l6NrzD', # password: testpassword
43
44
  mail_address: 'mail@example.org')
@@ -51,6 +52,18 @@ describe CASino::ActiveRecordAuthenticator do
51
52
  end
52
53
  end
53
54
 
55
+ describe 'custom model name' do
56
+ let(:model_name) { 'DongerRaiser' }
57
+ before do
58
+ options[:model_name] = model_name
59
+ end
60
+
61
+ it 'should create the model with the name specified' do
62
+ described_class.new(options)
63
+ expect(described_class.const_get(model_name)).to be_a Class
64
+ end
65
+ end
66
+
54
67
  describe 'invalid yaml input' do
55
68
  context 'no hash input' do
56
69
  it 'throws an argument error if the supplied input was not hash' do
@@ -66,6 +79,25 @@ describe CASino::ActiveRecordAuthenticator do
66
79
  end
67
80
  end
68
81
  end
82
+
83
+ describe '#load_user_data' do
84
+ context 'valid username' do
85
+ it 'returns the username' do
86
+ subject.validate('test', 'testpassword')[:username].should eq('test')
87
+ end
88
+
89
+ it 'returns the extra attributes' do
90
+ subject.load_user_data('test')[:extra_attributes][:email].should eq('mail@example.org')
91
+ end
92
+ end
93
+
94
+ context 'invalid username' do
95
+ it 'returns nil' do
96
+ subject.load_user_data('does-not-exist').should eq(nil)
97
+ end
98
+ end
99
+ end
100
+
69
101
  describe '#validate' do
70
102
 
71
103
  context 'valid username' do
@@ -95,7 +127,7 @@ describe CASino::ActiveRecordAuthenticator do
95
127
 
96
128
  context 'NULL password field' do
97
129
  it 'returns false' do
98
- user = described_class::User.first
130
+ user = user_class.first
99
131
  user.password = nil
100
132
  user.save!
101
133
 
@@ -105,7 +137,7 @@ describe CASino::ActiveRecordAuthenticator do
105
137
 
106
138
  context 'empty password field' do
107
139
  it 'returns false' do
108
- user = described_class::User.first
140
+ user = user_class.first
109
141
  user.password = ''
110
142
  user.save!
111
143
 
@@ -122,7 +154,7 @@ describe CASino::ActiveRecordAuthenticator do
122
154
 
123
155
  context 'support for bcrypt' do
124
156
  before do
125
- described_class::User.create!(
157
+ user_class.create!(
126
158
  username: 'test2',
127
159
  password: '$2a$10$dRFLSkYedQ05sqMs3b265e0nnJSoa9RhbpKXU79FDPVeuS1qBG7Jq', # password: testpassword2
128
160
  mail_address: 'mail@example.org')
@@ -137,7 +169,7 @@ describe CASino::ActiveRecordAuthenticator do
137
169
  let(:pepper) { 'abcdefg' }
138
170
 
139
171
  before do
140
- described_class::User.create!(
172
+ user_class.create!(
141
173
  username: 'test3',
142
174
  password: '$2a$10$ndCGPWg5JFMQH/Kl6xKe.OGNaiG7CFIAVsgAOJU75Q6g5/FpY5eX6', # password: testpassword3, pepper: abcdefg
143
175
  mail_address: 'mail@example.org')
@@ -150,7 +182,7 @@ describe CASino::ActiveRecordAuthenticator do
150
182
 
151
183
  context 'support for phpass' do
152
184
  before do
153
- described_class::User.create!(
185
+ user_class.create!(
154
186
  username: 'test4',
155
187
  password: '$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0', # password: test12345
156
188
  mail_address: 'mail@example.org')
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casino-activerecord_authenticator
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
5
- prerelease:
4
+ version: 4.0.0.pre.1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nils Caspar
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-07-19 00:00:00.000000000 Z
13
+ date: 2014-11-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -145,17 +145,23 @@ dependencies:
145
145
  requirement: !ruby/object:Gem::Requirement
146
146
  none: false
147
147
  requirements:
148
- - - ~>
148
+ - - ! '>='
149
149
  - !ruby/object:Gem::Version
150
150
  version: 3.0.0
151
+ - - <
152
+ - !ruby/object:Gem::Version
153
+ version: 5.0.0
151
154
  type: :runtime
152
155
  prerelease: false
153
156
  version_requirements: !ruby/object:Gem::Requirement
154
157
  none: false
155
158
  requirements:
156
- - - ~>
159
+ - - ! '>='
157
160
  - !ruby/object:Gem::Version
158
161
  version: 3.0.0
162
+ - - <
163
+ - !ruby/object:Gem::Version
164
+ version: 5.0.0
159
165
  - !ruby/object:Gem::Dependency
160
166
  name: phpass-ruby
161
167
  requirement: !ruby/object:Gem::Requirement
@@ -213,9 +219,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
219
  required_rubygems_version: !ruby/object:Gem::Requirement
214
220
  none: false
215
221
  requirements:
216
- - - ! '>='
222
+ - - ! '>'
217
223
  - !ruby/object:Gem::Version
218
- version: '0'
224
+ version: 1.3.1
219
225
  requirements: []
220
226
  rubyforge_project:
221
227
  rubygems_version: 1.8.23