diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/lisp/auth-source-tests.el | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el index d6845b0af37..4d4786f4ca9 100644 --- a/test/lisp/auth-source-tests.el +++ b/test/lisp/auth-source-tests.el | |||
| @@ -32,6 +32,13 @@ | |||
| 32 | (require 'auth-source) | 32 | (require 'auth-source) |
| 33 | (require 'secrets) | 33 | (require 'secrets) |
| 34 | 34 | ||
| 35 | ;; (dolist | ||
| 36 | ;; (elt | ||
| 37 | ;; (append | ||
| 38 | ;; (mapcar #'intern (all-completions "auth-" obarray #'functionp)) | ||
| 39 | ;; (mapcar #'intern (all-completions "password-" obarray #'functionp)))) | ||
| 40 | ;; (trace-function-background elt)) | ||
| 41 | |||
| 35 | (defun auth-source-ensure-ignored-backend (source) | 42 | (defun auth-source-ensure-ignored-backend (source) |
| 36 | (auth-source-validate-backend source '((source . "") | 43 | (auth-source-validate-backend source '((source . "") |
| 37 | (type . ignore)))) | 44 | (type . ignore)))) |
| @@ -103,6 +110,14 @@ | |||
| 103 | (create-function | 110 | (create-function |
| 104 | . auth-source-plstore-create)))) | 111 | . auth-source-plstore-create)))) |
| 105 | 112 | ||
| 113 | (ert-deftest auth-source-backend-parse-plstore-string () | ||
| 114 | (auth-source-validate-backend "foo.plist" | ||
| 115 | '((source . "foo.plist") | ||
| 116 | (type . plstore) | ||
| 117 | (search-function . auth-source-plstore-search) | ||
| 118 | (create-function | ||
| 119 | . auth-source-plstore-create)))) | ||
| 120 | |||
| 106 | (ert-deftest auth-source-backend-parse-netrc () | 121 | (ert-deftest auth-source-backend-parse-netrc () |
| 107 | (auth-source-validate-backend '(:source "foo") | 122 | (auth-source-validate-backend '(:source "foo") |
| 108 | '((source . "foo") | 123 | '((source . "foo") |
| @@ -129,6 +144,16 @@ | |||
| 129 | ;; . auth-source-json-create)))) | 144 | ;; . auth-source-json-create)))) |
| 130 | . ignore)))) | 145 | . ignore)))) |
| 131 | 146 | ||
| 147 | (ert-deftest auth-source-backend-parse-json-string () | ||
| 148 | (auth-source-validate-backend "foo.json" | ||
| 149 | '((source . "foo.json") | ||
| 150 | (type . json) | ||
| 151 | (search-function . auth-source-json-search) | ||
| 152 | (create-function | ||
| 153 | ;; To be implemented: | ||
| 154 | ;; . auth-source-json-create)))) | ||
| 155 | . ignore)))) | ||
| 156 | |||
| 132 | (ert-deftest auth-source-backend-parse-secrets () | 157 | (ert-deftest auth-source-backend-parse-secrets () |
| 133 | (provide 'secrets) ; simulates the presence of the `secrets' package | 158 | (provide 'secrets) ; simulates the presence of the `secrets' package |
| 134 | (let ((secrets-enabled t)) | 159 | (let ((secrets-enabled t)) |
| @@ -198,6 +223,20 @@ | |||
| 198 | (auth-source-ensure-ignored-backend '(:source '(foo))) | 223 | (auth-source-ensure-ignored-backend '(:source '(foo))) |
| 199 | (auth-source-ensure-ignored-backend '(:source nil)))) | 224 | (auth-source-ensure-ignored-backend '(:source nil)))) |
| 200 | 225 | ||
| 226 | (ert-deftest auth-source-backend-parse-fallback () | ||
| 227 | (let* (auth-sources | ||
| 228 | (backends (auth-source-backends)) | ||
| 229 | (backend (car backends)) | ||
| 230 | (validation-alist | ||
| 231 | '((source . "") | ||
| 232 | (type . read-passwd) | ||
| 233 | (search-function . auth-source-read-passwd-search) | ||
| 234 | (create-function . auth-source-read-passwd-create)))) | ||
| 235 | (should (length= backends 1)) | ||
| 236 | (should (auth-source-backend-p backend)) | ||
| 237 | (dolist (pair validation-alist) | ||
| 238 | (should (equal (eieio-oref backend (car pair)) (cdr pair)))))) | ||
| 239 | |||
| 201 | (defun auth-source--test-netrc-parse-entry (entry host user port) | 240 | (defun auth-source--test-netrc-parse-entry (entry host user port) |
| 202 | "Parse a netrc entry from buffer." | 241 | "Parse a netrc entry from buffer." |
| 203 | (auth-source-forget-all-cached) | 242 | (auth-source-forget-all-cached) |
| @@ -434,6 +473,35 @@ | |||
| 434 | (should (string-equal auth-passwd passwd)) | 473 | (should (string-equal auth-passwd passwd)) |
| 435 | (should (search-forward host nil 'noerror))))))))) | 474 | (should (search-forward host nil 'noerror))))))))) |
| 436 | 475 | ||
| 476 | (ert-deftest auth-source-test-read-passwd-create-secret () | ||
| 477 | (let (auth-sources auth-info auth-passwd host) | ||
| 478 | (auth-source-forget-all-cached) | ||
| 479 | (dolist (passwd '("foo" "" nil)) | ||
| 480 | (unwind-protect | ||
| 481 | ;; Redefine `read-*' in order to avoid interactive input. | ||
| 482 | (cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd)) | ||
| 483 | ((symbol-function 'read-string) | ||
| 484 | (lambda (_prompt &optional _initial _history default | ||
| 485 | _inherit-input-method) | ||
| 486 | default))) | ||
| 487 | (setq host | ||
| 488 | (md5 (concat (prin1-to-string process-environment) passwd)) | ||
| 489 | auth-info | ||
| 490 | (car (auth-source-search | ||
| 491 | :max 1 :host host :require '(:user :secret) :create t)) | ||
| 492 | auth-passwd (auth-info-password auth-info)) | ||
| 493 | (should (string-equal (plist-get auth-info :user) (user-login-name))) | ||
| 494 | (should (string-equal (plist-get auth-info :host) host)) | ||
| 495 | (should (equal auth-passwd passwd)) | ||
| 496 | (should-not (plist-get auth-info :save-function)) | ||
| 497 | |||
| 498 | ;; Check, that the item hasn't been created persistently. | ||
| 499 | (auth-source-forget+ :host t) | ||
| 500 | (should-not (auth-source-search :host host))) | ||
| 501 | |||
| 502 | ;; Cleanup. | ||
| 503 | t)))) | ||
| 504 | |||
| 437 | (ert-deftest auth-source-delete () | 505 | (ert-deftest auth-source-delete () |
| 438 | (ert-with-temp-file netrc-file | 506 | (ert-with-temp-file netrc-file |
| 439 | :suffix "auth-source-test" :text "\ | 507 | :suffix "auth-source-test" :text "\ |