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
b87e500e
Commit
b87e500e
authored
Jul 29, 2007
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup
parent
b8849ab2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
46 deletions
+22
-46
lib/python/ZPublisher/tests/testHTTPRequest.py
lib/python/ZPublisher/tests/testHTTPRequest.py
+22
-46
No files found.
lib/python/ZPublisher/tests/testHTTPRequest.py
View file @
b87e500e
import
sys
import
base64
import
unittest
import
unittest
from
urllib
import
quote_plus
from
urllib
import
quote_plus
from
types
import
ListType
,
TupleType
,
StringType
,
UnicodeType
from
StringIO
import
StringIO
from
DateTime
import
DateTime
from
ZPublisher.HTTPRequest
import
HTTPRequest
,
record
,
trusted_proxies
from
ZPublisher.TaintedString
import
TaintedString
from
ZPublisher.Converters
import
type_converters
TEST_LARGEFILE_DATA
=
'''
TEST_LARGEFILE_DATA
=
'''
--12345
--12345
...
@@ -13,13 +22,10 @@ test %s
...
@@ -13,13 +22,10 @@ test %s
class
AuthCredentialsTests
(
unittest
.
TestCase
):
class
AuthCredentialsTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
def
_getTargetClass
(
self
):
from
ZPublisher.HTTPRequest
import
HTTPRequest
return
HTTPRequest
return
HTTPRequest
def
_makeOne
(
self
,
stdin
=
None
,
environ
=
None
,
response
=
None
,
clean
=
1
):
def
_makeOne
(
self
,
stdin
=
None
,
environ
=
None
,
response
=
None
,
clean
=
1
):
if
stdin
is
None
:
if
stdin
is
None
:
from
StringIO
import
StringIO
stdin
=
StringIO
()
stdin
=
StringIO
()
if
environ
is
None
:
if
environ
is
None
:
...
@@ -40,9 +46,6 @@ class AuthCredentialsTests( unittest.TestCase ):
...
@@ -40,9 +46,6 @@ class AuthCredentialsTests( unittest.TestCase ):
return
self
.
_getTargetClass
()(
stdin
,
environ
,
response
,
clean
)
return
self
.
_getTargetClass
()(
stdin
,
environ
,
response
,
clean
)
def
test__authUserPW_simple
(
self
):
def
test__authUserPW_simple
(
self
):
import
base64
user_id
=
'user'
user_id
=
'user'
password
=
'password'
password
=
'password'
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
)
)
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
)
)
...
@@ -57,11 +60,7 @@ class AuthCredentialsTests( unittest.TestCase ):
...
@@ -57,11 +60,7 @@ class AuthCredentialsTests( unittest.TestCase ):
self
.
assertEqual
(
password_x
,
password
)
self
.
assertEqual
(
password_x
,
password
)
def
test__authUserPW_with_embedded_colon
(
self
):
def
test__authUserPW_with_embedded_colon
(
self
):
# http://www.zope.org/Collectors/Zope/2039
# http://www.zope.org/Collectors/Zope/2039
import
base64
user_id
=
'user'
user_id
=
'user'
password
=
'embedded:colon'
password
=
'embedded:colon'
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
)
)
encoded
=
base64
.
encodestring
(
'%s:%s'
%
(
user_id
,
password
)
)
...
@@ -75,21 +74,20 @@ class AuthCredentialsTests( unittest.TestCase ):
...
@@ -75,21 +74,20 @@ class AuthCredentialsTests( unittest.TestCase ):
self
.
assertEqual
(
user_id_x
,
user_id
)
self
.
assertEqual
(
user_id_x
,
user_id
)
self
.
assertEqual
(
password_x
,
password
)
self
.
assertEqual
(
password_x
,
password
)
class
RecordTests
(
unittest
.
TestCase
):
def
test_repr
(
self
):
class
RecordTests
(
unittest
.
TestCase
):
from
ZPublisher.HTTPRequest
import
record
record
=
record
()
def
test_repr
(
self
):
record
.
a
=
1
rec
=
record
()
record
.
b
=
'foo'
rec
.
a
=
1
r
=
repr
(
record
)
rec
.
b
=
'foo'
d
=
eval
(
r
)
r
=
repr
(
rec
)
self
.
assertEqual
(
d
,
record
.
__dict__
)
d
=
eval
(
r
)
self
.
assertEqual
(
d
,
rec
.
__dict__
)
class
ProcessInputsTests
(
unittest
.
TestCase
):
class
ProcessInputsTests
(
unittest
.
TestCase
):
def
_getHTTPRequest
(
self
,
env
):
def
_getHTTPRequest
(
self
,
env
):
from
ZPublisher.HTTPRequest
import
HTTPRequest
return
HTTPRequest
(
None
,
env
,
None
)
return
HTTPRequest
(
None
,
env
,
None
)
def
_processInputs
(
self
,
inputs
):
def
_processInputs
(
self
,
inputs
):
...
@@ -119,9 +117,6 @@ class ProcessInputsTests(unittest.TestCase):
...
@@ -119,9 +117,6 @@ class ProcessInputsTests(unittest.TestCase):
# when one is found.
# when one is found.
# Also raises an Assertion if a string which *should* have been
# Also raises an Assertion if a string which *should* have been
# tainted is found, or when a tainted string is not deemed dangerous.
# tainted is found, or when a tainted string is not deemed dangerous.
from
types
import
ListType
,
TupleType
,
StringType
,
UnicodeType
from
ZPublisher.HTTPRequest
import
record
from
ZPublisher.TaintedString
import
TaintedString
retval
=
0
retval
=
0
...
@@ -199,8 +194,6 @@ class ProcessInputsTests(unittest.TestCase):
...
@@ -199,8 +194,6 @@ class ProcessInputsTests(unittest.TestCase):
self
.
_onlyTaintedformHoldsTaintedStrings
(
req
)
self
.
_onlyTaintedformHoldsTaintedStrings
(
req
)
def
testSimpleMarshalling
(
self
):
def
testSimpleMarshalling
(
self
):
from
DateTime
import
DateTime
inputs
=
(
inputs
=
(
(
'num:int'
,
'42'
),
(
'fract:float'
,
'4.2'
),
(
'bign:long'
,
'45'
),
(
'num:int'
,
'42'
),
(
'fract:float'
,
'4.2'
),
(
'bign:long'
,
'45'
),
(
'words:string'
,
'Some words'
),
(
'2tokens:tokens'
,
'one two'
),
(
'words:string'
,
'Some words'
),
(
'2tokens:tokens'
,
'one two'
),
...
@@ -454,9 +447,6 @@ class ProcessInputsTests(unittest.TestCase):
...
@@ -454,9 +447,6 @@ class ProcessInputsTests(unittest.TestCase):
self
.
_onlyTaintedformHoldsTaintedStrings
(
req
)
self
.
_onlyTaintedformHoldsTaintedStrings
(
req
)
def
testSimpleContainersWithTaints
(
self
):
def
testSimpleContainersWithTaints
(
self
):
from
types
import
ListType
,
TupleType
from
ZPublisher.HTTPRequest
import
record
inputs
=
(
inputs
=
(
(
'toneitem:list'
,
'<one>'
),
(
'toneitem:list'
,
'<one>'
),
(
'<tkeyoneitem>:list'
,
'one'
),
(
'<tkeyoneitem>:list'
,
'one'
),
...
@@ -611,8 +601,6 @@ class ProcessInputsTests(unittest.TestCase):
...
@@ -611,8 +601,6 @@ class ProcessInputsTests(unittest.TestCase):
def
testNoTaintedExceptions
(
self
):
def
testNoTaintedExceptions
(
self
):
# Feed tainted garbage to the conversion methods, and any exception
# Feed tainted garbage to the conversion methods, and any exception
# returned should be HTML safe
# returned should be HTML safe
from
ZPublisher.Converters
import
type_converters
from
DateTime
import
DateTime
for
type
,
convert
in
type_converters
.
items
():
for
type
,
convert
in
type_converters
.
items
():
try
:
try
:
convert
(
'<html garbage>'
)
convert
(
'<html garbage>'
)
...
@@ -695,12 +683,10 @@ class RequestTests( unittest.TestCase ):
...
@@ -695,12 +683,10 @@ class RequestTests( unittest.TestCase ):
def
testRemoveStdinReferences
(
self
):
def
testRemoveStdinReferences
(
self
):
# Verifies that all references to the input stream go away on
# Verifies that all references to the input stream go away on
# request.close(). Otherwise a tempfile may stick around.
# request.close(). Otherwise a tempfile may stick around.
import
sys
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_FILE_DATA
)
s
=
StringIO
(
TEST_FILE_DATA
)
env
=
TEST_ENVIRON
.
copy
()
env
=
TEST_ENVIRON
.
copy
()
start_count
=
sys
.
getrefcount
(
s
)
start_count
=
sys
.
getrefcount
(
s
)
from
ZPublisher.HTTPRequest
import
HTTPRequest
req
=
HTTPRequest
(
s
,
env
,
None
)
req
=
HTTPRequest
(
s
,
env
,
None
)
req
.
processInputs
()
req
.
processInputs
()
self
.
assertNotEqual
(
start_count
,
sys
.
getrefcount
(
s
))
# Precondition
self
.
assertNotEqual
(
start_count
,
sys
.
getrefcount
(
s
))
# Precondition
...
@@ -709,10 +695,9 @@ class RequestTests( unittest.TestCase ):
...
@@ -709,10 +695,9 @@ class RequestTests( unittest.TestCase ):
def
testFileName
(
self
):
def
testFileName
(
self
):
# checks fileupload object supports the filename
# checks fileupload object supports the filename
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_LARGEFILE_DATA
)
s
=
StringIO
(
TEST_LARGEFILE_DATA
)
env
=
TEST_ENVIRON
.
copy
()
env
=
TEST_ENVIRON
.
copy
()
from
ZPublisher.HTTPRequest
import
HTTPRequest
req
=
HTTPRequest
(
s
,
env
,
None
)
req
=
HTTPRequest
(
s
,
env
,
None
)
req
.
processInputs
()
req
.
processInputs
()
f
=
req
.
form
.
get
(
'file'
)
f
=
req
.
form
.
get
(
'file'
)
...
@@ -721,11 +706,9 @@ class RequestTests( unittest.TestCase ):
...
@@ -721,11 +706,9 @@ class RequestTests( unittest.TestCase ):
def
testFileIterator
(
self
):
def
testFileIterator
(
self
):
# checks fileupload object supports the iterator protocol
# checks fileupload object supports the iterator protocol
# collector entry 1837
# collector entry 1837
import
sys
from
StringIO
import
StringIO
s
=
StringIO
(
TEST_FILE_DATA
)
s
=
StringIO
(
TEST_FILE_DATA
)
env
=
TEST_ENVIRON
.
copy
()
env
=
TEST_ENVIRON
.
copy
()
from
ZPublisher.HTTPRequest
import
HTTPRequest
req
=
HTTPRequest
(
s
,
env
,
None
)
req
=
HTTPRequest
(
s
,
env
,
None
)
req
.
processInputs
()
req
.
processInputs
()
f
=
req
.
form
.
get
(
'file'
)
f
=
req
.
form
.
get
(
'file'
)
...
@@ -741,8 +724,6 @@ class RequestTests( unittest.TestCase ):
...
@@ -741,8 +724,6 @@ class RequestTests( unittest.TestCase ):
'SERVER_NAME'
:
'localhost'
,
'SERVER_NAME'
:
'localhost'
,
'SERVER_PORT'
:
'80'
,
'SERVER_PORT'
:
'80'
,
}
}
from
StringIO
import
StringIO
from
ZPublisher.HTTPRequest
import
HTTPRequest
s
=
StringIO
(
''
)
s
=
StringIO
(
''
)
# accessing request.debug from non-Zope3 code will raise an
# accessing request.debug from non-Zope3 code will raise an
...
@@ -780,8 +761,6 @@ class RequestTests( unittest.TestCase ):
...
@@ -780,8 +761,6 @@ class RequestTests( unittest.TestCase ):
'SERVER_NAME'
:
'localhost'
,
'SERVER_NAME'
:
'localhost'
,
'SERVER_PORT'
:
'80'
,
'SERVER_PORT'
:
'80'
,
}
}
from
StringIO
import
StringIO
from
ZPublisher.HTTPRequest
import
HTTPRequest
s
=
StringIO
(
''
)
s
=
StringIO
(
''
)
env
=
TEST_ENVIRON
.
copy
()
env
=
TEST_ENVIRON
.
copy
()
...
@@ -801,8 +780,6 @@ class RequestTests( unittest.TestCase ):
...
@@ -801,8 +780,6 @@ class RequestTests( unittest.TestCase ):
'REMOTE_ADDR'
:
'127.0.0.1'
,
'REMOTE_ADDR'
:
'127.0.0.1'
,
'HTTP_X_FORWARDED_FOR'
:
'10.1.20.30, 192.168.1.100'
,
'HTTP_X_FORWARDED_FOR'
:
'10.1.20.30, 192.168.1.100'
,
}
}
from
StringIO
import
StringIO
from
ZPublisher.HTTPRequest
import
HTTPRequest
,
trusted_proxies
s
=
StringIO
(
''
)
s
=
StringIO
(
''
)
env
=
TEST_ENVIRON
.
copy
()
env
=
TEST_ENVIRON
.
copy
()
...
@@ -824,7 +801,6 @@ class RequestTests( unittest.TestCase ):
...
@@ -824,7 +801,6 @@ class RequestTests( unittest.TestCase ):
request
=
HTTPRequest
(
s
,
env
,
None
)
request
=
HTTPRequest
(
s
,
env
,
None
)
self
.
assertEqual
(
request
.
getClientAddr
(),
''
)
self
.
assertEqual
(
request
.
getClientAddr
(),
''
)
def
test_suite
():
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
AuthCredentialsTests
,
'test'
))
suite
.
addTest
(
unittest
.
makeSuite
(
AuthCredentialsTests
,
'test'
))
...
...
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