comparison test/unit/lib/redmine/ciphering_test.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
55 Redmine::Configuration.with 'database_cipher_key' => nil do 55 Redmine::Configuration.with 'database_cipher_key' => nil do
56 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn') 56 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
57 end 57 end
58 58
59 Redmine::Configuration.with 'database_cipher_key' => 'secret' do 59 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
60 r = Repository.first(:order => 'id DESC') 60 r = Repository.order('id DESC').first
61 assert_equal 'clear', r.password 61 assert_equal 'clear', r.password
62 end 62 end
63 end 63 end
64 64
65 def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered 65 def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered
66 Redmine::Configuration.with 'database_cipher_key' => 'secret' do 66 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
67 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn') 67 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
68 end 68 end
69 69
70 Redmine::Configuration.with 'database_cipher_key' => '' do 70 Redmine::Configuration.with 'database_cipher_key' => '' do
71 r = Repository.first(:order => 'id DESC') 71 r = Repository.order('id DESC').first
72 # password can not be deciphered 72 # password can not be deciphered
73 assert_nothing_raised do 73 assert_nothing_raised do
74 assert r.password.match(/\Aaes-256-cbc:.+\Z/) 74 assert r.password.match(/\Aaes-256-cbc:.+\Z/)
75 end 75 end
76 end 76 end
83 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar') 83 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
84 end 84 end
85 85
86 Redmine::Configuration.with 'database_cipher_key' => 'secret' do 86 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
87 assert Repository.encrypt_all(:password) 87 assert Repository.encrypt_all(:password)
88 r = Repository.first(:order => 'id DESC') 88 r = Repository.order('id DESC').first
89 assert_equal 'bar', r.password 89 assert_equal 'bar', r.password
90 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) 90 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
91 end 91 end
92 end 92 end
93 93
96 Redmine::Configuration.with 'database_cipher_key' => 'secret' do 96 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
97 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo') 97 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo')
98 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar') 98 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
99 99
100 assert Repository.decrypt_all(:password) 100 assert Repository.decrypt_all(:password)
101 r = Repository.first(:order => 'id DESC') 101 r = Repository.order('id DESC').first
102 assert_equal 'bar', r.password 102 assert_equal 'bar', r.password
103 assert_equal 'bar', r.read_attribute(:password) 103 assert_equal 'bar', r.read_attribute(:password)
104 end 104 end
105 end 105 end
106 end 106 end