annotate .svn/pristine/d0/d0ec5b795163f25a52f81c99e4aaa93fb978f3ab.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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