Skip to content

Commit 1d6c978

Browse files
authored
Merge pull request #159 from resitcl/master
rotp upgrade
2 parents 972e455 + afd2003 commit 1d6c978

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ language: ruby
22

33
env:
44
- "RAILS_VERSION=4.2"
5-
- "RAILS_VERSION=5.1"
5+
- "RAILS_VERSION=5.2"
66
- "RAILS_VERSION=master"
77

88
rvm:
9-
- 2.3.6
10-
- 2.4.3
11-
- 2.5.0
9+
- 2.3.8
10+
- 2.4.5
11+
- 2.5.3
1212

1313
matrix:
1414
fast_finish: true
@@ -19,7 +19,8 @@ matrix:
1919
env: RAILS_VERSION=4.2
2020

2121
before_install:
22-
- gem update bundler
22+
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
23+
- gem install bundler -v '< 2'
2324

2425
before_script:
2526
- bundle exec rake app:db:setup

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rails = case rails_version
99
when "master"
1010
{github: "rails/rails"}
1111
when "default"
12-
"~> 5.1"
12+
"~> 5.2"
1313
else
1414
"~> #{rails_version}"
1515
end

lib/two_factor_authentication/models/two_factor_authenticatable.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def authenticate_totp(code, options = {})
3939
drift = options[:drift] || self.class.allowed_otp_drift_seconds
4040
raise "authenticate_totp called with no otp_secret_key set" if totp_secret.nil?
4141
totp = ROTP::TOTP.new(totp_secret, digits: digits)
42-
new_timestamp = totp.verify_with_drift_and_prior(without_spaces(code), drift, totp_timestamp)
42+
new_timestamp = totp.verify(
43+
without_spaces(code),
44+
drift_ahead: drift, drift_behind: drift, after: totp_timestamp
45+
)
4346
return false unless new_timestamp
4447
self.totp_timestamp = new_timestamp
4548
true

spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ def instance.send_two_factor_authentication_code(code)
138138

139139
it "returns uri with user's email" do
140140
expect(instance.provisioning_uri).
141-
to match(%r{otpauth://totp/[email protected]\?secret=\w{16}})
141+
to match(%r{otpauth://totp/[email protected]\?secret=\w{32}})
142142
end
143143

144144
it 'returns uri with issuer option' do
145145
expect(instance.provisioning_uri('houdini')).
146-
to match(%r{otpauth://totp/houdini\?secret=\w{16}$})
146+
to match(%r{otpauth://totp/houdini\?secret=\w{32}$})
147147
end
148148

149149
it 'returns uri with issuer option' do
@@ -155,7 +155,7 @@ def instance.send_two_factor_authentication_code(code)
155155
expect(uri.host).to eq('totp')
156156
expect(uri.path).to eq('/Magic:houdini')
157157
expect(params['issuer'].shift).to eq('Magic')
158-
expect(params['secret'].shift).to match(/\w{16}/)
158+
expect(params['secret'].shift).to match(/\w{32}/)
159159
end
160160
end
161161
end
@@ -168,10 +168,10 @@ def instance.send_two_factor_authentication_code(code)
168168
shared_examples 'generate_totp_secret' do |klass|
169169
let(:instance) { klass.new }
170170

171-
it 'returns a 16 character string' do
171+
it 'returns a 32 character string' do
172172
secret = instance.generate_totp_secret
173173

174-
expect(secret).to match(/\w{16}/)
174+
expect(secret).to match(/\w{32}/)
175175
end
176176
end
177177

spec/support/totp_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ def initialize(secret_key, otp_length)
66
end
77

88
def totp_code(time = Time.now)
9-
ROTP::TOTP.new(@secret_key, digits: @otp_length).at(time, true)
9+
ROTP::TOTP.new(@secret_key, digits: @otp_length).at(time)
1010
end
1111
end

two_factor_authentication.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |s|
2727
s.add_runtime_dependency 'rails', '>= 3.1.1'
2828
s.add_runtime_dependency 'devise'
2929
s.add_runtime_dependency 'randexp'
30-
s.add_runtime_dependency 'rotp', '>= 3.2.0'
30+
s.add_runtime_dependency 'rotp', '>= 4.0.0'
3131
s.add_runtime_dependency 'encryptor'
3232

3333
s.add_development_dependency 'bundler'

0 commit comments

Comments
 (0)