Skip to content

Commit

Permalink
Merge pull request #237 from mjankowski/allow-attr-encrypted-four
Browse files Browse the repository at this point in the history
Allow attr_encrypted version four
  • Loading branch information
bsedat committed Apr 23, 2023
2 parents 3365d1c + b4f0d29 commit e685f91
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion devise-two-factor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|

s.add_runtime_dependency 'railties', '< 7.1'
s.add_runtime_dependency 'activesupport', '< 7.1'
s.add_runtime_dependency 'attr_encrypted', '>= 1.3', '< 4', '!= 2'
s.add_runtime_dependency 'attr_encrypted', '>= 1.3', '< 5', '!= 2'
s.add_runtime_dependency 'devise', '~> 4.0'
s.add_runtime_dependency 'rotp', '~> 6.0'

Expand Down
22 changes: 19 additions & 3 deletions spec/devise/models/two_factor_authenticatable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,31 @@ def save(validate)

describe 'otp_secret options' do
it 'should be of the key' do
expect(subject.encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
else
expect(subject.encrypted_attributes[:otp_secret][:key]).to eq('test-key'*8)
end
end

it 'should be of the mode' do
expect(subject.encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
else
expect(subject.encrypted_attributes[:otp_secret][:mode]).to eq(:per_attribute_iv_and_salt)
end
end

it 'should be of the mode' do
expect(subject.encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
if attr_encrypted_is_rails_seven_compatible?
expect(subject.attr_encrypted_encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
else
expect(subject.encrypted_attributes[:otp_secret][:algorithm]).to eq('aes-256-cbc')
end
end

def attr_encrypted_is_rails_seven_compatible?
Gem::Version.new(AttrEncrypted::Version.string) >= Gem::Version.new('4.0.0')
end
end
end
Expand Down

0 comments on commit e685f91

Please sign in to comment.