Example #1
0
 def testRotateTwice(self):
     ring=Keyring()
     ring.rotate()
     ring.rotate()
     self.assertTrue(ring.data[0] is not None)
     self.assertTrue(ring.data[1] is not None)
     self.assertEqual(ring.data[2:], [ None, None, None])
Example #2
0
 def testRotateTwice(self):
     ring = Keyring()
     ring.rotate()
     ring.rotate()
     self.failUnless(ring.data[0] is not None)
     self.failUnless(ring.data[1] is not None)
     self.assertEqual(ring.data[2:], [None, None, None])
Example #3
0
def upgrade_keyring(context):
    logger.info('upgrading keyring')
    manager = getUtility(IKeyManager)

    manager[u'_system'].fill()

    if u'_anon' not in manager:
        manager[u'_anon'] = Keyring()
    manager[u'_anon'].fill()

    if u'_forms' not in manager:
        manager[u'_forms'] = Keyring()
    manager[u'_forms'].fill()

    logger.info('add keyring to zope root if not done already')
    app = aq_parent(getSite())
    sm = getSiteManager(app)

    if sm.queryUtility(IKeyManager) is None:
        obj = KeyManager()
        sm.registerUtility(aq_base(obj), IKeyManager, '')

    # disable CSRF protection which will fail due to
    # using different secrets than when the authenticator
    # was generated
    request = getRequest()
    if request is not None:
        alsoProvides(request, IDisableCSRFProtection)
Example #4
0
 def setUp(self):
     self.mgr = KeyManager()
     del self.mgr[u"_system"]
     self.mgr[u"_system"] = Keyring()
     self.mgr[u"_system"].rotate()
     self.mgr[u"one"] = Keyring()
     self.mgr[u"one"].rotate()
     self.mgr[u"two"] = Keyring()
     self.mgr[u"two"].rotate()
Example #5
0
    def __init__(self, keyring_size=5):
        SampleContainer.__init__(self)

        if keyring_size < 1:
            keyring_size = 5  # prevent not having any keys

        self[u"_system"] = Keyring(keyring_size)
        self[u"_system"].fill()

        # to be used with anonymous users
        self[u'_anon'] = Keyring(keyring_size)
        self[u'_anon'].fill()

        # to be used with forms, plone.protect here..
        self[u'_forms'] = Keyring(keyring_size)
        self[u'_forms'].fill()
Example #6
0
def upgrade_keyring(context):
    logger.info('upgrading keyring')
    manager = getUtility(IKeyManager)

    manager[u'_system'].fill()

    if u'_anon' not in manager:
        manager[u'_anon'] = Keyring()
    manager[u'_anon'].fill()

    if u'_forms' not in manager:
        manager[u'_forms'] = Keyring()
    manager[u'_forms'].fill()

    logger.info('add keyring to zope root if not done already')
    app = aq_parent(getSite())
    sm = getSiteManager(app)

    if sm.queryUtility(IKeyManager) is None:
        obj = KeyManager()
        sm.registerUtility(aq_base(obj), IKeyManager, '')
Example #7
0
 def testCurrent(self):
     ring = Keyring()
     marker = []
     ring.data = [marker, 1, 2, 3]
     self.failUnless(ring.current is marker)
Example #8
0
 def testClear(self):
     ring = Keyring()
     ring.data = [0, 1, 2]
     ring.clear()
     self.assertEqual(ring.data, [None, None, None])
Example #9
0
 def testRotate(self):
     ring = Keyring()
     ring.rotate()
     self.failIf(ring.current is None)
     self.assertEqual(ring.data[1:], [None, None, None, None])
Example #10
0
 def testKeyringStartsEmpty(self):
     ring = Keyring()
     self.assertEqual(set(list(ring)), set([None]))
Example #11
0
 def testIterate(self):
     ring = Keyring()
     ring.data = [0, 1, 2, 3, 4]
     iterator = ring.__iter__()
     self.failUnless(isinstance(iterator, types.GeneratorType))
     self.assertEqual(list(iterator), [0, 1, 2, 3, 4])
Example #12
0
 def testConstructionDefaultSize(self):
     ring = Keyring()
     self.assertEqual(len(ring), 5)
Example #13
0
 def testConstructionSize(self):
     ring = Keyring(3)
     self.assertEqual(len(ring), 3)
Example #14
0
 def testCurrent(self):
     ring=Keyring()
     marker=[]
     ring.data=[marker, 1, 2, 3]
     self.failUnless(ring.current is marker)
Example #15
0
 def testCurrent(self):
     ring=Keyring()
     marker=[]
     ring.data=[marker, 1, 2, 3]
     self.assertTrue(ring.current is marker)
Example #16
0
 def testIterate(self):
     ring=Keyring()
     ring.data=[0, 1, 2, 3, 4]
     iterator=ring.__iter__()
     self.assertTrue(isinstance(iterator, types.GeneratorType))
     self.assertEqual(list(iterator), [0, 1, 2, 3, 4])
Example #17
0
 def testRotate(self):
     ring=Keyring()
     ring.rotate()
     self.assertFalse(ring.current is None)
     self.assertEqual(ring.data[1:], [ None, None, None, None])
Example #18
0
 def testClear(self):
     ring=Keyring()
     ring.data=[0, 1, 2]
     ring.clear()
     self.assertEqual(ring.data, [ None, None, None ])