Skip to content

Commit

Permalink
Merge pull request learningequality#3496 from jamalex/fix_the_evil_bu…
Browse files Browse the repository at this point in the history
…g_that_spoke_softly_and_carried_a_big_stick

Fixes learningequality#2470: "Cant register because Client device must be self-signed with a signature matching its own public key"
  • Loading branch information
jamalex committed Apr 9, 2015
2 parents 7f97ffc + d1d5e02 commit 71f1477
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kalite/facility/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FacilityGroup(DeferredCountSyncedModel):

def __init__(self, *args, **kwargs):
super(FacilityGroup, self).__init__(*args, **kwargs)
self._unhashable_fields.append("description") # since it's being stripped out by minversion, we can't include it in the signature
self._unhashable_fields += ("description",) # since it's being stripped out by minversion, we can't include it in the signature

class Meta:
app_label = "securesync" # for back-compat reasons
Expand Down
7 changes: 3 additions & 4 deletions python-packages/securesync/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ class SyncedModel(ExtendedModel):
objects = SyncedModelManager()
all_objects = SyncedModelManager(show_deleted=True)

_unhashable_fields = ["signature", "signed_by"] # fields of this class to avoid serializing
_always_hash_fields = ["signed_version", "id"] # fields of this class to always serialize (see note above for signed_version)
_import_excluded_validation_fields = [] # fields that should not be validated upon import

_unhashable_fields = ("signature", "signed_by") # fields of this class to avoid serializing
_always_hash_fields = ("signed_version", "id") # fields of this class to always serialize (see note above for signed_version)
_import_excluded_validation_fields = tuple() # fields that should not be validated upon import

__metaclass__ = SyncedModelMetaclass

Expand Down
15 changes: 15 additions & 0 deletions python-packages/securesync/tests/crypto_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,18 @@ def test_facility_group_save(self):
group.save()
assert group.zone_fallback is not None, "Centrally created FacilityGroup was not assigned a zone."


class TestHashableFieldsAndSerialization(unittest.TestCase):

def test_description_exclusion_regression_bug_2470(self):
"""FacilityGroup.__init__ used to append "description" to _unhashable_fields, which affected other classes as well.
This test ensures that the description is not being excluded from Device._hashable_representation, even after
instantiating a FacilityGroup."""

d = Device(name="Test", description="Test")
possibly_bad_serialization = d._hashable_representation()
self.assertIn("description=Test", possibly_bad_serialization, "Hashable representation of Device did not include description")

g = FacilityGroup()
possibly_worse_serialization = d._hashable_representation()
self.assertIn("description=Test", possibly_worse_serialization, "Instantiating a FacilityGroup changed hashable representation of Device")

0 comments on commit 71f1477

Please sign in to comment.