Beispiel #1
0
    def testStale(self):
        # is a file with mtime older than max_staleness considered stale?

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        time.sleep(2)  # thanks for waiting :)
        uid2 = filesys.fuid(self.fname, max_staleness=1)
        assert uid2 != uid1  # should be considered stale if platform has no inode support
    def testUpdateFileInPlace(self):
        # update file in place, changing size and maybe mtime
        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.fname, "foofoo")
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1 # we changed size and maybe mtime
Beispiel #3
0
    def testStale(self):
        # is a file with mtime older than max_staleness considered stale?

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        time.sleep(2)  # thanks for waiting :)
        uid2 = filesys.fuid(self.fname, max_staleness=1)
        assert uid2 != uid1  # should be considered stale if platform has no inode support
Beispiel #4
0
    def testUpdateFileInPlace(self):
        # update file in place, changing size and maybe mtime
        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.fname, "foofoo")
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1  # we changed size and maybe mtime
    def testStale(self):
        # is a file with mtime older than max_staleness considered stale?
        if sys.platform != 'win32':
            py.test.skip("max_staleness check only done on win32 because it doesn't support inode change detection")

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        time.sleep(2) # thanks for waiting :)
        uid2 = filesys.fuid(self.fname, max_staleness=1)
        assert uid2 != uid1  # should be considered stale if platform has no inode support
    def testStale(self):
        # is a file with mtime older than max_staleness considered stale?
        if sys.platform != 'win32':
            py.test.skip("max_staleness check only done on win32 because it doesn't support inode change detection")

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        time.sleep(2) # thanks for waiting :)
        uid2 = filesys.fuid(self.fname, max_staleness=1)
        assert uid2 != uid1  # should be considered stale if platform has no inode support
Beispiel #7
0
    def testUpdateFileMovingFromTemp(self):
        # update file by moving another file over it
        # changing inode, maybe mtime, but not size

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.tmpname, "bar")
        os.rename(self.tmpname, self.fname)
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1  # we didn't change size, but inode and maybe mtime
Beispiel #8
0
    def testUpdateFileMovingFromTemp(self):
        # update file by moving another file over it
        # changing inode, maybe mtime, but not size

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.tmpname, "bar")
        os.rename(self.tmpname, self.fname)
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1  # we didn't change size, but inode and maybe mtime
    def testUpdateFileMovingFromTemp(self):
        # update file by moving another file over it
        # changing inode, maybe mtime, but not size
        if sys.platform == 'win32':
            py.test.skip("Inode change detection not supported on win32")

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.tmpname, "bar")
        os.rename(self.tmpname, self.fname)
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1 # we didn't change size, but inode and maybe mtime
    def testUpdateFileMovingFromTemp(self):
        # update file by moving another file over it (see caching.update)
        # changing inode, maybe mtime, but not size
        if sys.platform == 'win32':
            py.test.skip("Inode change detection not supported on win32")

        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        self.makefile(self.tmpname, "bar")
        os.rename(self.tmpname, self.fname)
        uid2 = filesys.fuid(self.fname)

        assert uid2 != uid1 # we didn't change size, but inode and maybe mtime
Beispiel #11
0
def key(request,
        wikiname=None,
        itemname=None,
        attachname=None,
        content=None,
        secret=None):
    """
    Calculate a (hard-to-guess) cache key.

    Important key properties:
    * The key must be hard to guess (this is because do=get does no ACL checks,
      so whoever got the key [e.g. from html rendering of an ACL protected wiki
      page], will be able to see the cached content.
    * The key must change if the (original) content changes. This is because
      ACLs on some item may change and even if somebody was allowed to see some
      revision of some item, it does not implicate that he is allowed to see
      any other revision also. There will be no harm if he can see exactly the
      same content again, but there could be harm if he could access a revision
      with different content.

    If content is supplied, we will calculate and return a hMAC of the content.

    If wikiname, itemname, attachname is given, we don't touch the content (nor do
    we read it ourselves from the attachment file), but we just calculate a key
    from the given metadata values and some metadata we get from the filesystem.

    Hint: if you need multiple cache objects for the same source content (e.g.
          thumbnails of different sizes for the same image), calculate the key
          only once and then add some different prefixes to it to get the final
          cache keys.

    @param request: the request object
    @param wikiname: the name of the wiki (if not given, will be read from cfg)
    @param itemname: the name of the page
    @param attachname: the filename of the attachment
    @param content: content data as unicode object (e.g. for page content or
                    parser section content)
    @param secret: secret for hMAC calculation (default: use secret from cfg)
    """
    if secret is None:
        secret = request.cfg.secrets['action/cache']
    if content:
        hmac_data = content
    elif itemname is not None and attachname is not None:
        wikiname = wikiname or request.cfg.interwikiname or request.cfg.siteid
        fuid = filesys.fuid(
            AttachFile.getFilename(request, itemname, attachname))
        hmac_data = u''.join([wikiname, itemname, attachname, repr(fuid)])
    else:
        raise AssertionError('cache_key called with unsupported parameters')

    hmac_data = hmac_data.encode('utf-8')
    key = hmac.new(secret, hmac_data).hexdigest()
    return key
Beispiel #12
0
def key(request, wikiname=None, itemname=None, attachname=None, content=None, secret=None):
    """
    Calculate a (hard-to-guess) cache key.

    Important key properties:
    * The key must be hard to guess (this is because do=get does no ACL checks,
      so whoever got the key [e.g. from html rendering of an ACL protected wiki
      page], will be able to see the cached content.
    * The key must change if the (original) content changes. This is because
      ACLs on some item may change and even if somebody was allowed to see some
      revision of some item, it does not implicate that he is allowed to see
      any other revision also. There will be no harm if he can see exactly the
      same content again, but there could be harm if he could access a revision
      with different content.

    If content is supplied, we will calculate and return a hMAC of the content.

    If wikiname, itemname, attachname is given, we don't touch the content (nor do
    we read it ourselves from the attachment file), but we just calculate a key
    from the given metadata values and some metadata we get from the filesystem.

    Hint: if you need multiple cache objects for the same source content (e.g.
          thumbnails of different sizes for the same image), calculate the key
          only once and then add some different prefixes to it to get the final
          cache keys.

    @param request: the request object
    @param wikiname: the name of the wiki (if not given, will be read from cfg)
    @param itemname: the name of the page
    @param attachname: the filename of the attachment
    @param content: content data as unicode object (e.g. for page content or
                    parser section content)
    @param secret: secret for hMAC calculation (default: use secret from cfg)
    """
    if secret is None:
        secret = request.cfg.secrets["action/cache"]
    if content:
        hmac_data = content
    elif itemname is not None and attachname is not None:
        wikiname = wikiname or request.cfg.interwikiname or request.cfg.siteid
        fuid = filesys.fuid(AttachFile.getFilename(request, itemname, attachname))
        hmac_data = u"".join([wikiname, itemname, attachname, repr(fuid)])
    else:
        raise AssertionError("cache_key called with unsupported parameters")

    hmac_data = hmac_data.encode("utf-8")
    key = hmac_new(secret, hmac_data).hexdigest()
    return key
Beispiel #13
0
    def testNewFile(self):
        # freshly created file
        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        assert uid1 is not None  # None would mean some failure in fuid()
Beispiel #14
0
    def testNoFile(self):
        # no file created
        uid = filesys.fuid(self.fname)

        assert uid is None  # there is no file yet, fuid will fail internally and return None
Beispiel #15
0
    def uid(self):
        """ Return a value that likely changes when the on-disk cache was updated.

            See docstring of MoinMoin.util.filesys.fuid for details.
        """
        return filesys.fuid(self._fname)
    def testNewFile(self):
        # freshly created file
        self.makefile(self.fname, "foo")
        uid1 = filesys.fuid(self.fname)

        assert uid1 is not None  # None would mean some failure in fuid()
    def testNoFile(self):
        # no file created
        uid = filesys.fuid(self.fname)

        assert uid is None  # there is no file yet, fuid will fail internally and return None
Beispiel #18
0
    def uid(self):
        """ Return a value that likely changes when the on-disk cache was updated.

            See docstring of MoinMoin.util.filesys.fuid for details.
        """
        return filesys.fuid(self._fname)