2
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
5
# of this software and associated documentation files (the "Software"), to deal
6
# in the Software without restriction, including without limitation the rights
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
# copies of the Software, and to permit persons to whom the Software is
9
# furnished to do so, subject to the following conditions:
11
# The above copyright notice and this permission notice shall be included in all
12
# copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
# DRI: Wilfredo Sanchez, wsanchez@apple.com
25
from twisted.trial import unittest
26
from twisted.web2.dav import util
28
class Utilities(unittest.TestCase):
32
def test_normalizeURL(self):
36
self.assertEquals(util.normalizeURL("http://server//foo"), "http://server/foo")
37
self.assertEquals(util.normalizeURL("http://server/foo/.."), "http://server/")
38
self.assertEquals(util.normalizeURL("/foo/bar/..//"), "/foo")
39
self.assertEquals(util.normalizeURL("/foo/bar/.//"), "/foo/bar")
40
self.assertEquals(util.normalizeURL("//foo///bar/../baz"), "/foo/baz")
41
self.assertEquals(util.normalizeURL("//foo///bar/./baz"), "/foo/bar/baz")
42
self.assertEquals(util.normalizeURL("///../"), "/")
43
self.assertEquals(util.normalizeURL("/.."), "/")
45
def test_joinURL(self):
49
self.assertEquals(util.joinURL("http://server/foo/"), "http://server/foo/")
50
self.assertEquals(util.joinURL("http://server/foo", "/bar"), "http://server/foo/bar")
51
self.assertEquals(util.joinURL("http://server/foo", "bar"), "http://server/foo/bar")
52
self.assertEquals(util.joinURL("http://server/foo/", "/bar"), "http://server/foo/bar")
53
self.assertEquals(util.joinURL("http://server/foo/", "/bar/.."), "http://server/foo")
54
self.assertEquals(util.joinURL("http://server/foo/", "/bar/."), "http://server/foo/bar")
55
self.assertEquals(util.joinURL("http://server/foo/", "/bar/../"), "http://server/foo/")
56
self.assertEquals(util.joinURL("http://server/foo/", "/bar/./"), "http://server/foo/bar/")
57
self.assertEquals(util.joinURL("http://server/foo/../", "/bar"), "http://server/bar")
58
self.assertEquals(util.joinURL("/foo/"), "/foo/")
59
self.assertEquals(util.joinURL("/foo", "/bar"), "/foo/bar")
60
self.assertEquals(util.joinURL("/foo", "bar"), "/foo/bar")
61
self.assertEquals(util.joinURL("/foo/", "/bar"), "/foo/bar")
62
self.assertEquals(util.joinURL("/foo/", "/bar/.."), "/foo")
63
self.assertEquals(util.joinURL("/foo/", "/bar/."), "/foo/bar")
64
self.assertEquals(util.joinURL("/foo/", "/bar/../"), "/foo/")
65
self.assertEquals(util.joinURL("/foo/", "/bar/./"), "/foo/bar/")
66
self.assertEquals(util.joinURL("/foo/../", "/bar"), "/bar")
67
self.assertEquals(util.joinURL("/foo", "/../"), "/")
68
self.assertEquals(util.joinURL("/foo", "/./"), "/foo/")
70
def test_parentForURL(self):
74
self.assertEquals(util.parentForURL("http://server/"), None)
75
self.assertEquals(util.parentForURL("http://server//"), None)
76
self.assertEquals(util.parentForURL("http://server/foo/.."), None)
77
self.assertEquals(util.parentForURL("http://server/foo/../"), None)
78
self.assertEquals(util.parentForURL("http://server/foo/."), "http://server/")
79
self.assertEquals(util.parentForURL("http://server/foo/./"), "http://server/")
80
self.assertEquals(util.parentForURL("http://server/foo"), "http://server/")
81
self.assertEquals(util.parentForURL("http://server//foo"), "http://server/")
82
self.assertEquals(util.parentForURL("http://server/foo/bar/.."), "http://server/")
83
self.assertEquals(util.parentForURL("http://server/foo/bar/."), "http://server/foo/")
84
self.assertEquals(util.parentForURL("http://server/foo/bar"), "http://server/foo/")
85
self.assertEquals(util.parentForURL("http://server/foo/bar/"), "http://server/foo/")
86
self.assertEquals(util.parentForURL("/"), None)
87
self.assertEquals(util.parentForURL("/foo/.."), None)
88
self.assertEquals(util.parentForURL("/foo/../"), None)
89
self.assertEquals(util.parentForURL("/foo/."), "/")
90
self.assertEquals(util.parentForURL("/foo/./"), "/")
91
self.assertEquals(util.parentForURL("/foo"), "/")
92
self.assertEquals(util.parentForURL("/foo"), "/")
93
self.assertEquals(util.parentForURL("/foo/bar/.."), "/")
94
self.assertEquals(util.parentForURL("/foo/bar/."), "/foo/")
95
self.assertEquals(util.parentForURL("/foo/bar"), "/foo/")
96
self.assertEquals(util.parentForURL("/foo/bar/"), "/foo/")