コード例 #1
0
 def test_disablePowerTokens(self):
     token1 = self.utility.enablePowerToken(self.doc, 'foo')
     token2 = self.utility.enablePowerToken(self.doc, 'foo')
     self.assertTrue(IPowerTokenizedContent.providedBy(self.doc))
     self.utility.disablePowerTokens(self.doc)
     self.assertFalse(IPowerTokenizedContent.providedBy(self.doc))
     self.assertRaises(PowerTokenConfigurationError, self.utility.verifyToken, self.doc, token1, False)
     self.assertRaises(PowerTokenConfigurationError, self.utility.verifyToken, self.doc, token2, False)
     self.assertEqual(IAnnotations(self.doc).get(config.MAIN_TOKEN_NAME), None)
コード例 #2
0
    def verifyToken(self, content, token, raiseOnError=True):
        if not IPowerTokenizedContent.providedBy(content):
            raise PowerTokenConfigurationError("Content %s isn't an IPowerTokenizedContent" % '/'.join(content.getPhysicalPath()))
        annotations = IAnnotations(content)
        try:
            powertokens = annotations[config.MAIN_TOKEN_NAME]
        except KeyError:
            raise KeyError("Content %s doesn't provide tokens" % '/'.join(content.getPhysicalPath()))

        if not token or powertokens.get(token) is None:
            if raiseOnError:
                raise PowerTokenSecurityError('Token verification failed')
            return False
        return True
コード例 #3
0
    def verifyToken(self, content, token, raiseOnError=True):
        if not IPowerTokenizedContent.providedBy(content):
            raise PowerTokenConfigurationError(
                "Content %s isn't an IPowerTokenizedContent" %
                '/'.join(content.getPhysicalPath()))
        annotations = IAnnotations(content)
        try:
            powertokens = annotations[config.MAIN_TOKEN_NAME]
        except KeyError:
            raise KeyError("Content %s doesn't provide tokens" %
                           '/'.join(content.getPhysicalPath()))

        if not token or powertokens.get(token) is None:
            if raiseOnError:
                raise PowerTokenSecurityError('Token verification failed')
            return False
        return True
コード例 #4
0
 def test_enablePowerToken(self):
     token = self.utility.enablePowerToken(self.doc, 'foo')
     configuration = IAnnotations(self.doc)[config.MAIN_TOKEN_NAME]
     self.assertTrue(IPowerTokenizedContent.providedBy(self.doc))
     self.assertEquals(configuration.keys()[0], token)