aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael R. Mauger2019-12-22 23:56:05 -0500
committerMichael R. Mauger2019-12-22 23:56:05 -0500
commit3df7d06d4187d402e4df1177461862af638d96de (patch)
treeceb522ae690fec95a1ee7118293cd93edd460479 /test
parenteea05713bef7b86ff84ca843948f944e4c856119 (diff)
downloademacs-3df7d06d4187d402e4df1177461862af638d96de.tar.gz
emacs-3df7d06d4187d402e4df1177461862af638d96de.zip
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 @@
52 (dolist (str comint-testsuite-password-strings) 52 (dolist (str comint-testsuite-password-strings)
53 (should (string-match comint-password-prompt-regexp str)))) 53 (should (string-match comint-password-prompt-regexp str))))
54 54
55(ert-deftest comint-test-no-password-function ()
56 "Test that `comint-password-function' not being set does not
57alter normal password flow."
58 (cl-letf
59 (((symbol-function 'read-passwd)
60 (lambda (_prompt &optional _confirm _default)
61 "PaSsWoRd123")))
62 (let ((cat (executable-find "cat")))
63 (when cat
64 (with-temp-buffer
65 (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
66 (let ((proc (get-buffer-process (current-buffer))))
67 (comint-send-string proc "Password: ")
68 (accept-process-output proc 0 1 t)
69 (comint-send-eof)
70 (accept-process-output proc 0 1 t)
71 (should (string-equal (buffer-substring-no-properties (point-min) (point-max))
72 "Password: PaSsWoRd123\n"))
73 (when (process-live-p proc)
74 (kill-process proc))
75 (accept-process-output proc 0 1 t)))))))
76
77(ert-deftest comint-test-password-function-with-value ()
78 "Test that `comint-password-function' alters normal password
79flow. Hook function returns alternative password."
80 (cl-letf
81 (((symbol-function 'read-passwd)
82 (lambda (_prompt &optional _confirm _default)
83 "PaSsWoRd123")))
84 (let ((cat (executable-find "cat"))
85 (comint-password-function (lambda (_prompt) "MaGiC-PaSsWoRd789")))
86 (when cat
87 (with-temp-buffer
88 (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
89 (let ((proc (get-buffer-process (current-buffer))))
90 (comint-send-string proc "Password: ")
91 (accept-process-output proc 0 1 t)
92 (comint-send-eof)
93 (accept-process-output proc 0 1 t)
94 (should (string-equal (buffer-substring-no-properties (point-min) (point-max))
95 "Password: MaGiC-PaSsWoRd789\n"))
96 (when (process-live-p proc)
97 (kill-process proc))
98 (accept-process-output proc 0 1 t)))))))
99
100(ert-deftest comint-test-password-function-with-nil ()
101 "Test that `comint-password-function' does not alter the normal
102password flow if it returns a nil value."
103 (cl-letf
104 (((symbol-function 'read-passwd)
105 (lambda (_prompt &optional _confirm _default)
106 "PaSsWoRd456")))
107 (let ((cat (executable-find "cat"))
108 (comint-password-function (lambda (_prompt) nil)))
109 (when cat
110 (with-temp-buffer
111 (make-comint-in-buffer "test-comint-password" (current-buffer) cat)
112 (let ((proc (get-buffer-process (current-buffer))))
113 (comint-send-string proc "Password: ")
114 (accept-process-output proc 0 1 t)
115 (comint-send-eof)
116 (accept-process-output proc 0 1 t)
117 (should (string-equal (buffer-substring-no-properties (point-min) (point-max))
118 "Password: PaSsWoRd456\n"))
119 (when (process-live-p proc)
120 (kill-process proc))
121 (accept-process-output proc 0 1 t)))))))
122
55;; Local Variables: 123;; Local Variables:
56;; no-byte-compile: t 124;; no-byte-compile: t
57;; End: 125;; End: