cdcddf098130f7f91e9cf08ad3f535a175b8ace2
[mediagoblin.git] / mediagoblin / tests / test_storage.py
1 # GNU Mediagoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
3 #
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.
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 Affero General Public License for more details.
13 #
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/>.
16
17
18 from mediagoblin import storage
19
20
21 def test_clean_listy_filepath():
22 expected = [u'dir1', u'dir2', u'linooks.jpg']
23 assert storage.clean_listy_filepath(
24 ['dir1', 'dir2', 'linooks.jpg']) == expected
25
26 expected = [u'dir1', u'foo_.._nasty', u'linooks.jpg']
27 assert storage.clean_listy_filepath(
28 ['/dir1/', 'foo/../nasty', 'linooks.jpg']) == expected
29
30 expected = [u'etc', u'passwd']
31 assert storage.clean_listy_filepath(
32 ['../../../etc/', 'passwd']) == expected
33
34 try:
35 storage.clean_listy_filepath(
36 ['../../', 'linooks.jpg'])
37 except storage.InvalidFilepath:
38 # Yes, this error should be raise
39 pass
40 else:
41 assert "success" == "failboat"