annotate test/unit/lib/redmine/ciphering_test.rb @ 1180:14058c37047a feature_14

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