Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
806a9497
Commit
806a9497
authored
Oct 14, 2003
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged yuppie-collector1079-branch:
- Fixed BaseRequest's traversal loop. (Collector #1079)
parent
c40186da
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
161 additions
and
4 deletions
+161
-4
lib/python/ZPublisher/BaseRequest.py
lib/python/ZPublisher/BaseRequest.py
+6
-4
lib/python/ZPublisher/tests/testBaseRequest.py
lib/python/ZPublisher/tests/testBaseRequest.py
+155
-0
No files found.
lib/python/ZPublisher/BaseRequest.py
View file @
806a9497
...
...
@@ -10,7 +10,10 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__version__
=
'$Revision: 1.51 $'
[
11
:
-
2
]
""" Basic ZPublisher request management.
$Id: BaseRequest.py,v 1.52 2003/10/14 09:08:44 yuppie Exp $
"""
from
urllib
import
quote
import
xmlrpc
...
...
@@ -269,13 +272,13 @@ class BaseRequest:
request
[
'TraversalRequestNameStack'
]
=
path
continue
else
:
method
=
default_path
[
0
]
entry_name
=
method
entry_name
=
default_path
[
0
]
elif
(
method
and
hasattr
(
object
,
method
)
and
entry_name
!=
method
and
getattr
(
object
,
method
)
is
not
None
):
request
.
_hacked_path
=
1
entry_name
=
method
method
=
'index_html'
else
:
if
(
hasattr
(
object
,
'__call__'
)
and
hasattr
(
object
.
__call__
,
'__roles__'
)):
...
...
@@ -284,7 +287,6 @@ class BaseRequest:
i
=
URL
.
rfind
(
'/'
)
if
i
>
0
:
response
.
setBase
(
URL
[:
i
])
break
if
not
entry_name
:
continue
step
=
quote
(
entry_name
)
_steps
.
append
(
step
)
request
[
'URL'
]
=
URL
=
'%s/%s'
%
(
request
[
'URL'
],
step
)
...
...
lib/python/ZPublisher/tests/testBaseRequest.py
0 → 100644
View file @
806a9497
from
unittest
import
TestCase
,
TestSuite
,
makeSuite
,
main
import
Zope
Zope
.
startup
()
from
Acquisition
import
Implicit
from
ZPublisher.BaseRequest
import
BaseRequest
from
ZPublisher.HTTPResponse
import
HTTPResponse
class
DummyObjectBasic
(
Implicit
):
""" Dummy class with docstring.
"""
def
_setObject
(
self
,
id
,
object
):
setattr
(
self
,
id
,
object
)
return
getattr
(
self
,
id
)
def
view
(
self
):
""" Atrribute with docstring.
"""
return
'view content'
class
DummyObjectWithDefault
(
DummyObjectBasic
):
""" Dummy class with docstring.
"""
def
index_html
(
self
):
""" Atrribute with docstring.
"""
return
'index_html content'
class
DummyObjectWithDefaultNone
(
DummyObjectWithDefault
):
""" Dummy class with docstring.
"""
index_html
=
None
class
DummyObjectWithBPTH
(
DummyObjectBasic
):
""" Dummy class with docstring.
"""
def
__before_publishing_traverse__
(
self
,
object
,
REQUEST
):
if
REQUEST
[
'_test_counter'
]
<
100
:
REQUEST
[
'_test_counter'
]
+=
1
else
:
raise
RuntimeError
(
'Infinite loop detected.'
)
REQUEST
[
'TraversalRequestNameStack'
]
+=
self
.
_path
REQUEST
.
_hacked_path
=
1
class
DummyObjectWithBD
(
DummyObjectBasic
):
""" Dummy class with docstring.
"""
def
__browser_default__
(
self
,
REQUEST
):
if
REQUEST
[
'_test_counter'
]
<
100
:
REQUEST
[
'_test_counter'
]
+=
1
else
:
raise
RuntimeError
(
'Infinite loop detected.'
)
return
self
,
self
.
_default_path
class
TestBaseRequest
(
TestCase
):
def
setUp
(
self
):
self
.
root
=
DummyObjectBasic
()
self
.
f1
=
self
.
root
.
_setObject
(
'folder'
,
DummyObjectBasic
()
)
self
.
f1
.
_setObject
(
'objBasic'
,
DummyObjectBasic
()
)
self
.
f1
.
_setObject
(
'objWithDefault'
,
DummyObjectWithDefault
()
)
self
.
f1
.
_setObject
(
'objWithDefaultNone'
,
DummyObjectWithDefaultNone
()
)
self
.
f1
.
_setObject
(
'objWithBPTH'
,
DummyObjectWithBPTH
()
)
self
.
f1
.
_setObject
(
'objWithBD'
,
DummyObjectWithBD
()
)
def
makeBaseRequest
(
self
):
response
=
HTTPResponse
()
environment
=
{
'URL'
:
''
,
'PARENTS'
:
[
self
.
root
],
'steps'
:
[],
'_hacked_path'
:
0
,
'_test_counter'
:
0
,
'response'
:
response
}
return
BaseRequest
(
environment
)
def
test_traverse_basic
(
self
):
r
=
self
.
makeBaseRequest
()
r
.
traverse
(
'folder/objBasic'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objBasic'
)
self
.
assertEqual
(
r
.
response
.
base
,
''
)
def
test_traverse_withDefault
(
self
):
r
=
self
.
makeBaseRequest
()
r
.
traverse
(
'folder/objWithDefault'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithDefault/index_html'
)
self
.
assertEqual
(
r
.
response
.
base
,
'/folder/objWithDefault/'
)
def
test_traverse_withDefaultNone
(
self
):
r
=
self
.
makeBaseRequest
()
r
.
traverse
(
'folder/objWithDefaultNone'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithDefaultNone'
)
self
.
assertEqual
(
r
.
response
.
base
,
''
)
def
test_traverse_withBPTH
(
self
):
r
=
self
.
makeBaseRequest
()
self
.
f1
.
objWithBPTH
.
_path
=
[
'view'
]
r
.
traverse
(
'folder/objWithBPTH'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithBPTH/view'
)
self
.
assertEqual
(
r
.
response
.
base
,
'/folder/objWithBPTH/'
)
def
test_traverse_withBDView
(
self
):
r
=
self
.
makeBaseRequest
()
self
.
f1
.
objWithBD
.
_default_path
=
[
'view'
]
r
.
traverse
(
'folder/objWithBD'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithBD/view'
)
self
.
assertEqual
(
r
.
response
.
base
,
'/folder/objWithBD/'
)
def
test_traverse_withAcquisition
(
self
):
r
=
self
.
makeBaseRequest
()
self
.
f1
.
objWithBPTH
.
_path
=
[
'view'
]
self
.
f1
.
objWithBD
.
_default_path
=
[
'view'
]
r
.
traverse
(
'folder/objWithBD/objWithBPTH'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithBD/objWithBPTH/view'
)
self
.
assertEqual
(
r
.
response
.
base
,
'/folder/objWithBD/objWithBPTH/'
)
def
test_traverse_withBDAndBPTH
(
self
):
# Collector 1079 (infinite loop 1)
r
=
self
.
makeBaseRequest
()
self
.
f1
.
objWithBPTH
.
_path
=
[
'objBasic'
]
self
.
f1
.
objWithBD
.
_default_path
=
[
'objWithBPTH'
]
r
.
traverse
(
'folder/objWithBD'
)
self
.
assertEqual
(
r
.
URL
,
'/folder/objWithBD/objWithBPTH/objBasic'
)
self
.
assertEqual
(
r
.
response
.
base
,
'/folder/objWithBD/objWithBPTH/'
)
def
test_traverse_withBDEmpty
(
self
):
# Collector 1079 (infinite loop 2)
r
=
self
.
makeBaseRequest
()
self
.
f1
.
objWithBD
.
_default_path
=
[
''
]
self
.
failUnlessRaises
(
'NotFound'
,
r
.
traverse
,
'folder/objWithBD'
)
def
test_traverse_slash
(
self
):
r
=
self
.
makeBaseRequest
()
r
[
'PARENTS'
]
=
[
self
.
f1
.
objWithDefault
]
r
.
traverse
(
'/'
)
self
.
assertEqual
(
r
.
URL
,
'/index_html'
)
self
.
assertEqual
(
r
.
response
.
base
,
''
)
def
test_suite
():
return
TestSuite
(
(
makeSuite
(
TestBaseRequest
),
)
)
if
__name__
==
'__main__'
:
main
(
defaultTest
=
'test_suite'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment