To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 27 / 275a63d95374044297ed252103e82089ce4c9a74.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (2.84 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
require File.expand_path('../../../test_helper', __FILE__)
19

    
20
class ApiTest::AttachmentsTest < ActionController::IntegrationTest
21
  fixtures :projects, :trackers, :issue_statuses, :issues,
22
           :enumerations, :users, :issue_categories,
23
           :projects_trackers,
24
           :roles,
25
           :member_roles,
26
           :members,
27
           :enabled_modules,
28
           :workflows,
29
           :attachments
30

    
31
  def setup
32
    Setting.rest_api_enabled = '1'
33
    Attachment.storage_path = "#{Rails.root}/test/fixtures/files"
34
  end
35

    
36
  context "/attachments/:id" do
37
    context "GET" do
38
      should "return the attachment" do
39
        get '/attachments/7.xml', {}, :authorization => credentials('jsmith')
40
        assert_response :success
41
        assert_equal 'application/xml', @response.content_type
42
        assert_tag :tag => 'attachment',
43
          :child => {
44
            :tag => 'id',
45
            :content => '7',
46
            :sibling => {
47
              :tag => 'filename',
48
              :content => 'archive.zip',
49
              :sibling => {
50
                :tag => 'content_url',
51
                :content => 'http://www.example.com/attachments/download/7/archive.zip'
52
              }
53
            }
54
          }
55
      end
56

    
57
      should "deny access without credentials" do
58
        get '/attachments/7.xml'
59
        assert_response 401
60
        set_tmp_attachments_directory
61
      end
62
    end
63
  end
64

    
65
  context "/attachments/download/:id/:filename" do
66
    context "GET" do
67
      should "return the attachment content" do
68
        get '/attachments/download/7/archive.zip',
69
            {}, :authorization => credentials('jsmith')
70
        assert_response :success
71
        assert_equal 'application/octet-stream', @response.content_type
72
        set_tmp_attachments_directory
73
      end
74

    
75
      should "deny access without credentials" do
76
        get '/attachments/download/7/archive.zip'
77
        assert_response 302
78
        set_tmp_attachments_directory
79
      end
80
    end
81
  end
82

    
83
  def credentials(user, password=nil)
84
    ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
85
  end
86
end