From a3eb5dca24e3efa8f16ebcdc4b7d635dc9af03b7 Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Sat, 28 Aug 2021 20:36:10 +0200 Subject: [PATCH] Allow piping the password to login_cli This is useful for testing where entering a password manually is not possible. --- changelog.yaml | 1 + toot/auth.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog.yaml b/changelog.yaml index 45a8b238..0d38a8da 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -4,6 +4,7 @@ - "Add `--scheduled-at` option to `toot post`, allows scheduling toots" - "Add `--description` option to `toot post`, for adding descriptions to media attachments (thanks @ansuz)" - "Disable paging timeline when output is piped (thanks @stacyharper)" + - "Allow piping the password to login_cli for testing purposes (thanks @NinjaTrappeur)" 0.27.0: date: 2020-06-15 diff --git a/toot/auth.py b/toot/auth.py index eb9e3c89..1b4a3278 100644 --- a/toot/auth.py +++ b/toot/auth.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import sys import webbrowser from builtins import input @@ -66,7 +67,13 @@ def login_interactive(app, email=None): while not email: email = input('Email: ') - password = getpass('Password: ') + # Accept password piped from stdin, useful for testing purposes but not + # documented so people won't get ideas. Otherwise prompt for password. + if sys.stdin.isatty(): + password = getpass('Password: ') + else: + password = sys.stdin.read().strip() + print_out("Password: read from stdin") try: print_out("Authenticating...")