summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2026-05-16 07:17:51 -0400
committerEli Zaretskii <eliz@gnu.org>2026-05-16 07:17:51 -0400
commit87e4687749f29a3495fc335e99991837b8170725 (patch)
tree2ba699e2fcf888060481aebf6a2c9fa8304c6916 /test
parent025ecf9e7b45aa7a8d5825559f0e6226bfebb9d2 (diff)
parent7eab6ef3cee22c5f3ada55f1a68e29cb3f23da45 (diff)
Merge from origin/emacs-31
7eab6ef3cee Fix 'sgml-parse-tag-backward' to handle tags in comments 09dc864b0b8 Fix eww-submit for forms with no action (bug#80918) 0e7a24d9313 * lisp/progmodes/hideshow.el (hs--set-variable): Use 'set... f12b01582db Fix Completions buffer disappearing with tmm-menubar (bug... 519fd832111 Fix secrets.el when Emacs is a flatpak 9e4ea934f23 Fix 'prepare-user-lisp' to follow symlinks e613e38021e Update "timeout" to 2.1.6 196fd80689e [GTK3, HiDPI] Fix width/height round-trip through Configu... acc07f1a030 [GTK3] On Expose, repaint the border before the content 5323eebcffc Test read-passwd behavior (bug#80838) 01c5990dd06 Fix nested read-passwd calls (bug#80838) 027043df257 ; * lisp/gnus/message.el (message-server-alist): Doc fix ... 3b608b233ed Fix terminal emulation of "ESC [ K" sequence 6a605c65a83 Fix vertical-motion across overlay strings with embedded ... e4d529c67b6 ; Fix last change d54faa0f1bf Mark gnus-dbus.el as obsolete 9bf2a19bb21 Move gnus-dbus.el to obsolete/gnus-dbus.el 984024daf3c Gnus: Use new sleep library d7c130972e0 ; * lisp/term/pgtk-win.el (icon-map-list): Fix :type. 5579893ed7c ; Don't block/unblock input in text_extents methods 547b1ee7b6d Fix Rmail behavior wrt globalized minor modes 6ba05106f4e Fix display images in the display margins 56f27dd9f06 Eglot: fix eglot--sig-info with non-UTF-32 positionEncoding 543d8a7a9d7 [NS] Fix deprecated variable (bug#80985) # Conflicts: # etc/NEWS
Diffstat (limited to 'test')
-rw-r--r--test/lisp/auth-source-tests.el113
1 files changed, 113 insertions, 0 deletions
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el
index 7da3fed70be..9a58d15484d 100644
--- a/test/lisp/auth-source-tests.el
+++ b/test/lisp/auth-source-tests.el
@@ -571,5 +571,118 @@ machine c1 port c2 user c3 password c4\n"
:user '("a" "b") :host '("example.org")
:port '("irc" "ftp" "https" 123)))))
+(defun auth-source-test--displayed-string (string)
+ "Apply `display' properties of STRING and return the displayed string."
+ (let ((i 0)
+ res)
+ (while i
+ (let ((display (get-text-property i 'display string))
+ (i0 i))
+ (setq i (next-single-property-change i 'display string))
+ (if display
+ (push display res)
+ (push (substring string i0 i) res))))
+ (apply #'concat (nreverse res))))
+
+(ert-deftest auth-source-test-read-passwd ()
+ "Check that a password read with `read-passwd' isn't visible by default."
+ (let* ((cursor-in-echo-area t)
+ (screenshot (intern "ert--screenshot"))
+ (keys `[,@"secret"
+ ;; fake input event to capture the current minibuf string
+ ,screenshot
+ ;; leave outer prompt
+ ,@(kbd "RET")])
+ (minibuffer-string nil)
+ (command-screenshot
+ (lambda ()
+ (interactive)
+ (setq minibuffer-string (buffer-string)))))
+ (unwind-protect
+ (progn
+ (define-key global-map `[,screenshot] command-screenshot)
+ (ert-simulate-keys keys
+ (should (equal (read-passwd "Test: ") "secret"))))
+ (define-key global-map `[,screenshot] command-screenshot t))
+ ;; check that the secret's there
+ (should (equal "Test: secret" minibuffer-string))
+ ;; now simulate what redisplay does to hide the password
+ (setq minibuffer-string
+ (auth-source-test--displayed-string minibuffer-string))
+ ;; check that the secret is not visible
+ (should (equal "Test: ******" minibuffer-string))))
+
+(ert-deftest auth-source-test-read-passwd-revealed ()
+ "Check that a password read with `read-passwd' can be made visible."
+ (let* ((cursor-in-echo-area t)
+ (screenshot (intern "ert--screenshot"))
+ (keys `[,@"secret"
+ ;; TAB: reveals the password
+ ,@(kbd "TAB")
+ ;; fake input event to capture the current minibuf string
+ ,screenshot
+ ;; leave outer prompt
+ ,@(kbd "RET")])
+ (minibuffer-string nil)
+ (command-screenshot
+ (lambda ()
+ (interactive)
+ (setq minibuffer-string (buffer-string)))))
+ (unwind-protect
+ (progn
+ (define-key global-map `[,screenshot] command-screenshot)
+ (ert-simulate-keys keys
+ (should (equal (read-passwd "Test: ") "secret"))))
+ (define-key global-map `[,screenshot] command-screenshot t))
+ ;; check that the secret's there
+ (should (equal "Test: secret" minibuffer-string))
+ ;; now simulate what redisplay does to hide the password
+ (setq minibuffer-string
+ (auth-source-test--displayed-string minibuffer-string))
+ ;; check that the secret is visible once more
+ (should (equal "Test: secret" minibuffer-string))))
+
+(ert-deftest auth-source-test-read-passwd-nested ()
+ "Check that nested `read-passwd' calls do not reveal the password."
+ (let* ((cursor-in-echo-area t)
+ (trigger-nested (intern "ert--trigger-nested"))
+ (screenshot (intern "ert--screenshot"))
+ (keys `[,@"secret"
+ ;; fake input event to trigger a nested prompt
+ ,trigger-nested
+ ,@"SECRET"
+ ;; leave nested prompt
+ ,@(kbd "RET")
+ ;; fake input event to capture the current minibuf string
+ ,screenshot
+ ;; leave outer prompt
+ ,@(kbd "RET")])
+ (inner-password nil)
+ (command-trigger-nested
+ (lambda ()
+ (interactive)
+ (setq inner-password (read-passwd "inner prompt: "))))
+ (minibuffer-string nil)
+ (command-screenshot
+ (lambda ()
+ (interactive)
+ (setq minibuffer-string (buffer-string)))))
+ (unwind-protect
+ (progn
+ (define-key global-map `[,screenshot] command-screenshot)
+ (define-key global-map `[,trigger-nested] command-trigger-nested)
+ (ert-simulate-keys keys
+ (should (equal (read-passwd "Test: ") "secret"))))
+ (define-key global-map `[,screenshot] command-screenshot t)
+ (define-key global-map `[,trigger-nested] command-trigger-nested t))
+ (should (equal inner-password "SECRET"))
+ ;; check that the secret's there
+ (should (equal "Test: secret" minibuffer-string))
+ ;; now simulate what redisplay does to hide the password
+ (setq minibuffer-string
+ (auth-source-test--displayed-string minibuffer-string))
+ ;; check that the secret has been hidden
+ (should (equal "Test: ******" minibuffer-string))))
+
(provide 'auth-source-tests)
;;; auth-source-tests.el ends here