@@ -5,12 +5,12 | |||||
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. | |
@@ -24,12 +24,12 class ApiTest::AttachmentsTest < ActionController::IntegrationTest | |||||
24 | Setting.rest_api_enabled = '1' |
|
24 | Setting.rest_api_enabled = '1' | |
25 | Attachment.storage_path = "#{Rails.root}/test/fixtures/files" |
|
25 | Attachment.storage_path = "#{Rails.root}/test/fixtures/files" | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | context "/attachments/:id" do |
|
28 | context "/attachments/:id" do | |
29 | context "GET" do |
|
29 | context "GET" do | |
30 | should "return the attachment" do |
|
30 | should "return the attachment" do | |
31 | get '/attachments/7.xml', {}, :authorization => credentials('jsmith') |
|
31 | get '/attachments/7.xml', {}, :authorization => credentials('jsmith') | |
32 |
|
32 | |||
33 | assert_response :success |
|
33 | assert_response :success | |
34 | assert_equal 'application/xml', @response.content_type |
|
34 | assert_equal 'application/xml', @response.content_type | |
35 | assert_tag :tag => 'attachment', |
|
35 | assert_tag :tag => 'attachment', | |
@@ -46,32 +46,32 class ApiTest::AttachmentsTest < ActionController::IntegrationTest | |||||
46 | } |
|
46 | } | |
47 | } |
|
47 | } | |
48 | end |
|
48 | end | |
49 |
|
49 | |||
50 | should "deny access without credentials" do |
|
50 | should "deny access without credentials" do | |
51 | get '/attachments/7.xml' |
|
51 | get '/attachments/7.xml' | |
52 |
|
52 | |||
53 | assert_response 401 |
|
53 | assert_response 401 | |
54 | end |
|
54 | end | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | context "/attachments/download/:id/:filename" do |
|
58 | context "/attachments/download/:id/:filename" do | |
59 | context "GET" do |
|
59 | context "GET" do | |
60 | should "return the attachment content" do |
|
60 | should "return the attachment content" do | |
61 | get '/attachments/download/7/archive.zip', {}, :authorization => credentials('jsmith') |
|
61 | get '/attachments/download/7/archive.zip', {}, :authorization => credentials('jsmith') | |
62 |
|
62 | |||
63 | assert_response :success |
|
63 | assert_response :success | |
64 | assert_equal 'application/octet-stream', @response.content_type |
|
64 | assert_equal 'application/octet-stream', @response.content_type | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | should "deny access without credentials" do |
|
67 | should "deny access without credentials" do | |
68 | get '/attachments/download/7/archive.zip' |
|
68 | get '/attachments/download/7/archive.zip' | |
69 |
|
69 | |||
70 | assert_response 302 |
|
70 | assert_response 302 | |
71 | end |
|
71 | end | |
72 | end |
|
72 | end | |
73 | end |
|
73 | end | |
74 |
|
74 | |||
75 | def credentials(user, password=nil) |
|
75 | def credentials(user, password=nil) | |
76 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
76 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
77 | end |
|
77 | end |
General Comments 0
You need to be logged in to leave comments.
Login now