google-authenticator-rails 0.0.4 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -6
- data/Appraisals +27 -0
- data/README.md +185 -23
- data/Rakefile +26 -0
- data/gemfiles/rails2.3.gemfile +7 -0
- data/gemfiles/rails2.3.gemfile.lock +45 -0
- data/gemfiles/rails3.0.gemfile +7 -0
- data/gemfiles/rails3.0.gemfile.lock +70 -0
- data/gemfiles/rails3.1.gemfile +7 -0
- data/gemfiles/rails3.1.gemfile.lock +79 -0
- data/gemfiles/rails3.2..gemfile +7 -0
- data/gemfiles/rails3.2..gemfile.lock +78 -0
- data/gemfiles/rails4.0.gemfile +8 -0
- data/gemfiles/rails4.0.gemfile.lock +75 -0
- data/gemfiles/rails4.1.gemfile +8 -0
- data/gemfiles/rails4.1.gemfile.lock +75 -0
- data/google-authenticator.gemspec +11 -4
- data/lib/google-authenticator-rails/action_controller/rails_adapter.rb +3 -1
- data/lib/google-authenticator-rails/active_record/acts_as_google_authenticated.rb +31 -21
- data/lib/google-authenticator-rails/active_record/helpers.rb +10 -14
- data/lib/google-authenticator-rails/session/persistence.rb +13 -7
- data/lib/google-authenticator-rails/version.rb +1 -1
- data/lib/google-authenticator-rails.rb +31 -9
- data/spec/google_authenticator_spec.rb +50 -26
- data/spec/session/persistance_spec.rb +27 -6
- data/spec/spec_helper.rb +26 -4
- metadata +53 -38
@@ -16,16 +16,33 @@ describe GoogleAuthenticatorRails::Session::Base do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'session' do
|
19
|
-
before { set_cookie_for(user) }
|
20
|
-
after { clear_cookie }
|
19
|
+
before { set_cookie_for(user) unless user.nil? }
|
20
|
+
after { clear_cookie unless user.nil? }
|
21
21
|
|
22
22
|
it { should be_a UserMfaSession }
|
23
23
|
its(:record) { should eq user }
|
24
|
+
|
25
|
+
context 'custom lookup token' do
|
26
|
+
let(:user) { SaltUser.create(:password => "password", :email => "email@example.com") }
|
27
|
+
|
28
|
+
subject { SaltUserMfaSession.find }
|
29
|
+
|
30
|
+
it { should be_a SaltUserMfaSession }
|
31
|
+
its(:record) { should eq user }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'after destroy' do
|
35
|
+
before { UserMfaSession.destroy }
|
36
|
+
|
37
|
+
subject { UserMfaSession.find }
|
38
|
+
|
39
|
+
it { should be_nil }
|
40
|
+
end
|
24
41
|
end
|
25
42
|
end
|
26
43
|
|
27
44
|
describe '::create' do
|
28
|
-
after { clear_cookie }
|
45
|
+
after { clear_cookie unless user.nil? }
|
29
46
|
subject { UserMfaSession.create(user) }
|
30
47
|
|
31
48
|
it { should be_a UserMfaSession }
|
@@ -50,9 +67,13 @@ describe GoogleAuthenticatorRails::Session::Base do
|
|
50
67
|
end
|
51
68
|
|
52
69
|
def set_cookie_for(user)
|
53
|
-
controller.cookies[
|
70
|
+
controller.cookies[klass(user).__send__(:cookie_key)] = { :value => [user.google_token_value, user.id].join('::'), :expires => nil }
|
71
|
+
end
|
72
|
+
|
73
|
+
def klass(user)
|
74
|
+
"#{user.class.to_s}MfaSession".constantize unless user.nil?
|
54
75
|
end
|
55
76
|
|
56
77
|
def clear_cookie
|
57
|
-
controller.cookies[
|
58
|
-
end
|
78
|
+
controller.cookies[klass(user).__send__(:cookie_key)] = nil
|
79
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,8 @@ require 'time'
|
|
2
2
|
require 'active_record'
|
3
3
|
require 'action_controller'
|
4
4
|
require 'rotp'
|
5
|
+
require 'bundler'
|
6
|
+
require 'bundler/setup'
|
5
7
|
|
6
8
|
require 'google-authenticator-rails'
|
7
9
|
|
@@ -37,12 +39,12 @@ class MockCookieJar < Hash
|
|
37
39
|
def delete(key, options = {})
|
38
40
|
super(key)
|
39
41
|
end
|
40
|
-
end
|
42
|
+
end
|
41
43
|
|
42
44
|
class UserMfaSession < GoogleAuthenticatorRails::Session::Base; end
|
43
45
|
|
44
46
|
ActiveRecord::Base.establish_connection(
|
45
|
-
:adapter
|
47
|
+
:adapter => 'sqlite3',
|
46
48
|
:database => ':memory:'
|
47
49
|
)
|
48
50
|
|
@@ -55,6 +57,7 @@ ActiveRecord::Schema.define do
|
|
55
57
|
t.string :user_name
|
56
58
|
t.string :password
|
57
59
|
t.string :persistence_token
|
60
|
+
t.string :salt
|
58
61
|
|
59
62
|
t.timestamps
|
60
63
|
end
|
@@ -64,21 +67,30 @@ ActiveRecord::Schema.define do
|
|
64
67
|
t.string :email
|
65
68
|
t.string :user_name
|
66
69
|
t.string :persistence_token
|
70
|
+
t.string :salt
|
67
71
|
|
68
72
|
t.timestamps
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
76
|
class BaseUser < ActiveRecord::Base
|
73
|
-
attr_accessible
|
77
|
+
# Older versions of ActiveRecord allow attr_accessible, but newer
|
78
|
+
# ones do not
|
79
|
+
begin
|
80
|
+
attr_accessible :email, :user_name, :password
|
81
|
+
rescue
|
82
|
+
attr_accessor :email, :user_name, :password
|
83
|
+
end
|
84
|
+
|
74
85
|
self.table_name = "users"
|
75
86
|
|
76
87
|
before_save do |user|
|
77
88
|
user.persistence_token ||= "token"
|
89
|
+
user.salt ||= "salt"
|
78
90
|
end
|
79
91
|
end
|
80
92
|
|
81
|
-
class User < BaseUser
|
93
|
+
class User < BaseUser
|
82
94
|
acts_as_google_authenticated
|
83
95
|
end
|
84
96
|
|
@@ -95,6 +107,10 @@ class ColumnNameUser < BaseUser
|
|
95
107
|
acts_as_google_authenticated :column_name => :user_name
|
96
108
|
end
|
97
109
|
|
110
|
+
class DriftUser < BaseUser
|
111
|
+
acts_as_google_authenticated :drift => 31
|
112
|
+
end
|
113
|
+
|
98
114
|
class ProcUser < BaseUser
|
99
115
|
acts_as_google_authenticated :method => Proc.new { |user| "#{user.user_name}@futureadvisor-admin" }
|
100
116
|
end
|
@@ -106,3 +122,9 @@ end
|
|
106
122
|
class StringUser < BaseUser
|
107
123
|
acts_as_google_authenticated :method => "email"
|
108
124
|
end
|
125
|
+
|
126
|
+
class SaltUserMfaSession < GoogleAuthenticatorRails::Session::Base; end
|
127
|
+
|
128
|
+
class SaltUser < BaseUser
|
129
|
+
acts_as_google_authenticated :lookup_token => :salt
|
130
|
+
end
|
metadata
CHANGED
@@ -1,110 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-authenticator-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 1.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jared McFarland
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rotp
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '='
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
19
|
+
version: 1.6.1
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '='
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
26
|
+
version: 1.6.1
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activerecord
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: google-qr
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: actionpack
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 2.8.0
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 2.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: appraisal
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.1
|
94
97
|
- !ruby/object:Gem::Dependency
|
95
98
|
name: sqlite3
|
96
99
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
100
|
requirements:
|
99
|
-
- -
|
101
|
+
- - ">="
|
100
102
|
- !ruby/object:Gem::Version
|
101
103
|
version: '0'
|
102
104
|
type: :development
|
103
105
|
prerelease: false
|
104
106
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
107
|
requirements:
|
107
|
-
- -
|
108
|
+
- - ">="
|
108
109
|
- !ruby/object:Gem::Version
|
109
110
|
version: '0'
|
110
111
|
description: Add the ability to use the Google Authenticator with ActiveRecord.
|
@@ -114,14 +115,29 @@ executables: []
|
|
114
115
|
extensions: []
|
115
116
|
extra_rdoc_files: []
|
116
117
|
files:
|
117
|
-
- .gitignore
|
118
|
-
- .rspec
|
119
|
-
- .
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".ruby-gemset"
|
121
|
+
- ".ruby-version"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Appraisals
|
120
124
|
- CONTRIBUTING.md
|
121
125
|
- Gemfile
|
122
126
|
- LICENSE
|
123
127
|
- README.md
|
124
128
|
- Rakefile
|
129
|
+
- gemfiles/rails2.3.gemfile
|
130
|
+
- gemfiles/rails2.3.gemfile.lock
|
131
|
+
- gemfiles/rails3.0.gemfile
|
132
|
+
- gemfiles/rails3.0.gemfile.lock
|
133
|
+
- gemfiles/rails3.1.gemfile
|
134
|
+
- gemfiles/rails3.1.gemfile.lock
|
135
|
+
- gemfiles/rails3.2..gemfile
|
136
|
+
- gemfiles/rails3.2..gemfile.lock
|
137
|
+
- gemfiles/rails4.0.gemfile
|
138
|
+
- gemfiles/rails4.0.gemfile.lock
|
139
|
+
- gemfiles/rails4.1.gemfile
|
140
|
+
- gemfiles/rails4.1.gemfile.lock
|
125
141
|
- google-authenticator.gemspec
|
126
142
|
- lib/google-authenticator-rails.rb
|
127
143
|
- lib/google-authenticator-rails/action_controller.rb
|
@@ -142,27 +158,26 @@ files:
|
|
142
158
|
- spec/spec_helper.rb
|
143
159
|
homepage: http://github.com/jaredonline/google-authenticator
|
144
160
|
licenses: []
|
161
|
+
metadata: {}
|
145
162
|
post_install_message:
|
146
163
|
rdoc_options: []
|
147
164
|
require_paths:
|
148
165
|
- lib
|
149
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
-
none: false
|
151
167
|
requirements:
|
152
|
-
- -
|
168
|
+
- - ">="
|
153
169
|
- !ruby/object:Gem::Version
|
154
170
|
version: '0'
|
155
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
-
none: false
|
157
172
|
requirements:
|
158
|
-
- -
|
173
|
+
- - ">="
|
159
174
|
- !ruby/object:Gem::Version
|
160
175
|
version: '0'
|
161
176
|
requirements: []
|
162
177
|
rubyforge_project:
|
163
|
-
rubygems_version:
|
178
|
+
rubygems_version: 2.4.3
|
164
179
|
signing_key:
|
165
|
-
specification_version:
|
180
|
+
specification_version: 4
|
166
181
|
summary: Add the ability to use the Google Authenticator with ActiveRecord.
|
167
182
|
test_files:
|
168
183
|
- spec/action_controller/integration_spec.rb
|