annotate .svn/pristine/27/2745a50d7301c30263d5450e181481b6eeb6b406.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class Redmine::CipheringTest < ActiveSupport::TestCase
Chris@1295 21
Chris@1295 22 def test_password_should_be_encrypted
Chris@1295 23 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 24 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 25 assert_equal 'foo', r.password
Chris@1295 26 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
Chris@1295 27 end
Chris@1295 28 end
Chris@1295 29
Chris@1295 30 def test_password_should_be_clear_with_blank_key
Chris@1295 31 Redmine::Configuration.with 'database_cipher_key' => '' do
Chris@1295 32 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 33 assert_equal 'foo', r.password
Chris@1295 34 assert_equal 'foo', r.read_attribute(:password)
Chris@1295 35 end
Chris@1295 36 end
Chris@1295 37
Chris@1295 38 def test_password_should_be_clear_with_nil_key
Chris@1295 39 Redmine::Configuration.with 'database_cipher_key' => nil do
Chris@1295 40 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 41 assert_equal 'foo', r.password
Chris@1295 42 assert_equal 'foo', r.read_attribute(:password)
Chris@1295 43 end
Chris@1295 44 end
Chris@1295 45
Chris@1295 46 def test_blank_password_should_be_clear
Chris@1295 47 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 48 r = Repository::Subversion.create!(:password => '', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 49 assert_equal '', r.password
Chris@1295 50 assert_equal '', r.read_attribute(:password)
Chris@1295 51 end
Chris@1295 52 end
Chris@1295 53
Chris@1295 54 def test_unciphered_password_should_be_readable
Chris@1295 55 Redmine::Configuration.with 'database_cipher_key' => nil do
Chris@1295 56 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 57 end
Chris@1295 58
Chris@1295 59 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 60 r = Repository.first(:order => 'id DESC')
Chris@1295 61 assert_equal 'clear', r.password
Chris@1295 62 end
Chris@1295 63 end
Chris@1295 64
Chris@1295 65 def test_ciphered_password_with_no_cipher_key_configured_should_be_returned_ciphered
Chris@1295 66 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 67 r = Repository::Subversion.create!(:password => 'clear', :url => 'file:///tmp', :identifier => 'svn')
Chris@1295 68 end
Chris@1295 69
Chris@1295 70 Redmine::Configuration.with 'database_cipher_key' => '' do
Chris@1295 71 r = Repository.first(:order => 'id DESC')
Chris@1295 72 # password can not be deciphered
Chris@1295 73 assert_nothing_raised do
Chris@1295 74 assert r.password.match(/\Aaes-256-cbc:.+\Z/)
Chris@1295 75 end
Chris@1295 76 end
Chris@1295 77 end
Chris@1295 78
Chris@1295 79 def test_encrypt_all
Chris@1295 80 Repository.delete_all
Chris@1295 81 Redmine::Configuration.with 'database_cipher_key' => nil do
Chris@1295 82 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo')
Chris@1295 83 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
Chris@1295 84 end
Chris@1295 85
Chris@1295 86 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 87 assert Repository.encrypt_all(:password)
Chris@1295 88 r = Repository.first(:order => 'id DESC')
Chris@1295 89 assert_equal 'bar', r.password
Chris@1295 90 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/)
Chris@1295 91 end
Chris@1295 92 end
Chris@1295 93
Chris@1295 94 def test_decrypt_all
Chris@1295 95 Repository.delete_all
Chris@1295 96 Redmine::Configuration.with 'database_cipher_key' => 'secret' do
Chris@1295 97 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo')
Chris@1295 98 Repository::Subversion.create!(:password => 'bar', :url => 'file:///tmp', :identifier => 'bar')
Chris@1295 99
Chris@1295 100 assert Repository.decrypt_all(:password)
Chris@1295 101 r = Repository.first(:order => 'id DESC')
Chris@1295 102 assert_equal 'bar', r.password
Chris@1295 103 assert_equal 'bar', r.read_attribute(:password)
Chris@1295 104 end
Chris@1295 105 end
Chris@1295 106 end