~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/studpath.py

  • Committer: William Grant
  • Date: 2010-02-15 05:37:50 UTC
  • Revision ID: grantw@unimelb.edu.au-20100215053750-hihmegnp8e7dshc2
Ignore test coverage files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    Returns (None, None) if the path is empty.
52
52
 
53
53
    >>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
54
 
    >>> url_to_local(stubconfig, '')
55
 
    (None, None)
 
54
 
56
55
    >>> url_to_local(stubconfig, 'joe/foo/bar/baz')
57
56
    ('joe', '/jails/joe/home/joe/foo/bar/baz')
 
57
    >>> url_to_local(stubconfig, 'joe')
 
58
    ('joe', '/jails/joe/home/joe')
 
59
    >>> url_to_local(stubconfig, 'joe/')
 
60
    ('joe', '/jails/joe/home/joe')
 
61
 
 
62
    We have some protection from various potential attacks. An empty,
 
63
    absolute, or ..-prefixed path yields a special result.
 
64
 
 
65
    >>> url_to_local(stubconfig, '')
 
66
    (None, None)
 
67
    >>> url_to_local(stubconfig, '/foo')
 
68
    (None, None)
 
69
    >>> url_to_local(stubconfig, '../bar')
 
70
    (None, None)
58
71
    """
59
72
 
60
73
    # First normalise the path
85
98
 
86
99
    urlpath: See urlpath in url_to_local.
87
100
 
88
 
    >>> url_to_jailpaths("joe/mydir/myfile")
89
 
    ('joe', '/var/lib/ivle/jailmounts/joe', '/home/joe/mydir/myfile')
 
101
    >>> stubconfig = {'paths': {'jails': {'mounts': '/jails'}}}
90
102
 
91
 
    >>> url_to_jailpaths("")
 
103
    >>> url_to_jailpaths(stubconfig, "joe/mydir//myfile/.././myfile")
 
104
    ('joe', '/jails/joe', '/home/joe/mydir/myfile')
 
105
    >>> url_to_jailpaths(stubconfig, "")
 
106
    (None, None, None)
 
107
    >>> url_to_jailpaths(stubconfig, "../foo")
 
108
    (None, None, None)
 
109
    >>> url_to_jailpaths(stubconfig, "/foo")
92
110
    (None, None, None)
93
111
    """
94
112
    # First normalise the path
95
113
    urlpath = os.path.normpath(urlpath)
96
 
    # Now if it begins with ".." then it's illegal
97
 
    if urlpath.startswith(".."):
 
114
    # Now if it begins with "..", or is absolute, then it's illegal
 
115
    if urlpath.startswith("..") or os.path.isabs(urlpath):
98
116
        return (None, None, None)
99
117
    # Note: User can be a group name. There is absolutely no difference in our
100
118
    # current directory scheme.
111
129
 
112
130
    >>> to_home_path('joe/foo/bar/baz')
113
131
    '/home/joe/foo/bar/baz'
 
132
    >>> to_home_path('joe/foo//bar/baz/../../')
 
133
    '/home/joe/foo'
 
134
    >>> to_home_path('joe/foo//bar/baz/../../../../../') is None
 
135
    True
114
136
    """
 
137
 
 
138
    urlpath = os.path.normpath(urlpath)
 
139
    # If it begins with '..', it's illegal.
 
140
    if urlpath.startswith(".."):
 
141
        return None
 
142
 
115
143
    return os.path.join('/home', urlpath)
116
144
 
117
145
def svnpublished(path):