Skip to content

Commit

Permalink
Merge pull request ome#256 from sbesson/stdout_tty
Browse files Browse the repository at this point in the history
Also check stdout is a tty when requiring interactive credentials
  • Loading branch information
manics authored Sep 30, 2020
2 parents 5d81cfa + 606f9fc commit dabb54f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/omero/plugins/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,12 @@ def _get_username(self, defuser):
return rv

def _require_tty(self, msg):
if sys.stdin.isatty():
if not sys.stdin.isatty():
self.ctx.die(564, "stdin is not a terminal: %s" % msg)
elif not sys.stdout.isatty():
self.ctx.die(564, "stdout is not a terminal: %s" % msg)
else:
return
self.ctx.die(564, "stdin is not a terminal: %s" % msg)


try:
Expand Down
7 changes: 3 additions & 4 deletions test/unit/clitest/test_sess.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def isatty(*args, **kwargs):
return True
monkeypatch.setattr(sys.stdin, 'isatty', isatty)
assert sys.stdin.isatty()
monkeypatch.setattr(sys.stdout, 'isatty', isatty)
assert sys.stdout.isatty()


class MyStore(SessionsStore):
Expand Down Expand Up @@ -408,7 +410,7 @@ def testReuseWorks(self, connection, port, group):

@pytest.mark.parametrize('connection', CONNECTION_TYPES)
@pytest.mark.parametrize('group', DIFFERENT_GROUPS)
def testReuseFromDifferentGroupDoesntWork(self, connection, group, capsys):
def testReuseFromDifferentGroupDoesntWork(self, connection, group):
"""
Test session reuse with different groups fails
"""
Expand All @@ -423,9 +425,6 @@ def testReuseFromDifferentGroupDoesntWork(self, connection, group, capsys):
conn_args = self.get_conn_args(connection, group=group[1])
cli.invoke(["s", "login"] + conn_args)
cli.assertReqSize(self, 0)
out, err = capsys.readouterr()
msg = (self.get_conflict_message() + 'omero.group: %s!=%s')
assert err.splitlines()[-2] == msg % ('testsessid', group[0], group[1])

@pytest.mark.parametrize('connection', CONNECTION_TYPES)
@pytest.mark.parametrize('port', MATCHING_PORTS)
Expand Down

0 comments on commit dabb54f

Please sign in to comment.