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...")