2021-09-26 01:53:56 +02:00
|
|
|
;;; comint-tests.el --- Tests for comint.el -*- lexical-binding:t -*-
|
2011-05-08 17:43:07 -04:00
|
|
|
|
2024-01-02 09:47:10 +08:00
|
|
|
;; Copyright (C) 2010-2024 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
|
2020-10-09 06:57:07 +02:00
|
|
|
"doas (user@host) password:" ; OpenBSD doas
|
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:"
|
2021-11-07 21:34:41 +01:00
|
|
|
"(user@host) Password: " ; openssh-8.6p1
|
2021-09-27 07:55:37 +02:00
|
|
|
"Current password:" ; "passwd" (to change password) in Debian.
|
2021-09-27 08:15:24 +02:00
|
|
|
"Enter encryption key: " ; ccrypt
|
|
|
|
"Enter decryption key: " ; ccrypt
|
|
|
|
"Enter encryption key: (repeat) " ; ccrypt
|
2019-05-13 18:39:32 -04:00
|
|
|
"Enter Auth Password:" ; OpenVPN (Bug#35724)
|
2021-03-18 11:17:34 +01:00
|
|
|
"Verify password: " ; zip -e zipfile.zip ... (Bug#47209)
|
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))))
|
|
|
|
|
2022-12-07 21:52:00 +02:00
|
|
|
(declare-function w32-application-type "w32proc.c")
|
2022-12-07 21:23:42 +02:00
|
|
|
(defun w32-native-executable-p (fname)
|
|
|
|
"Predicate to test program FNAME for being a native Windows application."
|
|
|
|
(and (memq (w32-application-type fname) '(w32-native dos))
|
|
|
|
(file-executable-p fname)))
|
|
|
|
|
|
|
|
(defun w32-native-executable-find (name)
|
|
|
|
"Find a native MS-Windows application named NAME.
|
|
|
|
This is needed to avoid invoking MSYS or Cygwin executables that
|
|
|
|
happen to lurk on PATH when running the test suite."
|
|
|
|
(locate-file name exec-path exec-suffixes 'w32-native-executable-p))
|
|
|
|
|
2020-09-20 12:43:37 +02:00
|
|
|
(defun comint-tests/test-password-function (password-function)
|
|
|
|
"PASSWORD-FUNCTION can return nil or a string."
|
2022-12-07 21:23:42 +02:00
|
|
|
(when-let ((cat (if (eq system-type 'windows-nt)
|
|
|
|
(w32-native-executable-find "cat")
|
|
|
|
(executable-find "cat"))))
|
2020-09-20 12:43:37 +02:00
|
|
|
(let ((comint-password-function password-function))
|
|
|
|
(cl-letf (((symbol-function 'read-passwd)
|
|
|
|
(lambda (&rest _args) "non-nil")))
|
2019-12-22 23:56:05 -05:00
|
|
|
(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)
|
2020-09-20 12:43:37 +02:00
|
|
|
(set-process-query-on-exit-flag proc nil)
|
|
|
|
(comint-send-invisible "Password: ")
|
|
|
|
(accept-process-output proc 0.1)
|
|
|
|
(should (string-equal
|
|
|
|
(buffer-substring-no-properties (point-min) (point-max))
|
|
|
|
(concat (or (and password-function
|
|
|
|
(funcall password-function))
|
|
|
|
"non-nil")
|
|
|
|
"\n")))))))))
|
|
|
|
|
|
|
|
(ert-deftest comint-test-no-password-function ()
|
|
|
|
"Test that `comint-password-function' not being set does not
|
|
|
|
alter normal password flow."
|
|
|
|
(comint-tests/test-password-function nil))
|
2019-12-22 23:56:05 -05:00
|
|
|
|
|
|
|
(ert-deftest comint-test-password-function-with-value ()
|
|
|
|
"Test that `comint-password-function' alters normal password
|
|
|
|
flow. Hook function returns alternative password."
|
2020-09-20 12:43:37 +02:00
|
|
|
(comint-tests/test-password-function
|
|
|
|
(lambda (&rest _args) "MaGiC-PaSsWoRd789")))
|
2019-12-22 23:56:05 -05:00
|
|
|
|
|
|
|
(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."
|
2020-09-20 12:43:37 +02:00
|
|
|
(comint-tests/test-password-function #'ignore))
|
2019-12-22 23:56:05 -05:00
|
|
|
|
2021-09-26 01:53:56 +02:00
|
|
|
;;; comint-tests.el ends here
|