Skip to content

Commit d0c56c0

Browse files
committed
Rake tasks "db:encrypt" and "db:decrypt" may fail due to validation error (#33926).
Patch by Go MAEDA. git-svn-id: http://svn.redmine.org/redmine/trunk@19999 e93f8b46-1217-0410-a6f0-8f06a7374b81
1 parent b073982 commit d0c56c0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/redmine/ciphering.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def encrypt_all(attribute)
7474
all.each do |object|
7575
clear = object.send(attribute)
7676
object.send "#{attribute}=", clear
77-
raise(ActiveRecord::Rollback) unless object.save(:validation => false)
77+
raise(ActiveRecord::Rollback) unless object.save(validate: false)
7878
end
7979
end ? true : false
8080
end
@@ -84,7 +84,7 @@ def decrypt_all(attribute)
8484
all.each do |object|
8585
clear = object.send(attribute)
8686
object.send :write_attribute, attribute, clear
87-
raise(ActiveRecord::Rollback) unless object.save(:validation => false)
87+
raise(ActiveRecord::Rollback) unless object.save(validate: false)
8888
end
8989
end ? true : false
9090
end

test/unit/lib/redmine/ciphering_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require File.expand_path('../../../../test_helper', __FILE__)
2121

2222
class Redmine::CipheringTest < ActiveSupport::TestCase
23+
fixtures :auth_sources
2324

2425
def test_password_should_be_encrypted
2526
Redmine::Configuration.with 'database_cipher_key' => 'secret' do
@@ -106,4 +107,12 @@ def test_decrypt_all
106107
assert_equal 'bar', r.read_attribute(:password)
107108
end
108109
end
110+
111+
def test_encrypt_all_and_decrypt_all_should_skip_validation
112+
auth_source = auth_sources(:auth_sources_001)
113+
# validator checks if AuthSource#host is present
114+
auth_source.update_column(:host, nil)
115+
assert AuthSource.encrypt_all(:account_password)
116+
assert AuthSource.decrypt_all(:account_password)
117+
end
109118
end

0 commit comments

Comments
 (0)