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])
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])
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)
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()
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()
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, '')
def testCurrent(self): ring = Keyring() marker = [] ring.data = [marker, 1, 2, 3] self.failUnless(ring.current is marker)
def testClear(self): ring = Keyring() ring.data = [0, 1, 2] ring.clear() self.assertEqual(ring.data, [None, None, None])
def testRotate(self): ring = Keyring() ring.rotate() self.failIf(ring.current is None) self.assertEqual(ring.data[1:], [None, None, None, None])
def testKeyringStartsEmpty(self): ring = Keyring() self.assertEqual(set(list(ring)), set([None]))
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])
def testConstructionDefaultSize(self): ring = Keyring() self.assertEqual(len(ring), 5)
def testConstructionSize(self): ring = Keyring(3) self.assertEqual(len(ring), 3)
def testCurrent(self): ring=Keyring() marker=[] ring.data=[marker, 1, 2, 3] self.failUnless(ring.current is marker)
def testCurrent(self): ring=Keyring() marker=[] ring.data=[marker, 1, 2, 3] self.assertTrue(ring.current is marker)
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])
def testRotate(self): ring=Keyring() ring.rotate() self.assertFalse(ring.current is None) self.assertEqual(ring.data[1:], [ None, None, None, None])
def testClear(self): ring=Keyring() ring.data=[0, 1, 2] ring.clear() self.assertEqual(ring.data, [ None, None, None ])