2020-05-01 13:02:38 +02:00
|
|
|
;;; comint-tests.el -*- lexical-binding:t -*-
|
2011-05-08 17:43:07 -04:00
|
|
|
|
2020-01-01 00:19:43 +00:00
|
|
|
;; Copyright (C) 2010-2020 Free Software Foundation, Inc.
|
2011-05-08 17:43:07 -04:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2011-05-08 17:43:07 -04:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; Tests for comint and related modes.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'comint)
|
|
|
|
(require 'ert)
|
|
|
|
|
|
|
|
(defvar comint-testsuite-password-strings
|
2014-01-21 09:32:06 +01:00
|
|
|
'("foo@example.net's password: " ; ssh
|
2011-05-08 17:43:07 -04:00
|
|
|
"Password for foo@example.org: " ; kinit
|
2019-11-07 01:42:31 +01:00
|
|
|
"Password for 'https://foo@example.org':" ; git push Bug#20910
|
2011-05-08 17:43:07 -04:00
|
|
|
"Please enter the password for foo@example.org: " ; kinit
|
|
|
|
"Kerberos password for devnull/root <at> GNU.ORG: " ; ksu
|
|
|
|
"Enter passphrase: " ; ssh-add
|
|
|
|
"Enter passphrase (empty for no passphrase): " ; ssh-keygen
|
|
|
|
"Enter same passphrase again: " ; ssh-keygen
|
2019-10-06 03:08:27 +02:00
|
|
|
"Enter your password: " ; python3 -m twine ... Bug#37636
|
2011-05-08 17:43:07 -04:00
|
|
|
"Passphrase for key root@GNU.ORG: " ; plink
|
|
|
|
"[sudo] password for user:" ; Ubuntu sudo
|
2018-06-25 19:11:41 -04:00
|
|
|
"[sudo] user 的密码:" ; localized
|
2019-05-04 13:20:42 -04:00
|
|
|
"PIN for user:" ; Bug#35523
|
2011-05-08 17:43:07 -04:00
|
|
|
"Password (again):"
|
2014-01-21 09:32:06 +01:00
|
|
|
"Enter password:"
|
2019-05-13 18:39:32 -04:00
|
|
|
"Enter Auth Password:" ; OpenVPN (Bug#35724)
|
2018-08-17 06:29:35 -04:00
|
|
|
"Mot de Passe :" ; localized (Bug#29729)
|
2014-01-21 09:32:06 +01:00
|
|
|
"Passwort:") ; localized
|
2011-05-08 17:43:07 -04:00
|
|
|
"List of strings that should match `comint-password-prompt-regexp'.")
|
|
|
|
|
|
|
|
(ert-deftest comint-test-password-regexp ()
|
|
|
|
"Test `comint-password-prompt-regexp' against common password strings."
|
|
|
|
(dolist (str comint-testsuite-password-strings)
|
|
|
|
(should (string-match comint-password-prompt-regexp str))))
|
|
|
|
|
2019-12-22 23:56:05 -05:00
|
|
|
(ert-deftest comint-test-no-password-function ()
|
|
|
|
"Test that `comint-password-function' not being set does not
|
|
|
|
alter normal password flow."
|
|
|
|
(cl-letf
|
|
|
|
(((symbol-function 'read-passwd)
|
|
|
|
(lambda (_prompt &optional _confirm _default)
|
|
|
|
"PaSsWoRd123")))
|
|
|
|
(let ((cat (executable-find "cat")))
|
|
|
|
(when cat
|
|
|
|
(with-temp-buffer
|
|
|
|
(make-comint-in-buffer "test-comint-password" (current-buffer) cat)
|
|
|
|
(let ((proc (get-buffer-process (current-buffer))))
|
2019-12-30 14:10:02 +01:00
|
|
|
(set-process-query-on-exit-flag proc nil)
|
2019-12-22 23:56:05 -05:00
|
|
|
(comint-send-string proc "Password: ")
|
|
|
|
(comint-send-eof)
|
2019-12-30 14:10:02 +01:00
|
|
|
(while (accept-process-output proc 0.1 nil t))
|
2019-12-22 23:56:05 -05:00
|
|
|
(should (string-equal (buffer-substring-no-properties (point-min) (point-max))
|
|
|
|
"Password: PaSsWoRd123\n"))
|
|
|
|
(when (process-live-p proc)
|
|
|
|
(kill-process proc))
|
|
|
|
(accept-process-output proc 0 1 t)))))))
|
|
|
|
|
|
|
|
(ert-deftest comint-test-password-function-with-value ()
|
|
|
|
"Test that `comint-password-function' alters normal password
|
|
|
|
flow. Hook function returns alternative password."
|
|
|
|
(cl-letf
|
|
|
|
(((symbol-function 'read-passwd)
|
|
|
|
(lambda (_prompt &optional _confirm _default)
|
|
|
|
"PaSsWoRd123")))
|
|
|
|
(let ((cat (executable-find "cat"))
|
|
|
|
(comint-password-function (lambda (_prompt) "MaGiC-PaSsWoRd789")))
|
|
|
|
(when cat
|
|
|
|
(with-temp-buffer
|
|
|
|
(make-comint-in-buffer "test-comint-password" (current-buffer) cat)
|
|
|
|
(let ((proc (get-buffer-process (current-buffer))))
|
2019-12-30 14:10:02 +01:00
|
|
|
(set-process-query-on-exit-flag proc nil)
|
2019-12-22 23:56:05 -05:00
|
|
|
(comint-send-string proc "Password: ")
|
|
|
|
(comint-send-eof)
|
2019-12-30 14:10:02 +01:00
|
|
|
(while (accept-process-output proc 0.1 nil t))
|
2019-12-22 23:56:05 -05:00
|
|
|
(should (string-equal (buffer-substring-no-properties (point-min) (point-max))
|
|
|
|
"Password: MaGiC-PaSsWoRd789\n"))
|
|
|
|
(when (process-live-p proc)
|
|
|
|
(kill-process proc))
|
|
|
|
(accept-process-output proc 0 1 t)))))))
|
|
|
|
|
|
|
|
(ert-deftest comint-test-password-function-with-nil ()
|
|
|
|
"Test that `comint-password-function' does not alter the normal
|
|
|
|
password flow if it returns a nil value."
|
|
|
|
(cl-letf
|
|
|
|
(((symbol-function 'read-passwd)
|
|
|
|
(lambda (_prompt &optional _confirm _default)
|
|
|
|
"PaSsWoRd456")))
|
|
|
|
(let ((cat (executable-find "cat"))
|
|
|
|
(comint-password-function (lambda (_prompt) nil)))
|
|
|
|
(when cat
|
|
|
|
(with-temp-buffer
|
|
|
|
(make-comint-in-buffer "test-comint-password" (current-buffer) cat)
|
|
|
|
(let ((proc (get-buffer-process (current-buffer))))
|
2019-12-30 14:10:02 +01:00
|
|
|
(set-process-query-on-exit-flag proc nil)
|
2019-12-22 23:56:05 -05:00
|
|
|
(comint-send-string proc "Password: ")
|
|
|
|
(comint-send-eof)
|
2019-12-30 14:10:02 +01:00
|
|
|
(while (accept-process-output proc 0.1 nil t))
|
2019-12-22 23:56:05 -05:00
|
|
|
(should (string-equal (buffer-substring-no-properties (point-min) (point-max))
|
|
|
|
"Password: PaSsWoRd456\n"))
|
|
|
|
(when (process-live-p proc)
|
|
|
|
(kill-process proc))
|
|
|
|
(accept-process-output proc 0 1 t)))))))
|
|
|
|
|
2011-05-08 17:43:07 -04:00
|
|
|
;; Local Variables:
|
|
|
|
;; no-byte-compile: t
|
|
|
|
;; End:
|
|
|
|
|
|
|
|
;;; comint-testsuite.el ends here
|