casino_core-authenticator-activerecord 1.1.4 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,35 +15,4 @@ doc
15
15
  # jeweler generated
16
16
  pkg
17
17
 
18
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
- #
20
- # * Create a file at ~/.gitignore
21
- # * Include files you want ignored
22
- # * Run: git config --global core.excludesfile ~/.gitignore
23
- #
24
- # After doing this, these files will be ignored in all your git projects,
25
- # saving you from having to 'pollute' every project you touch with them
26
- #
27
- # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
- #
29
- # For MacOS:
30
- #
31
- #.DS_Store
32
-
33
- # For TextMate
34
- #*.tmproj
35
- #tmtags
36
-
37
- # For emacs:
38
- #*~
39
- #\#*
40
- #.\#*
41
-
42
- # For vim:
43
- #*.swp
44
-
45
- # For redcar:
46
- #.redcar
47
-
48
- # For rubinius:
49
- #*.rbc
18
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format Fivemat
@@ -1 +1 @@
1
- ruby-1.9.3-p194
1
+ 1.9.3-p194
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -19,6 +19,7 @@ To use the ActiveRecord authenticator, configure it in your cas.yml:
19
19
  table: "users"
20
20
  username_column: "username"
21
21
  password_column: "password"
22
+ pepper: "suffix of the password" # optional
22
23
  extra_attributes:
23
24
  email: "email_database_column"
24
25
  fullname: "displayname_database_column"
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'simplecov', '~> 0.7'
23
23
  s.add_development_dependency 'sqlite3', '~> 1.3.7'
24
24
  s.add_development_dependency 'coveralls'
25
+ s.add_development_dependency 'fivemat'
25
26
 
26
27
  s.add_runtime_dependency 'activerecord', '~> 3.2.12'
27
28
  s.add_runtime_dependency 'unix-crypt', '~> 1.1'
@@ -38,6 +38,7 @@ class CASinoCore::Authenticator::ActiveRecord
38
38
 
39
39
  private
40
40
  def valid_password?(password, password_from_database)
41
+ return false if password_from_database.blank?
41
42
  magic = password_from_database.split('$')[1]
42
43
  case magic
43
44
  when /\A2a?\z/
@@ -48,7 +49,8 @@ class CASinoCore::Authenticator::ActiveRecord
48
49
  end
49
50
 
50
51
  def valid_password_with_bcrypt?(password, password_from_database)
51
- BCrypt::Password.new(password_from_database) == password
52
+ password_with_pepper = password + @options[:pepper].to_s
53
+ BCrypt::Password.new(password_from_database) == password_with_pepper
52
54
  end
53
55
 
54
56
  def valid_password_with_unix_crypt?(password, password_from_database)
@@ -57,9 +59,13 @@ class CASinoCore::Authenticator::ActiveRecord
57
59
 
58
60
  def extra_attributes(user)
59
61
  attributes = {}
60
- @options[:extra_attributes].each do |attribute_name, database_column|
62
+ extra_attributes_option.each do |attribute_name, database_column|
61
63
  attributes[attribute_name] = user.send(database_column)
62
64
  end
63
65
  attributes
64
66
  end
67
+
68
+ def extra_attributes_option
69
+ @options[:extra_attributes] || {}
70
+ end
65
71
  end
@@ -1,7 +1,7 @@
1
1
  module CASinoCore
2
2
  class Authenticator
3
3
  class ActiveRecord
4
- VERSION = '1.1.4'
4
+ VERSION = '1.1.6'
5
5
  end
6
6
  end
7
7
  end
@@ -3,6 +3,8 @@ require 'casino_core/authenticator/activerecord'
3
3
 
4
4
  describe CASinoCore::Authenticator::ActiveRecord do
5
5
 
6
+ let(:pepper) { nil }
7
+ let(:extra_attributes) {{ email: 'mail_address' }}
6
8
  let(:options) do
7
9
  {
8
10
  connection: {
@@ -12,9 +14,8 @@ describe CASinoCore::Authenticator::ActiveRecord do
12
14
  table: 'users',
13
15
  username_column: 'username',
14
16
  password_column: 'password',
15
- extra_attributes: {
16
- email: 'mail_address'
17
- }
17
+ pepper: pepper,
18
+ extra_attributes: extra_attributes
18
19
  }
19
20
  end
20
21
 
@@ -58,6 +59,14 @@ describe CASinoCore::Authenticator::ActiveRecord do
58
59
  it 'returns the extra attributes' do
59
60
  @authenticator.validate('test', 'testpassword')[:extra_attributes][:email].should eq('mail@example.org')
60
61
  end
62
+
63
+ context 'when no extra attributes given' do
64
+ let(:extra_attributes) { nil }
65
+
66
+ it 'returns an empty hash for extra attributes' do
67
+ @authenticator.validate('test', 'testpassword')[:extra_attributes].should eq({})
68
+ end
69
+ end
61
70
  end
62
71
 
63
72
  context 'invalid password' do
@@ -65,6 +74,26 @@ describe CASinoCore::Authenticator::ActiveRecord do
65
74
  @authenticator.validate('test', 'wrongpassword').should eq(false)
66
75
  end
67
76
  end
77
+
78
+ context 'NULL password field' do
79
+ it 'returns false' do
80
+ user = CASinoCore::Authenticator::ActiveRecord::User.first
81
+ user.password = nil
82
+ user.save!
83
+
84
+ @authenticator.validate('test', 'wrongpassword').should eq(false)
85
+ end
86
+ end
87
+
88
+ context 'empty password field' do
89
+ it 'returns false' do
90
+ user = CASinoCore::Authenticator::ActiveRecord::User.first
91
+ user.password = ''
92
+ user.save!
93
+
94
+ @authenticator.validate('test', 'wrongpassword').should eq(false)
95
+ end
96
+ end
68
97
  end
69
98
 
70
99
  context 'invalid username' do
@@ -86,6 +115,21 @@ describe CASinoCore::Authenticator::ActiveRecord do
86
115
  end
87
116
  end
88
117
 
118
+ context 'support for bcrypt with pepper' do
119
+ let(:pepper) { 'abcdefg' }
120
+
121
+ before do
122
+ CASinoCore::Authenticator::ActiveRecord::User.create!(
123
+ username: 'test3',
124
+ password: '$2a$10$ndCGPWg5JFMQH/Kl6xKe.OGNaiG7CFIAVsgAOJU75Q6g5/FpY5eX6', # password: testpassword3, pepper: abcdefg
125
+ mail_address: 'mail@example.org')
126
+ end
127
+
128
+ it 'is able to handle bcrypt password hashes' do
129
+ @authenticator.validate('test3', 'testpassword3').should be_instance_of(Hash)
130
+ end
131
+ end
132
+
89
133
  end
90
134
 
91
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casino_core-authenticator-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-05-07 00:00:00.000000000 Z
13
+ date: 2013-07-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -92,6 +92,22 @@ dependencies:
92
92
  - - ! '>='
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: fivemat
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
95
111
  - !ruby/object:Gem::Dependency
96
112
  name: activerecord
97
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,10 +166,11 @@ extensions: []
150
166
  extra_rdoc_files: []
151
167
  files:
152
168
  - .gitignore
169
+ - .rspec
153
170
  - .ruby-gemset
154
171
  - .ruby-version
172
+ - .travis.yml
155
173
  - Gemfile
156
- - Gemfile.lock
157
174
  - LICENSE.txt
158
175
  - README.md
159
176
  - Rakefile
@@ -1,66 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- casino_core-authenticator-activerecord (1.1.3)
5
- activerecord (~> 3.2.12)
6
- bcrypt-ruby (~> 3.0)
7
- unix-crypt (~> 1.1)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (3.2.13)
13
- activesupport (= 3.2.13)
14
- builder (~> 3.0.0)
15
- activerecord (3.2.13)
16
- activemodel (= 3.2.13)
17
- activesupport (= 3.2.13)
18
- arel (~> 3.0.2)
19
- tzinfo (~> 0.3.29)
20
- activesupport (3.2.13)
21
- i18n (= 0.6.1)
22
- multi_json (~> 1.0)
23
- arel (3.0.2)
24
- bcrypt-ruby (3.0.1)
25
- builder (3.0.4)
26
- colorize (0.5.8)
27
- coveralls (0.6.4)
28
- colorize
29
- multi_json (~> 1.3)
30
- rest-client
31
- simplecov (>= 0.7)
32
- thor
33
- diff-lcs (1.2.2)
34
- i18n (0.6.1)
35
- mime-types (1.22)
36
- multi_json (1.7.2)
37
- rake (10.0.4)
38
- rest-client (1.6.7)
39
- mime-types (>= 1.16)
40
- rspec (2.13.0)
41
- rspec-core (~> 2.13.0)
42
- rspec-expectations (~> 2.13.0)
43
- rspec-mocks (~> 2.13.0)
44
- rspec-core (2.13.1)
45
- rspec-expectations (2.13.0)
46
- diff-lcs (>= 1.1.3, < 2.0)
47
- rspec-mocks (2.13.0)
48
- simplecov (0.7.1)
49
- multi_json (~> 1.0)
50
- simplecov-html (~> 0.7.1)
51
- simplecov-html (0.7.1)
52
- sqlite3 (1.3.7)
53
- thor (0.18.1)
54
- tzinfo (0.3.37)
55
- unix-crypt (1.1.0)
56
-
57
- PLATFORMS
58
- ruby
59
-
60
- DEPENDENCIES
61
- casino_core-authenticator-activerecord!
62
- coveralls
63
- rake (~> 10.0)
64
- rspec (~> 2.12)
65
- simplecov (~> 0.7)
66
- sqlite3 (~> 1.3.7)