Parcourir la source

[1924] Provide proper headers

It wouldn't be needed in practice, but provide headers as close to if it
was sent by another client as reasonable and possible.

Also test we can explicitly say we don't want the answer, instead of
having just the default.
Michal 'vorner' Vaner il y a 12 ans
Parent
commit
4f49376c5d
2 fichiers modifiés avec 14 ajouts et 6 suppressions
  1. 5 4
      src/bin/msgq/msgq.py.in
  2. 9 2
      src/bin/msgq/tests/msgq_test.py

+ 5 - 4
src/bin/msgq/msgq.py.in

@@ -568,10 +568,11 @@ class MsgQ:
             # one should be enough, we modify the dict only.
             header = routing.copy()
             header["reply"] = routing["seq"]
-            # The other headers can just stay the same. They are not used
-            # in the recipient and we know where to send it, so we don't
-            # need the "to" header. We don't know the sender's lname
-            # in this part of code anyway.
+            header["from"] = 'msgq' # Dummy lname not assigned to clients
+            header["to"] = routing["from"]
+            # We keep the seq as it is. We don't need to track the message
+            # and provided the sender always uses a new one, it won't know
+            # we're cheating, since we won't send it two same either.
             errmsg = self.preparemsg(header, payload)
             # Send it back.
             self.send_prepared_msg(sock, errmsg)

+ 9 - 2
src/bin/msgq/tests/msgq_test.py

@@ -179,6 +179,7 @@ class MsgQTest(unittest.TestCase):
         # The routing headers and data to test with.
         routing = {
             'to': '*',
+            'from': 'sender',
             'group': 'group',
             'instance': '*',
             'seq': 42
@@ -190,6 +191,10 @@ class MsgQTest(unittest.TestCase):
         # so none is generated.
         self.__msgq.process_command_send(sender, routing, data)
         self.assertEqual([], sent_messages)
+        # It should act the same if we explicitly say we do not want replies.
+        routing["wants_reply"] = False
+        self.__msgq.process_command_send(sender, routing, data)
+        self.assertEqual([], sent_messages)
         # Ask for errors if it can't be delivered.
         routing["wants_reply"] = True
         self.__msgq.process_command_send(sender, routing, data)
@@ -200,7 +205,8 @@ class MsgQTest(unittest.TestCase):
                               'instance': '*',
                               'reply': 42,
                               'seq': 42,
-                              'to': '*',
+                              'from': 'msgq',
+                              'to': 'sender',
                               'wants_reply': True
                           }, {'result': [-1, "No such recipient"]}),
                           self.parse_msg(sent_messages[0][1]))
@@ -235,7 +241,8 @@ class MsgQTest(unittest.TestCase):
                               'instance': '*',
                               'reply': 42,
                               'seq': 42,
-                              'to': 'lname',
+                              'from': 'msgq',
+                              'to': 'sender',
                               'wants_reply': True
                           }, {'result': [-1, "No such recipient"]}),
                           self.parse_msg(sent_messages[0][1]))