为Zope3设置信任层
项目描述
本软件包为Zope3提供信任层设置。信任意味着您可以遍历那些您没有权限的对象。如果您有一个具有多个IAuthentication实用工具的设置,则需要此功能。否则,您将无法在没有在父IAuthentication中进行身份验证的情况下遍历子站点的IAthentication实用工具。
README
本软件包包含信任层。此层支持正确的组件注册,可用于自定义皮肤的继承。
ITrustedBrowserLayer支持与IMinimalBrowserLayer相同的注册集。唯一的区别是,信任层提供了信任遍历适配器。这意味着使用此层的皮肤可以遍历PAU(可插拔IAuthentication实用工具)而不会遇到未经授权的异常。
有关更多信息,请参阅z3c.layer.minimal中的README.txt。
测试
为了测试ITrustedBrowserLayer,我们使用了在测试包中定义的测试皮肤,它使用ITrustedBrowserLayer。这意味着我们的测试皮肤还提供了在minimal软件包中定义的视图以及在minimal测试中定义的测试视图。
首先以管理员的身份登录
>>> from zope.testbrowser.testing import Browser >>> manager = Browser() >>> manager.addHeader('Authorization', 'Basic mgr:mgrpw')
检查我们是否可以使用我们的皮肤访问在ftesting.zcml文件中注册的public page.html视图
>>> skinURL = 'https://127.0.0.1/++skin++TrustedTesting' >>> manager.open(skinURL + '/page.html') >>> manager.url 'https://127.0.0.1/++skin++TrustedTesting/page.html'>>> print manager.contents <BLANKLINE> <html> <head> <title>testing</title> </head> <body> <BLANKLINE> test page <BLANKLINE> </body> </html> <BLANKLINE> <BLANKLINE>
现在检查未找到页面,它是在zope.publisher.interfaces.INotFound异常上的异常视图
>>> manager.open(skinURL + '/foobar.html') Traceback (most recent call last): ... HTTPError: HTTP Error 404: Not Found>>> print manager.contents <BLANKLINE> <html> <head> <title>testing</title> </head> <body> <div> <br /> <br /> <h3> The page you are trying to access is not available </h3> <br /> <b> Please try the following: </b> <br /> <ol> <li> Make sure that the Web site address is spelled correctly. </li> <li> <a href="javascript:history.back(1);"> Go back and try another URL. </a> </li> </ol> </div> </body> </html> <BLANKLINE> <BLANKLINE>
并检查用户错误页面,它是注册用于zope.exceptions.interfaces.IUserError异常的视图
>>> manager.open(skinURL + '/@@usererror.html') >>> print manager.contents <BLANKLINE> <html> <head> <title>testing</title> </head> <body> <div> <div>simply user error</div> </div> </body> </html> <BLANKLINE> <BLANKLINE>
并检查注册的异常视图 zope.interface.common.interfaces.IException
>>> manager.open(skinURL + '/@@systemerror.html') >>> print manager.contents <BLANKLINE> <html> <head> <title>testing</title> </head> <body> <div> <br /> <br /> <h3>A system error occurred</h3> <br /> <b>Please contact the administrator.</b> <a href="javascript:history.back(1);"> Go back and try another URL. </a> </div> </body> </html> <BLANKLINE> <BLANKLINE>
并检查 zope.security.interfaces.IUnauthorized 视图,为此使用一个新注册的用户(测试浏览器)
>>> unauthorized = Browser() >>> unauthorized.open(skinURL + '/@@forbidden.html') Traceback (most recent call last): ... HTTPError: HTTP Error 401: Unauthorized>>> print unauthorized.contents <BLANKLINE> <html> <head> <title>testing</title> </head> <body> <div> <BLANKLINE> <h1>Unauthorized</h1> <BLANKLINE> <p>You are not authorized</p> <BLANKLINE> </div> </body> </html> <BLANKLINE> <BLANKLINE>
当一个对象被遍历时,其安全代理被移除,因此其子对象也可以公开访问
>>> import zope.site.folder >>> getRootFolder()['test'] = zope.site.folder.Folder() >>> manager.open(skinURL + '/container_contents.html')
视图显示根文件夹内部内容对象的类型。内容对象没有被安全代理
>>> print manager.contents [<class 'zope.site.folder.Folder'>]
CHANGES
1.1.0 (2009-02-21)
Doctests 显示从遍历的对象中移除安全代理是期望的行为。
使用 zope.container 而不是 zope.app.container。
确保在 pypi 上正确渲染 long_description。
清理了依赖关系。
1.0.1 (2008-01-24)
错误:纠正并改进了元数据和文档。
1.0.0 (2008-01-21)
重构:将 z3c.layer.trusted 包从 zope.layer 移动到它自己的顶级包 z3c.layer.trusted。
错误:反映 zope.app.securitypolicy ZCML 配置中的更改。防止加载过时的模块配置。
重构:将实现从 z3c.layer 移动到 z3c.layer.trusted。
0.2.3 (2007-11-07)
前向错误:由于 mechanize 中的错误,testbrowser 抛出 httperror_seek_wrapper 而不是 HTTPError 错误。多亏了 RE 正则化器,代码现在将正常工作,无论该错误是否在 mechanize 中修复。
0.2.2 (2007-10-31)
错误:修复了包元数据。
错误:修复了由于依赖项更新导致的测试失败。
重构:修复了对 ZopeSecurityPolicy 的弃用警告。
0.2.1 (2007-??-??)
更改未知。
0.2.0 (2007-??-??)
初始版本。
项目详情
z3c.layer.trusted-1.1.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | e9ce5e6f3a4407f5c6f4389a682ef0bf347adeee110e3ef7c2a94783fe688b79 |
|
MD5 | 03d59bdf95d9e4da54cd06414fc8e9d3 |
|
BLAKE2b-256 | 617dd585ab9eae65c44ff061ed2351a90e677dfdaf078aa77ec6dbf1c054d289 |