##// END OF EJS Templates
scm: bazaar: add test for author html escaping (#14931)...
Toshi MARUYAMA -
r11918:8b794b5e8355
parent child
Show More
@@ -1,188 +1,210
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoriesBazaarControllerTest < ActionController::TestCase
20 class RepositoriesBazaarControllerTest < ActionController::TestCase
21 tests RepositoriesController
21 tests RepositoriesController
22
22
23 fixtures :projects, :users, :roles, :members, :member_roles,
23 fixtures :projects, :users, :roles, :members, :member_roles,
24 :repositories, :enabled_modules
24 :repositories, :enabled_modules
25
25
26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
26 REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s
27 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
27 REPOSITORY_PATH_TRUNK = File.join(REPOSITORY_PATH, "trunk")
28 PRJ_ID = 3
28 PRJ_ID = 3
29
29
30 def setup
30 def setup
31 User.current = nil
31 User.current = nil
32 @project = Project.find(PRJ_ID)
32 @project = Project.find(PRJ_ID)
33 @repository = Repository::Bazaar.create(
33 @repository = Repository::Bazaar.create(
34 :project => @project,
34 :project => @project,
35 :url => REPOSITORY_PATH_TRUNK,
35 :url => REPOSITORY_PATH_TRUNK,
36 :log_encoding => 'UTF-8')
36 :log_encoding => 'UTF-8')
37 assert @repository
37 assert @repository
38 end
38 end
39
39
40 if File.directory?(REPOSITORY_PATH)
40 if File.directory?(REPOSITORY_PATH)
41 def test_get_new
41 def test_get_new
42 @request.session[:user_id] = 1
42 @request.session[:user_id] = 1
43 @project.repository.destroy
43 @project.repository.destroy
44 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
44 get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
45 assert_response :success
45 assert_response :success
46 assert_template 'new'
46 assert_template 'new'
47 assert_kind_of Repository::Bazaar, assigns(:repository)
47 assert_kind_of Repository::Bazaar, assigns(:repository)
48 assert assigns(:repository).new_record?
48 assert assigns(:repository).new_record?
49 end
49 end
50
50
51 def test_browse_root
51 def test_browse_root
52 get :show, :id => PRJ_ID
52 get :show, :id => PRJ_ID
53 assert_response :success
53 assert_response :success
54 assert_template 'show'
54 assert_template 'show'
55 assert_not_nil assigns(:entries)
55 assert_not_nil assigns(:entries)
56 assert_equal 2, assigns(:entries).size
56 assert_equal 2, assigns(:entries).size
57 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
58 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
58 assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
59 end
59 end
60
60
61 def test_browse_directory
61 def test_browse_directory
62 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
62 get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
63 assert_response :success
63 assert_response :success
64 assert_template 'show'
64 assert_template 'show'
65 assert_not_nil assigns(:entries)
65 assert_not_nil assigns(:entries)
66 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
66 assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
67 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
68 assert_not_nil entry
68 assert_not_nil entry
69 assert_equal 'file', entry.kind
69 assert_equal 'file', entry.kind
70 assert_equal 'directory/edit.png', entry.path
70 assert_equal 'directory/edit.png', entry.path
71 end
71 end
72
72
73 def test_browse_at_given_revision
73 def test_browse_at_given_revision
74 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
74 get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
75 :rev => 3
75 :rev => 3
76 assert_response :success
76 assert_response :success
77 assert_template 'show'
77 assert_template 'show'
78 assert_not_nil assigns(:entries)
78 assert_not_nil assigns(:entries)
79 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
79 assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
80 assigns(:entries).collect(&:name)
80 assigns(:entries).collect(&:name)
81 end
81 end
82
82
83 def test_changes
83 def test_changes
84 get :changes, :id => PRJ_ID,
84 get :changes, :id => PRJ_ID,
85 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
85 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
86 assert_response :success
86 assert_response :success
87 assert_template 'changes'
87 assert_template 'changes'
88 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
88 assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
89 end
89 end
90
90
91 def test_entry_show
91 def test_entry_show
92 get :entry, :id => PRJ_ID,
92 get :entry, :id => PRJ_ID,
93 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
93 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
94 assert_response :success
94 assert_response :success
95 assert_template 'entry'
95 assert_template 'entry'
96 # Line 19
96 # Line 19
97 assert_tag :tag => 'th',
97 assert_tag :tag => 'th',
98 :content => /29/,
98 :content => /29/,
99 :attributes => { :class => /line-num/ },
99 :attributes => { :class => /line-num/ },
100 :sibling => { :tag => 'td', :content => /Show help message/ }
100 :sibling => { :tag => 'td', :content => /Show help message/ }
101 end
101 end
102
102
103 def test_entry_download
103 def test_entry_download
104 get :entry, :id => PRJ_ID,
104 get :entry, :id => PRJ_ID,
105 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
105 :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
106 :format => 'raw'
106 :format => 'raw'
107 assert_response :success
107 assert_response :success
108 # File content
108 # File content
109 assert @response.body.include?('Show help message')
109 assert @response.body.include?('Show help message')
110 end
110 end
111
111
112 def test_directory_entry
112 def test_directory_entry
113 get :entry, :id => PRJ_ID,
113 get :entry, :id => PRJ_ID,
114 :path => repository_path_hash(['directory'])[:param]
114 :path => repository_path_hash(['directory'])[:param]
115 assert_response :success
115 assert_response :success
116 assert_template 'show'
116 assert_template 'show'
117 assert_not_nil assigns(:entry)
117 assert_not_nil assigns(:entry)
118 assert_equal 'directory', assigns(:entry).name
118 assert_equal 'directory', assigns(:entry).name
119 end
119 end
120
120
121 def test_diff
121 def test_diff
122 # Full diff of changeset 3
122 # Full diff of changeset 3
123 ['inline', 'sbs'].each do |dt|
123 ['inline', 'sbs'].each do |dt|
124 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
124 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
125 assert_response :success
125 assert_response :success
126 assert_template 'diff'
126 assert_template 'diff'
127 # Line 11 removed
127 # Line 11 removed
128 assert_tag :tag => 'th',
128 assert_tag :tag => 'th',
129 :content => '11',
129 :content => '11',
130 :sibling => { :tag => 'td',
130 :sibling => { :tag => 'td',
131 :attributes => { :class => /diff_out/ },
131 :attributes => { :class => /diff_out/ },
132 :content => /Display more information/ }
132 :content => /Display more information/ }
133 end
133 end
134 end
134 end
135
135
136 def test_annotate
136 def test_annotate
137 get :annotate, :id => PRJ_ID,
137 get :annotate, :id => PRJ_ID,
138 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
138 :path => repository_path_hash(['doc-mkdir.txt'])[:param]
139 assert_response :success
139 assert_response :success
140 assert_template 'annotate'
140 assert_template 'annotate'
141 assert_select "th.line-num", :text => '2' do
141 assert_select "th.line-num", :text => '2' do
142 assert_select "+ td.revision" do
142 assert_select "+ td.revision" do
143 assert_select "a", :text => '3'
143 assert_select "a", :text => '3'
144 assert_select "+ td.author", :text => "jsmith@" do
144 assert_select "+ td.author", :text => "jsmith@" do
145 assert_select "+ td",
145 assert_select "+ td",
146 :text => "Main purpose:"
146 :text => "Main purpose:"
147 end
147 end
148 end
148 end
149 end
149 end
150 end
150 end
151
151
152 def test_annotate_author_escaping
153 repository = Repository::Bazaar.create(
154 :project => @project,
155 :url => File.join(REPOSITORY_PATH, "author_escaping"),
156 :identifier => 'author_escaping',
157 :log_encoding => 'UTF-8')
158 assert repository
159 get :annotate, :id => PRJ_ID, :repository_id => 'author_escaping',
160 :path => repository_path_hash(['author-escaping-test.txt'])[:param]
161 assert_response :success
162 assert_template 'annotate'
163 assert_select "th.line-num", :text => '1' do
164 assert_select "+ td.revision" do
165 assert_select "a", :text => '2'
166 assert_select "+ td.author", :text => "test &amp;" do
167 assert_select "+ td",
168 :text => "author escaping test"
169 end
170 end
171 end
172 end
173
152 def test_destroy_valid_repository
174 def test_destroy_valid_repository
153 @request.session[:user_id] = 1 # admin
175 @request.session[:user_id] = 1 # admin
154 assert_equal 0, @repository.changesets.count
176 assert_equal 0, @repository.changesets.count
155 @repository.fetch_changesets
177 @repository.fetch_changesets
156 assert @repository.changesets.count > 0
178 assert @repository.changesets.count > 0
157
179
158 assert_difference 'Repository.count', -1 do
180 assert_difference 'Repository.count', -1 do
159 delete :destroy, :id => @repository.id
181 delete :destroy, :id => @repository.id
160 end
182 end
161 assert_response 302
183 assert_response 302
162 @project.reload
184 @project.reload
163 assert_nil @project.repository
185 assert_nil @project.repository
164 end
186 end
165
187
166 def test_destroy_invalid_repository
188 def test_destroy_invalid_repository
167 @request.session[:user_id] = 1 # admin
189 @request.session[:user_id] = 1 # admin
168 @project.repository.destroy
190 @project.repository.destroy
169 @repository = Repository::Bazaar.create!(
191 @repository = Repository::Bazaar.create!(
170 :project => @project,
192 :project => @project,
171 :url => "/invalid",
193 :url => "/invalid",
172 :log_encoding => 'UTF-8')
194 :log_encoding => 'UTF-8')
173 @repository.fetch_changesets
195 @repository.fetch_changesets
174 @repository.reload
196 @repository.reload
175 assert_equal 0, @repository.changesets.count
197 assert_equal 0, @repository.changesets.count
176
198
177 assert_difference 'Repository.count', -1 do
199 assert_difference 'Repository.count', -1 do
178 delete :destroy, :id => @repository.id
200 delete :destroy, :id => @repository.id
179 end
201 end
180 assert_response 302
202 assert_response 302
181 @project.reload
203 @project.reload
182 assert_nil @project.repository
204 assert_nil @project.repository
183 end
205 end
184 else
206 else
185 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
207 puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
186 def test_fake; assert true end
208 def test_fake; assert true end
187 end
209 end
188 end
210 end
General Comments 0
You need to be logged in to leave comments. Login now