Mercurial > hg > soundsoftware-site
comparison test/unit/lib/redmine/ciphering_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
19 | 19 |
20 class Redmine::CipheringTest < ActiveSupport::TestCase | 20 class Redmine::CipheringTest < ActiveSupport::TestCase |
21 | 21 |
22 def test_password_should_be_encrypted | 22 def test_password_should_be_encrypted |
23 Redmine::Configuration.with 'database_cipher_key' => 'secret' do | 23 Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
24 r = Repository::Subversion.generate!(:password => 'foo') | 24 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn') |
25 assert_equal 'foo', r.password | 25 assert_equal 'foo', r.password |
26 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) | 26 assert r.read_attribute(:password).match(/\Aaes-256-cbc:.+\Z/) |
27 end | 27 end |
28 end | 28 end |
29 | 29 |
30 def test_password_should_be_clear_with_blank_key | 30 def test_password_should_be_clear_with_blank_key |
31 Redmine::Configuration.with 'database_cipher_key' => '' do | 31 Redmine::Configuration.with 'database_cipher_key' => '' do |
32 r = Repository::Subversion.generate!(:password => 'foo') | 32 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn') |
33 assert_equal 'foo', r.password | 33 assert_equal 'foo', r.password |
34 assert_equal 'foo', r.read_attribute(:password) | 34 assert_equal 'foo', r.read_attribute(:password) |
35 end | 35 end |
36 end | 36 end |
37 | 37 |
38 def test_password_should_be_clear_with_nil_key | 38 def test_password_should_be_clear_with_nil_key |
39 Redmine::Configuration.with 'database_cipher_key' => nil do | 39 Redmine::Configuration.with 'database_cipher_key' => nil do |
40 r = Repository::Subversion.generate!(:password => 'foo') | 40 r = Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'svn') |
41 assert_equal 'foo', r.password | 41 assert_equal 'foo', r.password |
42 assert_equal 'foo', r.read_attribute(:password) | 42 assert_equal 'foo', r.read_attribute(:password) |
43 end | 43 end |
44 end | 44 end |
45 | 45 |
46 def test_blank_password_should_be_clear | 46 def test_blank_password_should_be_clear |
47 Redmine::Configuration.with 'database_cipher_key' => 'secret' do | 47 Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
48 r = Repository::Subversion.generate!(:password => '') | 48 r = Repository::Subversion.create!(:password => '', :url => 'file:///tmp', :identifier => 'svn') |
49 assert_equal '', r.password | 49 assert_equal '', r.password |
50 assert_equal '', r.read_attribute(:password) | 50 assert_equal '', r.read_attribute(:password) |
51 end | 51 end |
52 end | 52 end |
53 | 53 |
54 def test_unciphered_password_should_be_readable | 54 def test_unciphered_password_should_be_readable |
55 Redmine::Configuration.with 'database_cipher_key' => nil do | 55 Redmine::Configuration.with 'database_cipher_key' => nil do |
56 r = Repository::Subversion.generate!(:password => 'clear') | 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.first(:order => 'id DESC') |
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.generate!(:password => 'clear') | 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.first(:order => 'id DESC') |
72 # password can not be deciphered | 72 # password can not be deciphered |
77 end | 77 end |
78 | 78 |
79 def test_encrypt_all | 79 def test_encrypt_all |
80 Repository.delete_all | 80 Repository.delete_all |
81 Redmine::Configuration.with 'database_cipher_key' => nil do | 81 Redmine::Configuration.with 'database_cipher_key' => nil do |
82 Repository::Subversion.generate!(:password => 'foo') | 82 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo') |
83 Repository::Subversion.generate!(:password => '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.first(:order => 'id DESC') |
92 end | 92 end |
93 | 93 |
94 def test_decrypt_all | 94 def test_decrypt_all |
95 Repository.delete_all | 95 Repository.delete_all |
96 Redmine::Configuration.with 'database_cipher_key' => 'secret' do | 96 Redmine::Configuration.with 'database_cipher_key' => 'secret' do |
97 Repository::Subversion.generate!(:password => 'foo') | 97 Repository::Subversion.create!(:password => 'foo', :url => 'file:///tmp', :identifier => 'foo') |
98 Repository::Subversion.generate!(:password => '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.first(:order => 'id DESC') |
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) |