[Checkins] SVN: grok/trunk/src/grok/ftest group based ftests

Christian Klinger cklinger at novareto.de
Thu Nov 4 11:26:25 EDT 2010


Log message for revision 118206:
  group based ftests

Changed:
  U   grok/trunk/src/grok/ftesting.zcml
  A   grok/trunk/src/grok/ftests/security/groups.py

-=-
Modified: grok/trunk/src/grok/ftesting.zcml
===================================================================
--- grok/trunk/src/grok/ftesting.zcml	2010-11-04 13:52:16 UTC (rev 118205)
+++ grok/trunk/src/grok/ftesting.zcml	2010-11-04 15:26:25 UTC (rev 118206)
@@ -5,6 +5,11 @@
    i18n_domain="grok"
    package="grok">
 
+  <include package="zope.security" file="meta.zcml"/>
+
+  <permission title="grok.test"
+              id="grok.test"/>
+
   <include package="grok" />
   <grok:grok package="grok.ftests" />
 
@@ -14,11 +19,21 @@
       component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
       />
 
-  <unauthenticatedPrincipal
-      id="zope.anybody"
-      title="Unauthenticated User"
-      />
+
+  <unauthenticatedPrincipal id="zope.anybody"
+                            title="Unauthenticated User" />
+  <unauthenticatedGroup id="zope.Anybody"
+                        title="Unauthenticated Users" />
+  <authenticatedGroup id="zope.Authenticated"
+                      title="Authenticated Users" />
+  <everybodyGroup id="zope.Everybody"
+                  title="All Users" />
+
   <grant
+      permission="grok.test"
+      principal="zope.Authenticated"/>
+
+  <grant
       permission="zope.View"
       principal="zope.anybody"
       />
@@ -30,8 +45,14 @@
       password="mgrpw"
       />
 
+  <principal
+      id="sample.user"
+      title="foo"
+      login="foo"
+      password="secret"
+      />
+
   <role id="zope.Manager" title="Site Manager" />
   <grantAll role="zope.Manager" />
   <grant role="zope.Manager" principal="zope.mgr" />
-
 </configure>

Added: grok/trunk/src/grok/ftests/security/groups.py
===================================================================
--- grok/trunk/src/grok/ftests/security/groups.py	                        (rev 0)
+++ grok/trunk/src/grok/ftests/security/groups.py	2010-11-04 15:26:25 UTC (rev 118206)
@@ -0,0 +1,69 @@
+"""
+Default Group Behaviour
+-----------------------
+
+Grok provides a default security policy.
+Here we proofe that the basic stuff will work
+as expected.
+
+Note we defined the user and the permission in the ftesting.zcml
+
+  >>> from zope.app.wsgi.testlayer import Browser
+  >>> browser = Browser()
+
+If we try to acces a public site without authentication
+we will get the following goups 'zope.Anybody' and 'zope
+Everybody'
+
+  >>> browser.open("http://localhost/@@publicview")
+  >>> 'zope.Anybody' in browser.contents
+  True
+  >>> 'zope.Everybody' in browser.contents
+  True
+
+If we try to acces a protect view by an anonyoums user
+we will get an Unauthorized Message.
+
+  >>> browser.open("http://localhost/@@protectedview")
+  Traceback (most recent call last):
+  ...
+  HTTPError: HTTP Error 401: Unauthorized
+
+If access the view with an authenticated request we should
+get the groups zope.Authenticated.
+
+  >>> browser.addHeader('Authorization', 'Basic foo:secret')
+  >>> browser.open("http://localhost/@@publicview")
+  >>> 'zope.Authenticated' in browser.contents
+  True
+
+And of course you can access the protected view.
+
+  >>> browser.open("http://localhost/@@protectedview")
+  >>> 'zope.Authenticated' in browser.contents
+  True
+"""
+
+import grok
+import zope.interface
+from zope.component import queryUtility
+from zope.pluggableauth.interfaces import IPrincipalCreated
+from zope.security.interfaces import IGroup, IGroupAwarePrincipal
+from zope.authentication.interfaces import IAuthenticatedGroup, IEveryoneGroup
+
+
+class PublicView(grok.View):
+
+    grok.context(zope.interface.Interface)
+    grok.require('zope.Public')
+
+    def render(self):
+        return ', '.join(self.request.principal.groups)
+
+
+class ProtectedView(grok.View):
+    grok.context(zope.interface.Interface)
+    grok.require('grok.test')
+
+    def render(self):
+        return ', '.join(self.request.principal.groups)



More information about the checkins mailing list