changeset 2786:a16ba90d1f7e

macro.__init__.py:GetVal bug fixed of respecting acls and test added
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Wed, 29 Aug 2007 19:46:01 +0200
parents ff1886a5defa
children 1cb372eb7935
files MoinMoin/macro/__init__.py MoinMoin/macro/_tests/test_GetVal.py
diffstat 2 files changed, 89 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/macro/__init__.py	Wed Aug 29 17:59:13 2007 +0200
+++ b/MoinMoin/macro/__init__.py	Wed Aug 29 19:46:01 2007 +0200
@@ -392,6 +392,8 @@
 
     def macro_GetVal(self, page=None, key=None):
         page = wikiutil.get_unicode(self.request, page, 'page')
+        if not self.request.user.may.read(page):
+            raise ValueError("You don't have enough rights on this page")
         key = wikiutil.get_unicode(self.request, key, 'key')
         if page is None or key is None:
             raise ValueError("You need to give: pagename, key")
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/macro/_tests/test_GetVal.py	Wed Aug 29 19:46:01 2007 +0200
@@ -0,0 +1,87 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - MoinMoin.macro GetVal tested
+
+    @copyright: 2007 MoinMoin:ReimarBauer
+
+    @license: GNU GPL, see COPYING for details.
+"""
+import os, py
+from MoinMoin import macro
+from MoinMoin.logfile import eventlog
+from MoinMoin.Page import Page
+from MoinMoin.PageEditor import PageEditor
+from MoinMoin.parser.text_moin_wiki import Parser
+
+class TestGetVal:
+    """GetVal: testing getVal macro """
+
+    def setup_class(self):
+        self.cfg = self.request.cfg
+        self.pagename = u'MyDict'
+        self.page = PageEditor(self.request, self.pagename)
+        self.shouldDeleteTestPage = False
+        # for that test eventlog needs to be empty
+        fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+        if os.path.exists(fpath):
+            os.remove(fpath)
+        # remove old pages
+        import shutil
+        page = Page(self.request, self.pagename)
+        fpath = page.getPagePath(use_underlay=0, check_create=0)
+        shutil.rmtree(fpath, True)
+
+    def teardown_class(self):
+        if self.shouldDeleteTestPage:
+            import shutil
+            page = Page(self.request, self.pagename)
+            fpath = page.getPagePath(use_underlay=0, check_create=0)
+            shutil.rmtree(fpath, True)
+
+            fpath = self.request.rootpage.getPagePath('event-log', isfile=1)
+            if os.path.exists(fpath):
+                os.remove(fpath)
+
+    def _make_macro(self):
+        """Test helper"""
+        from MoinMoin.parser.text import Parser
+        from MoinMoin.formatter.text_html import Formatter
+        p = Parser("##\n", self.request)
+        p.formatter = Formatter(self.request)
+        p.formatter.page = self.page
+        self.request.formatter = p.formatter
+        p.form = self.request.form
+        m = macro.Macro(p)
+        return m
+
+    def _test_macro(self, name, args):
+        m = self._make_macro()
+        return m.execute(name, args)
+
+    def _createTestPage(self, body):
+        """ Create temporary page """
+        assert body is not None
+        self.request.reset()
+        self.page.saveText(body, 0)
+
+    def testGetValNoACLs(self):
+        """ macro GetVal test: 'reads VAR' """
+        self.shouldDeleteTestPage = True
+        self._createTestPage(u' VAR:: This is an example')
+        args = "%s,%s" % (self.pagename, u'VAR')
+        result = self._test_macro(u'GetVal', args)
+        expected = "This is an example"
+        assert result == expected
+
+    def testGetValACLs(self):
+        py.test.skip("user has no rights to create acl pages")
+        """ macro GetVal test: 'cant read VAR on an ACL protected page' """
+        self.shouldDeleteTestPage = True
+        self._createTestPage('#acl SomeUser:read,write All:delete\n VAR:: This is an example')
+        args = "%s,%s" % (self.pagename, u'VAR')
+        result = self._test_macro(u'GetVal', args)
+        expected = "&lt;&lt;GetVal: You don't have enough rights on this page&gt;&gt;"
+        assert result == expected
+
+coverage_modules = ['MoinMoin.macro.GetVal']
+