diff --git a/src/wormhole/cli/cli.py b/src/wormhole/cli/cli.py index f994478..9ce3d07 100644 --- a/src/wormhole/cli/cli.py +++ b/src/wormhole/cli/cli.py @@ -54,6 +54,8 @@ class AliasedGroup(click.Group): # top-level command ("wormhole ...") @click.group(cls=AliasedGroup) +@click.option( + "--appid", default=None, metavar="APPID", help="appid to use") @click.option( "--relay-url", default=public_relay.RENDEZVOUS_RELAY, metavar="URL", @@ -75,7 +77,7 @@ class AliasedGroup(click.Group): version=__version__, ) @click.pass_context -def wormhole(context, dump_timing, transit_helper, relay_url): +def wormhole(context, dump_timing, transit_helper, relay_url, appid): """ Create a Magic Wormhole and communicate through it. @@ -84,6 +86,7 @@ def wormhole(context, dump_timing, transit_helper, relay_url): anyone who doesn't use the same code. """ context.obj = cfg = Config() + cfg.appid = appid cfg.relay_url = relay_url cfg.transit_helper = transit_helper cfg.dump_timing = dump_timing diff --git a/src/wormhole/cli/cmd_receive.py b/src/wormhole/cli/cmd_receive.py index c23b44a..3d79f11 100644 --- a/src/wormhole/cli/cmd_receive.py +++ b/src/wormhole/cli/cmd_receive.py @@ -57,8 +57,8 @@ class TwistedReceiver: # with the user handing off the wormhole code yield self._tor_manager.start() - w = wormhole(APPID, self.args.relay_url, self._reactor, - self._tor_manager, timing=self.args.timing) + w = wormhole(self.args.appid or APPID, self.args.relay_url, + self._reactor, self._tor_manager, timing=self.args.timing) # I wanted to do this instead: # # try: diff --git a/src/wormhole/cli/cmd_send.py b/src/wormhole/cli/cmd_send.py index 958f794..9551f93 100644 --- a/src/wormhole/cli/cmd_send.py +++ b/src/wormhole/cli/cmd_send.py @@ -47,7 +47,7 @@ class Sender: # with the user handing off the wormhole code yield self._tor_manager.start() - w = wormhole(APPID, self._args.relay_url, + w = wormhole(self._args.appid or APPID, self._args.relay_url, self._reactor, self._tor_manager, timing=self._timing) d = self._go(w) diff --git a/src/wormhole/cli/cmd_ssh.py b/src/wormhole/cli/cmd_ssh.py index b452cec..f4b36da 100644 --- a/src/wormhole/cli/cmd_ssh.py +++ b/src/wormhole/cli/cmd_ssh.py @@ -63,7 +63,7 @@ def find_public_key(hint=None): def accept(cfg, reactor=reactor): yield xfer_util.send( reactor, - u"lothar.com/wormhole/ssh-add", + cfg.appid or u"lothar.com/wormhole/ssh-add", cfg.relay_url, data=cfg.public_key[2], code=cfg.code, @@ -104,7 +104,7 @@ def invite(cfg, reactor=reactor): pubkey = yield xfer_util.receive( reactor, - u"lothar.com/wormhole/ssh-add", + cfg.appid or u"lothar.com/wormhole/ssh-add", cfg.relay_url, None, # allocate a code for us use_tor=cfg.tor, diff --git a/src/wormhole/test/test_args.py b/src/wormhole/test/test_args.py index b8dbe6e..c013e29 100644 --- a/src/wormhole/test/test_args.py +++ b/src/wormhole/test/test_args.py @@ -14,6 +14,7 @@ class Send(unittest.TestCase): self.assertEqual(cfg.dump_timing, None) self.assertEqual(cfg.hide_progress, False) self.assertEqual(cfg.listen, True) + self.assertEqual(cfg.appid, None) self.assertEqual(cfg.relay_url, RENDEZVOUS_RELAY) self.assertEqual(cfg.transit_helper, TRANSIT_RELAY) self.assertEqual(cfg.text, "hi") @@ -21,6 +22,12 @@ class Send(unittest.TestCase): self.assertEqual(cfg.verify, False) self.assertEqual(cfg.zeromode, False) + def test_appid(self): + cfg = config("--appid", "xyz", "send", "--text", "hi") + self.assertEqual(cfg.appid, "xyz") + cfg = config("--appid=xyz", "send", "--text", "hi") + self.assertEqual(cfg.appid, "xyz") + def test_file(self): cfg = config("send", "fn") #pprint(cfg.__dict__) @@ -76,12 +83,19 @@ class Receive(unittest.TestCase): self.assertEqual(cfg.listen, True) self.assertEqual(cfg.only_text, False) self.assertEqual(cfg.output_file, None) + self.assertEqual(cfg.appid, None) self.assertEqual(cfg.relay_url, RENDEZVOUS_RELAY) self.assertEqual(cfg.transit_helper, TRANSIT_RELAY) self.assertEqual(cfg.tor, False) self.assertEqual(cfg.verify, False) self.assertEqual(cfg.zeromode, False) + def test_appid(self): + cfg = config("--appid", "xyz", "receive") + self.assertEqual(cfg.appid, "xyz") + cfg = config("--appid=xyz", "receive") + self.assertEqual(cfg.appid, "xyz") + def test_nolisten(self): cfg = config("receive", "--no-listen") self.assertEqual(cfg.listen, False) diff --git a/src/wormhole/test/test_scripts.py b/src/wormhole/test/test_scripts.py index 69f8a42..14abbb5 100644 --- a/src/wormhole/test/test_scripts.py +++ b/src/wormhole/test/test_scripts.py @@ -740,3 +740,34 @@ class ExtractFile(unittest.TestCase): zi.filename = "/etc/passwd" e = self.assertRaises(ValueError, ef, zf, zi, extract_dir) self.assertIn("malicious zipfile", str(e)) + +class AppID(ServerBase, unittest.TestCase): + def setUp(self): + d = super(AppID, self).setUp() + self.cfg = cfg = config("send") + # common options for all tests in this suite + cfg.hide_progress = True + cfg.relay_url = self.relayurl + cfg.transit_helper = "" + cfg.stdout = io.StringIO() + cfg.stderr = io.StringIO() + return d + + @inlineCallbacks + def test_override(self): + # make sure we use the overridden appid, not the default + self.cfg.text = "hello" + self.cfg.appid = "appid2" + self.cfg.code = "1-abc" + + send_d = cmd_send.send(self.cfg) + receive_d = cmd_receive.receive(self.cfg) + + yield send_d + yield receive_d + + used = self._rendezvous._db.execute("SELECT DISTINCT `app_id`" + " FROM `nameplate_usage`" + ).fetchall() + self.assertEqual(len(used), 1, used) + self.assertEqual(used[0]["app_id"], u"appid2")