Commit 4d66264d authored by Lambros Lambrou's avatar Lambros Lambrou Committed by Commit Bot

Add It2MePermissionCheck to native-messaging test tool

Also updated it to deal with _debug_log replies, and other cleanups.

Change-Id: I83484acd33df759f02f37d1d6eef6c2300132a75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1947478
Auto-Submit: Lambros Lambrou <lambroslambrou@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Jamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721138}
parent d5df2996
...@@ -21,11 +21,27 @@ def PrintMenuAndGetBuilder(messages): ...@@ -21,11 +21,27 @@ def PrintMenuAndGetBuilder(messages):
choice = raw_input('Enter choice: ') choice = raw_input('Enter choice: ')
if choice.lower() == 'q': if choice.lower() == 'q':
return None return None
choice = int(choice) try:
choice = int(choice)
except ValueError:
continue
if choice >= 1 and choice <= len(messages): if choice >= 1 and choice <= len(messages):
return messages[choice - 1][1] return messages[choice - 1][1]
def ReadMessage(in_stream):
reply_length_bytes = in_stream.read(4)
if len(reply_length_bytes) < 4:
print 'Invalid message length'
return None
reply_length = struct.unpack('i', reply_length_bytes)[0]
reply = in_stream.read(reply_length).decode('utf-8')
if len(reply) != reply_length:
print 'Invalid reply length'
return None
return json.loads(reply)
# Message builder methods. # Message builder methods.
def BuildHello(): def BuildHello():
return {'type': 'hello'} return {'type': 'hello'}
...@@ -99,6 +115,10 @@ def BuildGetDaemonState(): ...@@ -99,6 +115,10 @@ def BuildGetDaemonState():
return {'type': 'getDaemonState'} return {'type': 'getDaemonState'}
def BuildIt2MePermissionCheck():
return {'type': 'it2mePermissionCheck'}
def main(): def main():
if len(sys.argv) != 2: if len(sys.argv) != 2:
print 'Usage: ' + sys.argv[0] + ' <path to native messaging host>' print 'Usage: ' + sys.argv[0] + ' <path to native messaging host>'
...@@ -124,7 +144,8 @@ def main(): ...@@ -124,7 +144,8 @@ def main():
('Get usage stats consent', BuildGetUsageStatsConsent), ('Get usage stats consent', BuildGetUsageStatsConsent),
('Start daemon', BuildStartDaemon), ('Start daemon', BuildStartDaemon),
('Stop daemon', BuildStopDaemon), ('Stop daemon', BuildStopDaemon),
('Get daemon state', BuildGetDaemonState) ('Get daemon state', BuildGetDaemonState),
('It2Me permission check', BuildIt2MePermissionCheck),
] ]
builder = PrintMenuAndGetBuilder(messages) builder = PrintMenuAndGetBuilder(messages)
if not builder: if not builder:
...@@ -138,15 +159,15 @@ def main(): ...@@ -138,15 +159,15 @@ def main():
child.stdin.write(message) child.stdin.write(message)
child.stdin.flush() child.stdin.flush()
reply_length_bytes = child.stdout.read(4) while True:
if len(reply_length_bytes) < 4: reply_dict = ReadMessage(child.stdout)
print 'Invalid message length' if reply_dict is None:
break break
reply_length = struct.unpack('i', reply_length_bytes)[0] reply_pretty = json.dumps(reply_dict)
reply = child.stdout.read(reply_length).decode('utf-8') if reply_dict['type'] == '_debug_log':
print 'Reply: ' + reply print 'Log: ' + reply_pretty
if len(reply) != reply_length: continue
print 'Invalid reply length' print 'Reply: ' + reply_pretty
break break
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment