a30ca149fbb9f515af25c84dffa6e704145649e0
1 # GNU Mediagoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
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 Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from nose
.tools
import assert_raises
23 from mediagoblin
import storage
26 def test_clean_listy_filepath():
27 expected
= [u
'dir1', u
'dir2', u
'linooks.jpg']
28 assert storage
.clean_listy_filepath(
29 ['dir1', 'dir2', 'linooks.jpg']) == expected
31 expected
= [u
'dir1', u
'foo_.._nasty', u
'linooks.jpg']
32 assert storage
.clean_listy_filepath(
33 ['/dir1/', 'foo/../nasty', 'linooks.jpg']) == expected
35 expected
= [u
'etc', u
'passwd']
36 assert storage
.clean_listy_filepath(
37 ['../../../etc/', 'passwd']) == expected
40 storage
.InvalidFilepath
,
41 storage
.clean_listy_filepath
,
42 ['../../', 'linooks.jpg'])
45 ##########################
46 # Basic file storage tests
47 ##########################
49 def get_tmp_filestorage(mount_url
=None):
50 tmpdir
= tempfile
.mkdtemp()
51 this_storage
= storage
.BasicFileStorage(tmpdir
, mount_url
)
52 return tmpdir
, this_storage
55 def test_basic_storage__resolve_filepath():
56 tmpdir
, this_storage
= get_tmp_filestorage()
58 result
= this_storage
._resolve
_filepath
(['dir1', 'dir2', 'filename.jpg'])
59 assert result
== os
.path
.join(
60 tmpdir
, 'dir1/dir2/filename.jpg')
62 result
= this_storage
._resolve
_filepath
(['../../etc/', 'passwd'])
63 assert result
== os
.path
.join(
67 storage
.InvalidFilepath
,
68 this_storage
._resolve
_filepath
,
69 ['../../', 'etc', 'passwd'])
72 def test_basic_storage_file_exists():
76 def test_basic_storage_get_file():
80 def test_basic_storage_delete_file():
84 def test_basic_storage_url_for_file():