[CalendarServer-changes] [10626] CalendarServer/branches/users/glyph/digest-auth-redux
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 1 15:53:18 PST 2013
Revision: 10626
http://trac.calendarserver.org//changeset/10626
Author: glyph at apple.com
Date: 2013-02-01 15:53:18 -0800 (Fri, 01 Feb 2013)
Log Message:
-----------
Refactor http auth deterministicifying logic into a function.
Modified Paths:
--------------
CalendarServer/branches/users/glyph/digest-auth-redux/twext/web2/test/test_httpauth.py
Property Changed:
----------------
CalendarServer/branches/users/glyph/digest-auth-redux/
Modified: CalendarServer/branches/users/glyph/digest-auth-redux/twext/web2/test/test_httpauth.py
===================================================================
--- CalendarServer/branches/users/glyph/digest-auth-redux/twext/web2/test/test_httpauth.py 2013-02-01 23:53:17 UTC (rev 10625)
+++ CalendarServer/branches/users/glyph/digest-auth-redux/twext/web2/test/test_httpauth.py 2013-02-01 23:53:18 UTC (rev 10626)
@@ -16,6 +16,39 @@
_trivial_GET = SimpleRequest(None, 'GET', '/')
+
+def makeDigestDeterministic(twistedDigestFactory, key="0",
+ nonce='178288758716122392881254770685', time=0):
+ """
+ Patch up various bits of private state to make a digest credential factory
+ (the one that comes from Twisted) behave deterministically.
+ """
+
+ def _fakeStaticNonce():
+ """
+ Generate a static nonce
+ """
+ return nonce
+
+ def _fakeStaticTime():
+ """
+ Return a stable time
+ """
+ return time
+
+ twistedDigestFactory.privateKey = key
+
+ # FIXME: These tests are somewhat redundant with the tests for Twisted's
+ # built-in digest auth; these private values need to be patched to
+ # create deterministic results, but at some future point the whole
+ # digest module should be removed from twext.web2 (as all of twext.web2
+ # should be removed) and we can just get rid of this.
+
+ twistedDigestFactory._generateNonce = _fakeStaticNonce
+ twistedDigestFactory._getTime = _fakeStaticTime
+
+
+
class FakeDigestCredentialFactory(digest.DigestCredentialFactory):
"""
A Fake Digest Credential Factory that generates a predictable
@@ -24,33 +57,12 @@
def __init__(self, *args, **kwargs):
super(FakeDigestCredentialFactory, self).__init__(*args, **kwargs)
- self._real.privateKey = self._fakeStaticPrivateKey
+ makeDigestDeterministic(self._real, self._fakeStaticPrivateKey)
- # FIXME: These tests are somewhat redundant with the tests for Twisted's
- # built-in digest auth; these private values need to be patched to
- # create deterministic results, but at some future point the whole
- # digest module should be removed from twext.web2 (as all of twext.web2
- # should be removed) and we can just get rid of this.
-
- self._real._generateNonce = self._fakeStaticNonce
- self._real._getTime = self._fakeStaticTime
-
-
_fakeStaticPrivateKey = "0"
- def _fakeStaticNonce(self):
- """
- Generate a static nonce
- """
- return '178288758716122392881254770685'
- def _fakeStaticTime(self):
- """
- Return a stable time
- """
- return 0
-
class BasicAuthTestCase(unittest.TestCase):
def setUp(self):
self.credentialFactory = basic.BasicCredentialFactory('foo')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130201/89b08246/attachment.html>
More information about the calendarserver-changes
mailing list