Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 344
- Log:
Massive changeset which brings the old, ROOL customised Instiki
version up to date, but without any ROOL customisations in this
latest checked-in version (which is 0.19.1). This is deliberate,
so that it's easy to see the changes made for the ROOL version
in a subsequent changeset. The 'app/views/shared' directory is not
part of Instiki but is kept to maintain the change history with
updated ROOL customisations, some of which involve the same files
in that same directory.
- Author:
- rool
- Date:
- Sat Mar 19 19:52:13 +0000 2011
- Size:
- 10943 Bytes
- Properties:
- Property svn:executable is set
1 | #!/usr/bin/env ruby |
2 | |
3 | require Rails.root.join('test', 'test_helper') |
4 | require 'file_controller' |
5 | require 'fileutils' |
6 | require 'stringio' |
7 | |
8 | # Raise errors beyond the default web-based presentation |
9 | class FileController; def rescue_action(e) logger.error(e); raise e end; end |
10 | |
11 | class FileControllerTest < ActionController::TestCase |
12 | fixtures :webs, :pages, :revisions, :system |
13 | |
14 | def setup |
15 | @controller = FileController.new |
16 | @request = ActionController::TestRequest.new |
17 | @response = ActionController::TestResponse.new |
18 | class << @request.session |
19 | attr_accessor :dbman |
20 | end |
21 | # simulate a cookie session store |
22 | @request.session.dbman = FakeSessionDbMan |
23 | @web = webs(:test_wiki) |
24 | @wiki = Wiki.new |
25 | WikiFile.delete_all |
26 | require 'fileutils' |
27 | FileUtils.rm_rf("#{RAILS_ROOT}/webs/wiki1") |
28 | end |
29 | |
30 | def test_file_upload_form |
31 | get :file, :web => 'wiki1', :id => 'new_file.txt' |
32 | assert_response(:success) |
33 | assert_template 'file/file' |
34 | end |
35 | |
36 | def test_file_download_text_file |
37 | @web.wiki_files.create(:file_name => 'foo.txt', :description => 'Text file', |
38 | :content => "Contents of the file") |
39 | |
40 | r = get :file, :web => 'wiki1', :id => 'foo.txt' |
41 | |
42 | assert_response(:success, bypass_body_parsing = true) |
43 | assert_equal "Contents of the file", r.body |
44 | assert_equal 'text/plain', r.headers['Content-Type'] |
45 | assert_equal 'inline; filename="foo.txt"', r.headers['Content-Disposition'] |
46 | end |
47 | |
48 | def test_file_download_html_file |
49 | @web.wiki_files.create(:file_name => 'foo.html', :description => 'Text file', |
50 | :content => "Contents of the file") |
51 | |
52 | r = get :file, :web => 'wiki1', :id => 'foo.html' |
53 | |
54 | assert_response(:success, bypass_body_parsing = true) |
55 | assert_equal "Contents of the file", r.body |
56 | assert_equal 'application/octet-stream', r.headers['Content-Type'] |
57 | assert_equal 'attachment; filename="foo.html"', r.headers['Content-Disposition'] |
58 | end |
59 | |
60 | def test_file_download_pdf_file |
61 | @web.wiki_files.create(:file_name => 'foo.pdf', :description => 'PDF file', |
62 | :content => "aaa\nbbb\n") |
63 | |
64 | r = get :file, :web => 'wiki1', :id => 'foo.pdf' |
65 | |
66 | assert_response(:success, bypass_body_parsing = true) |
67 | assert_equal "aaa\nbbb\n", r.body |
68 | assert_equal 'application/pdf', r.headers['Content-Type'] |
69 | end |
70 | |
71 | def test_pic_download_gif |
72 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
73 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
74 | |
75 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
76 | |
77 | assert_response(:success, bypass_body_parsing = true) |
78 | assert_equal 'image/gif', r.headers['Content-Type'] |
79 | assert_equal pic.size, r.body.size |
80 | assert_equal pic, r.body |
81 | assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] |
82 | end |
83 | |
84 | def test_pic_download_gif_published_web |
85 | @web.update_attribute(:published, true) |
86 | @web.update_attribute(:password, 'pswd') |
87 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
88 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
89 | |
90 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
91 | |
92 | assert_response(:success, bypass_body_parsing = true) |
93 | assert_equal 'image/gif', r.headers['Content-Type'] |
94 | assert_equal pic.size, r.body.size |
95 | assert_equal pic, r.body |
96 | assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] |
97 | end |
98 | |
99 | def test_pic_download_gif_unpublished_web |
100 | @web.update_attribute(:published, false) |
101 | @web.update_attribute(:password, 'pswd') |
102 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
103 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
104 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
105 | |
106 | assert_response(:forbidden) |
107 | end |
108 | |
109 | def test_pic_x_sendfile |
110 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
111 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
112 | @request.env.update({ 'HTTP_X_SENDFILE_TYPE' => 'foo' }) |
113 | @request.remote_addr = '127.0.0.1' |
114 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
115 | |
116 | assert_response(:success, bypass_body_parsing = true) |
117 | # It's no longer possible to use X-Sendfile in development; ergo no way to test |
118 | # assert_match '/rails.gif', r.headers['X-Sendfile'] |
119 | assert_equal 'image/gif', r.headers['Content-Type'] |
120 | assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] |
121 | end |
122 | |
123 | def test_pic_x_sendfile_published_web |
124 | @web.update_attribute(:published, true) |
125 | @web.update_attribute(:password, 'pswd') |
126 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
127 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
128 | @request.env.update({ 'HTTP_X_SENDFILE_TYPE' => 'foo' }) |
129 | @request.remote_addr = '127.0.0.1' |
130 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
131 | |
132 | assert_response(:success, bypass_body_parsing = true) |
133 | # It's no longer possible to use X-Sendfile in development; ergo no way to test |
134 | # assert_match '/rails.gif', r.headers['X-Sendfile'] |
135 | assert_equal 'image/gif', r.headers['Content-Type'] |
136 | assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] |
137 | end |
138 | |
139 | def test_pic_x_sendfile_unpublished_web |
140 | @web.update_attribute(:published, false) |
141 | @web.update_attribute(:password, 'pswd') |
142 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
143 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
144 | @request.env.update({ 'HTTP_X_SENDFILE_TYPE' => 'foo' }) |
145 | @request.remote_addr = '127.0.0.1' |
146 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
147 | |
148 | assert_response(:forbidden) |
149 | end |
150 | |
151 | def test_pic_x_sendfile_type_nonlocal |
152 | pic = File.open("#{RAILS_ROOT}/test/fixtures/rails.gif", 'rb') { |f| f.read } |
153 | @web.wiki_files.create(:file_name => 'rails.gif', :description => 'An image', :content => pic) |
154 | @request.env.update({ 'HTTP_X_SENDFILE_TYPE' => 'foo' }) |
155 | r = get :file, :web => 'wiki1', :id => 'rails.gif' |
156 | |
157 | assert_response(:success, bypass_body_parsing = true) |
158 | assert_equal 'image/gif', r.headers['Content-Type'] |
159 | assert_equal pic.size, r.body.size |
160 | assert_equal pic, r.body |
161 | assert_equal 'inline; filename="rails.gif"', r.headers['Content-Disposition'] |
162 | end |
163 | |
164 | def test_pic_unknown_pic |
165 | r = get :file, :web => 'wiki1', :id => 'non-existant.gif' |
166 | |
167 | assert_response(:success) |
168 | assert_template 'file/file' |
169 | end |
170 | |
171 | def test_pic_upload_published_web |
172 | @web.update_attribute(:published, true) |
173 | @web.update_attribute(:password, 'pswd') |
174 | @web.update_attribute(:allow_uploads, true) |
175 | # edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif' |
176 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
177 | renderer = PageRenderer.new |
178 | @wiki.revise_page('wiki1', 'Oak', 'Oak', '[[rails-e2e.gif:pic]]', |
179 | Time.now, 'AnonymousBrave', renderer) |
180 | assert_equal "<p><span class='newWikiWord'>rails-e2e.gif</span></p>", |
181 | renderer.display_published |
182 | |
183 | # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form |
184 | r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif' |
185 | assert_response(:forbidden) |
186 | end |
187 | |
188 | def test_pic_upload_unpublished_web |
189 | @web.update_attribute(:published, false) |
190 | @web.update_attribute(:password, 'pswd') |
191 | @web.update_attribute(:allow_uploads, true) |
192 | # edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif' |
193 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
194 | renderer = PageRenderer.new |
195 | @wiki.revise_page('wiki1', 'Oak', 'Oak', '[[rails-e2e.gif:pic]]', |
196 | Time.now, 'AnonymousBrave', renderer) |
197 | assert_equal "<p><span class='newWikiWord'>rails-e2e.gif</span></p>", |
198 | renderer.display_published |
199 | |
200 | # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form |
201 | r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif' |
202 | assert_response(:forbidden) |
203 | end |
204 | |
205 | def test_pic_upload_end_to_end |
206 | # edit and re-render a page so that it has an "unknown file" link to 'rails-e2e.gif' |
207 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
208 | renderer = PageRenderer.new |
209 | @wiki.revise_page('wiki1', 'Oak', 'Oak', '[[rails-e2e.gif:pic]]', |
210 | Time.now, 'AnonymousBrave', renderer) |
211 | assert_equal "<p><span class='newWikiWord'>rails-e2e.gif<a href='../file/rails-e2e.gif'>" + |
212 | "?</a></span></p>", |
213 | renderer.display_content |
214 | |
215 | # rails-e2e.gif is unknown to the system, so pic action goes to the file [upload] form |
216 | r = get :file, :web => 'wiki1', :id => 'rails-e2e.gif' |
217 | assert_response(:success) |
218 | assert_template 'file/file' |
219 | |
220 | # User uploads the picture |
221 | begin # Ruby 1.9 |
222 | picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif", :encoding => 'ascii-8bit') |
223 | rescue #Ruby 1.8 |
224 | picture = File.read("#{RAILS_ROOT}/test/fixtures/rails.gif") |
225 | end |
226 | # updated from post to get - post fails the spam protection (no javascript) |
227 | # Moron! If substituting GET for POST actually works, you |
228 | # have much, much bigger problems. |
229 | r = get :file, :web => 'wiki1', :referring_page => '/wiki1/show/Oak', |
230 | :file => {:file_name => 'rails-e2e.gif', |
231 | :content => StringIO.new(picture), |
232 | :description => 'Rails, end-to-end'} |
233 | assert_redirected_to '/wiki1/show/Oak' |
234 | assert @web.has_file?('rails-e2e.gif') |
235 | assert_equal(picture, WikiFile.find_by_file_name('rails-e2e.gif').content) |
236 | PageRenderer.setup_url_generator(StubUrlGenerator.new) |
237 | @wiki.revise_page('wiki1', 'Oak', 'Oak', 'Try [[rails-e2e.gif:pic]] again.', |
238 | Time.now, 'AnonymousBrave', renderer) |
239 | assert_equal "<p>Try <img alt='Rails, end-to-end' src='../file/rails-e2e.gif'/> again.</p>", |
240 | renderer.display_content |
241 | assert_equal "<p>Try <img alt='Rails, end-to-end' src='../file/rails-e2e.gif'/> again.</p>", |
242 | renderer.display_published |
243 | end |
244 | |
245 | def test_import |
246 | # updated from post to get - post fails the spam protection (no javascript) |
247 | r = get :import, :web => 'wiki1', :file => uploaded_file("#{RAILS_ROOT}/test/fixtures/exported_markup.zip") |
248 | assert_response(:redirect) |
249 | assert @web.has_page?('ImportedPage') |
250 | end |
251 | |
252 | def uploaded_file(path, content_type="application/octet-stream", filename=nil) |
253 | filename ||= File.basename(path) |
254 | t = Tempfile.new(filename) |
255 | FileUtils.copy_file(path, t.path) |
256 | (class << t; self; end;).class_eval do |
257 | alias local_path path |
258 | define_method(:original_filename) { filename } |
259 | define_method(:content_type) { content_type } |
260 | end |
261 | return t |
262 | end |
263 | |
264 | end |