Skip to content

Commit 3383088

Browse files
author
Kevin Turner
committed
[project @ association.Association.__init__: set .sign_all according to assoc_type]
and it turns out that objects with attributes which are functions or methods assigned after the object was created do not deepcopy so well.
1 parent efe02df commit 3383088

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎openid/association.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
'HMAC-SHA256-SIGNALL',
1818
]
1919

20+
signall_association_types = [
21+
'HMAC-SHA1-SIGNALL',
22+
'HMAC-SHA256-SIGNALL',
23+
]
24+
2025
if hasattr(cryptutil, 'hmacSha256'):
2126
supported_association_types = list(all_association_types)
2227

@@ -277,7 +282,7 @@ def __init__(self, handle, secret, issued, lifetime, assoc_type):
277282
self.issued = issued
278283
self.lifetime = lifetime
279284
self.assoc_type = assoc_type
280-
self.sign_all = False
285+
self.sign_all = assoc_type in signall_association_types
281286

282287
def getExpiresIn(self, now=None):
283288
"""
@@ -451,6 +456,16 @@ def checkMessageSignature(self, message):
451456
return calculated_sig == message_sig
452457

453458

459+
def _makePairs(self, message):
460+
# Feels a bit kludgy to dispatch here instead of of letting the class
461+
# have the method appropriately defined, but this seemed to be the
462+
# least complicated alternative at the time.
463+
if self.sign_all:
464+
return self._makePairsSignAll(message)
465+
else:
466+
return self._makePairsSignedList(message)
467+
468+
454469
def _makePairsSignAll(self, message):
455470
pairs = message.toPostArgs().items()
456471
pairs.sort()
@@ -468,5 +483,3 @@ def _makePairsSignedList(self, message):
468483
for field in signed_list:
469484
pairs.append((field, data.get('openid.' + field, '')))
470485
return pairs
471-
472-
_makePairs = _makePairsSignedList

‎openid/test/test_association.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ def testMakePairsSignAll(self):
110110
self.failUnlessEqual(pairs, expected)
111111

112112

113+
114+
class TestIsSignAll(unittest.TestCase):
115+
def test_sha1(self):
116+
self.assoc = association.Association.fromExpiresIn(
117+
3600, '{sha1}', 'very_secret', "HMAC-SHA1")
118+
self.failUnlessEqual(self.assoc.sign_all, False)
119+
120+
121+
def test_sha1signAll(self):
122+
self.assoc = association.Association.fromExpiresIn(
123+
3600, '{sha1-sa}', 'very_secret', "HMAC-SHA1-SIGNALL")
124+
self.failUnlessEqual(self.assoc.sign_all, True)
125+
126+
127+
113128
def pyUnitTests():
114129
return datadriven.loadTests(__name__)
115130

0 commit comments

Comments
 (0)