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
aa6b8b78
Commit
aa6b8b78
authored
Apr 21, 2010
by
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- fixed some unicode issues in Unauthorized
parent
c9d53e90
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
4 deletions
+142
-4
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
src/zExceptions/tests/test_unauthorized.py
src/zExceptions/tests/test_unauthorized.py
+130
-0
src/zExceptions/unauthorized.py
src/zExceptions/unauthorized.py
+10
-4
No files found.
doc/CHANGES.rst
View file @
aa6b8b78
...
...
@@ -55,6 +55,8 @@ Features Added
Bugs Fixed
++++++++++
- zExceptions: Fixed some unicode issues in Unauthorized.
- LP #372632, comments #15ff.: Fixed regression in Unauthorized handling.
- LP #563229: Process "evil" JSON cookies which contain double quotes in
...
...
src/zExceptions/tests/test_unauthorized.py
0 → 100644
View file @
aa6b8b78
##############################################################################
#
# Copyright (c) 2010 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Unit tests for unauthorized module.
$Id$
"""
import
unittest
from
zope.interface.verify
import
verifyClass
_MESSAGE
=
"You are not allowed to access '%s' in this context"
class
UnauthorizedTests
(
unittest
.
TestCase
):
def
_getTargetClass
(
self
):
from
zExceptions.unauthorized
import
Unauthorized
return
Unauthorized
def
_makeOne
(
self
,
*
args
,
**
kw
):
return
self
.
_getTargetClass
()(
*
args
,
**
kw
)
def
test_interfaces
(
self
):
from
zope.security.interfaces
import
IUnauthorized
verifyClass
(
IUnauthorized
,
self
.
_getTargetClass
())
def
test_empty
(
self
):
exc
=
self
.
_makeOne
()
self
.
assertEqual
(
exc
.
name
,
None
)
self
.
assertEqual
(
exc
.
message
,
None
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertEqual
(
str
(
exc
),
str
(
repr
(
exc
)))
self
.
assertEqual
(
unicode
(
exc
),
unicode
(
repr
(
exc
)))
def
test_ascii_message
(
self
):
arg
=
'ERROR MESSAGE'
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
None
)
self
.
assertEqual
(
exc
.
message
,
arg
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertEqual
(
str
(
exc
),
arg
)
self
.
assertEqual
(
unicode
(
exc
),
arg
.
decode
(
'ascii'
))
def
test_encoded_message
(
self
):
arg
=
u'ERROR MESSAGE
\
u03A9
'
.
encode
(
'utf-8'
)
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
None
)
self
.
assertEqual
(
exc
.
message
,
arg
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertEqual
(
str
(
exc
),
arg
)
self
.
assertRaises
(
UnicodeDecodeError
,
unicode
,
exc
)
def
test_unicode_message
(
self
):
arg
=
u'ERROR MESSAGE
\
u03A9
'
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
None
)
self
.
assertEqual
(
exc
.
message
,
arg
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertRaises
(
UnicodeEncodeError
,
str
,
exc
)
self
.
assertEqual
(
unicode
(
exc
),
arg
)
def
test_ascii_name
(
self
):
arg
=
'ERROR_NAME'
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
arg
)
self
.
assertEqual
(
exc
.
message
,
None
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertEqual
(
str
(
exc
),
_MESSAGE
%
arg
)
self
.
assertEqual
(
unicode
(
exc
),
_MESSAGE
%
arg
.
decode
(
'ascii'
))
def
test_encoded_name
(
self
):
arg
=
u'ERROR_NAME_
\
u03A9
'
.
encode
(
'utf-8'
)
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
arg
)
self
.
assertEqual
(
exc
.
message
,
None
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertEqual
(
str
(
exc
),
_MESSAGE
%
arg
)
self
.
assertRaises
(
UnicodeDecodeError
,
unicode
,
exc
)
def
test_unicode_name
(
self
):
arg
=
u'ERROR_NAME_
\
u03A9
'
exc
=
self
.
_makeOne
(
arg
)
self
.
assertEqual
(
exc
.
name
,
arg
)
self
.
assertEqual
(
exc
.
message
,
None
)
self
.
assertEqual
(
exc
.
value
,
None
)
self
.
assertEqual
(
exc
.
needed
,
None
)
self
.
assertRaises
(
UnicodeEncodeError
,
str
,
exc
)
self
.
assertEqual
(
unicode
(
exc
),
_MESSAGE
%
arg
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UnauthorizedTests
))
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
src/zExceptions/unauthorized.py
View file @
aa6b8b78
...
...
@@ -7,17 +7,17 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
# FOR A PARTICULAR PURPOSE
.
#
##############################################################################
"""
$Id$
"""
from
types
import
StringType
from
zope.interface
import
implements
from
zope.security.interfaces
import
IUnauthorized
class
Unauthorized
(
Exception
):
"""Some user wasn't allowed to access a resource
"""
...
...
@@ -43,7 +43,7 @@ class Unauthorized(Exception):
provides are added to needed.
"""
if
name
is
None
and
(
not
isinstance
(
message
,
StringType
)
or
len
(
message
.
split
())
<=
1
):
not
isinstance
(
message
,
basestring
)
or
len
(
message
.
split
())
<=
1
):
# First arg is a name, not a message
name
=
message
message
=
None
...
...
@@ -59,7 +59,8 @@ class Unauthorized(Exception):
self
.
needed
=
needed
def
__str__
(
self
):
if
self
.
message
is
not
None
:
return
self
.
message
if
self
.
message
is
not
None
:
return
self
.
message
if
self
.
name
is
not
None
:
return
(
"You are not allowed to access '%s' in this context"
%
self
.
name
)
...
...
@@ -68,6 +69,11 @@ class Unauthorized(Exception):
%
self
.
getValueName
())
return
repr
(
self
)
def
__unicode__
(
self
):
result
=
self
.
__str__
()
if
isinstance
(
result
,
unicode
):
return
result
return
unicode
(
result
,
'ascii'
)
# override sys.getdefaultencoding()
def
getValueName
(
self
):
v
=
self
.
value
...
...
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