summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael R. Mauger <michael@mauger.com>2019-12-22 23:56:05 -0500
committerMichael R. Mauger <michael@mauger.com>2019-12-22 23:56:05 -0500
commit3df7d06d4187d402e4df1177461862af638d96de (patch)
treeceb522ae690fec95a1ee7118293cd93edd460479 /test
parenteea05713bef7b86ff84ca843948f944e4c856119 (diff)
downloademacs-3df7d06d4187d402e4df1177461862af638d96de.tar.gz
Added `comint-password-function' hook
* etc/NEWS: * lisp/comint.el (comint-password-function): New variable. (comint-send-invisible): Use it. * test/lisp/comint-tests.el (comint-test-no-password-function, comint-test-password-function-with-value, comint-test-password-function-with-nil): Test new variable.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/comint-tests.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/lisp/comint-tests.el b/test/lisp/comint-tests.el
index 213a5c7c9e4..c04134599f6 100644
--- a/test/lisp/comint-tests.el
+++ b/test/lisp/comint-tests.el
@@ -52,6 +52,74 @@
(dolist (str comint-testsuite-password-strings)
(should (string-match comint-password-prompt-regexp str))))
+(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))))
+ (comint-send-string proc "Password: ")
+ (accept-process-output proc 0 1 t)
+ (comint-send-eof)
+ (accept-process-output proc 0 1 t)
+ (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))))
+ (comint-send-string proc "Password: ")
+ (accept-process-output proc 0 1 t)
+ (comint-send-eof)
+ (accept-process-output proc 0 1 t)
+ (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))))
+ (comint-send-string proc "Password: ")
+ (accept-process-output proc 0 1 t)
+ (comint-send-eof)
+ (accept-process-output proc 0 1 t)
+ (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)))))))
+
;; Local Variables:
;; no-byte-compile: t
;; End: