annotate .svn/pristine/25/25e2b9b227cb6f18e371c2b9f54071b5c31827f3.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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