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
--- 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: