summary refs log tree commit diff
path: root/tests/crypto/test_event_signing.py
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2015-10-19 15:00:52 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2015-10-19 15:00:52 +0100
commit07b58a431f9e0367f8c08d2bc8983473c8a0c379 (patch)
treea8cceb59925a311260bb2d1bfb3e4543e3c30523 /tests/crypto/test_event_signing.py
parentInitial minimial hack at a test of event hashing and signing (diff)
downloadsynapse-07b58a431f9e0367f8c08d2bc8983473c8a0c379.tar.xz
Another signing test vector using an 'm.room.message' with content, so that the implementation will have to redact it
Diffstat (limited to 'tests/crypto/test_event_signing.py')
-rw-r--r--tests/crypto/test_event_signing.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/tests/crypto/test_event_signing.py b/tests/crypto/test_event_signing.py
index 0b560e9317..0f487d9c7b 100644
--- a/tests/crypto/test_event_signing.py
+++ b/tests/crypto/test_event_signing.py
@@ -61,7 +61,7 @@ class EventSigningTestCase(unittest.TestCase):
         self.signing_key.alg = KEY_ALG
         self.signing_key.version = KEY_VER
 
-    def test_sign(self):
+    def test_sign_minimal(self):
         builder = self.event_builder_factory.new(
             {'type': "X"}
         )
@@ -96,3 +96,51 @@ class EventSigningTestCase(unittest.TestCase):
             "2Wptgo4CwmLo/Y8B8qinxApKaCkBG2fjTWB7AbP5Uy+"
             "aIbygsSdLOFzvdDjww8zUVKCmI02eP9xtyJxc/cLiBA",
         )
+
+    def test_sign_message(self):
+        builder = self.event_builder_factory.new(
+            {
+                'type': "m.room.message",
+                'sender': "@u:domain",
+                'room_id': "!r:domain",
+                'content': {
+                    'body': "Here is the message content",
+                },
+            }
+        )
+        self.assertEquals(
+            builder.build().get_dict(),
+            {
+                'content': {
+                    'body': "Here is the message content",
+                },
+                'event_id': "$0:domain",
+                'origin': "domain",
+                'origin_server_ts': 1000000,
+                'type': "m.room.message",
+                'room_id': "!r:domain",
+                'sender': "@u:domain",
+                'signatures': {},
+                'unsigned': {'age_ts': 1000000},
+            }
+        )
+
+        add_hashes_and_signatures(builder, HOSTNAME, self.signing_key)
+
+        event = builder.build()
+
+        self.assertTrue(hasattr(event, 'hashes'))
+        self.assertTrue('sha256' in event.hashes)
+        self.assertEquals(
+            event.hashes['sha256'],
+            "onLKD1bGljeBWQhWZ1kaP9SorVmRQNdN5aM2JYU2n/g",
+        )
+
+        self.assertTrue(hasattr(event, 'signatures'))
+        self.assertTrue(HOSTNAME in event.signatures)
+        self.assertTrue(KEY_NAME in event.signatures["domain"])
+        self.assertEquals(
+            event.signatures[HOSTNAME][KEY_NAME],
+            "Wm+VzmOUOz08Ds+0NTWb1d4CZrVsJSikkeRxh6aCcUw"
+            "u6pNC78FunoD7KNWzqFn241eYHYMGCA5McEiVPdhzBA"
+        )