Bug 1414882 - Add handshake to Marionette client. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 08 Nov 2017 15:26:50 +0100
changeset 695742 c4a1424cef5f998b6a9987b0bb1200d04e232deb
parent 695741 4d7eeeb41488c901fc52e5e62c5162cffc3995c0
child 695743 d993213e4ac742e3a7726df45c7fd294a3d30ea3
push id88528
push userbmo:hskupin@gmail.com
push dateThu, 09 Nov 2017 19:48:28 +0000
bugs1414882
milestone58.0a1
Bug 1414882 - Add handshake to Marionette client. A connection to Marionette server should only be accepted if the application type equals to 'gecko', and the protocol version as returned is supported by the client. MozReview-Commit-ID: LjZCsL4dt8Y
testing/marionette/client/marionette_driver/transport.py
--- a/testing/marionette/client/marionette_driver/transport.py
+++ b/testing/marionette/client/marionette_driver/transport.py
@@ -204,18 +204,28 @@ class TcpTransport(object):
                 raw = self.receive(unmarshal=False)
         except socket.timeout:
             msg = "Connection attempt failed because no data has been received over the socket: {}"
             exc, val, tb = sys.exc_info()
 
             raise exc, msg.format(val), tb
 
         hello = json.loads(raw)
-        self.protocol = hello.get("marionetteProtocol", self.min_protocol_level)
-        self.application_type = hello.get("applicationType")
+        application_type = hello.get("applicationType")
+        protocol = hello.get("marionetteProtocol")
+
+        if application_type != "gecko":
+            raise ValueError("Application type '{}' is not supported".format(application_type))
+
+        if not isinstance(protocol, int) or protocol < self.min_protocol_level:
+            msg = "Earliest supported protocol level is '{}' but got '{}'"
+            raise ValueError(msg.format(self.min_protocol_level, protocol))
+
+        self.application_type = application_type
+        self.protocol = protocol
 
         return (self.protocol, self.application_type)
 
     def send(self, obj):
         """Send message to the remote server.  Allowed input is a
         ``Message`` instance or a JSON serialisable object.
         """
         if not self.sock: