diff tests/test-commandserver.py @ 21195:9336bc7dca8e stable

cmdserver: forcibly use L channel to read password input (issue3161) Command server is designed to use the channel protocol even if the server process is accessible to tty, whereas vanilla hg should be able to read password from tty in that case. So it isn't enough to swap sys.stdin: # works only if the server process is detached from the console sys.stdin = self.fin getpass.getpass('') sys.stdin = oldin or test isatty: # vanilla hg can't talk to tty if stdin is redirected if self._isatty(self.fin): return getpass.getpass('') else: ... Since ui.nontty flag is undocumented and command-server channels don't provide isatty(), this change won't affect the other uses of ui._isatty(). issue3161 also suggests to provide some context of messages. I think it can be implemented by using the generic templating function.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 26 Apr 2014 18:13:06 +0900
parents e811b93f2cb1
children 26d2fb899637
line wrap: on
line diff
--- a/tests/test-commandserver.py	Tue Apr 29 12:37:36 2014 +0900
+++ b/tests/test-commandserver.py	Sat Apr 26 18:13:06 2014 +0900
@@ -294,6 +294,11 @@
     # repo.mq should be recreated to point to new queue
     runcommand(server, ['qqueue', '--active'])
 
+def getpass(server):
+    readchannel(server)
+    runcommand(server, ['debuggetpass', '--config', 'ui.interactive=True'],
+               input=cStringIO.StringIO('1234\n'))
+
 def startwithoutrepo(server):
     readchannel(server)
     runcommand(server, ['init', 'repo2'])
@@ -334,6 +339,19 @@
     hgrc.write('[extensions]\nmq=\n')
     hgrc.close()
     check(mqoutsidechanges)
+    dbg = open('dbgui.py', 'w')
+    dbg.write('from mercurial import cmdutil, commands\n'
+              'commands.norepo += " debuggetpass"\n'
+              'cmdtable = {}\n'
+              'command = cmdutil.command(cmdtable)\n'
+              '@command("debuggetpass")\n'
+              'def debuggetpass(ui):\n'
+              '    ui.write("%s\\n" % ui.getpass())\n')
+    dbg.close()
+    hgrc = open('.hg/hgrc', 'a')
+    hgrc.write('[extensions]\ndbgui=dbgui.py\n')
+    hgrc.close()
+    check(getpass)
 
     os.chdir('..')
     check(hellomessage)