aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Albinus2018-05-02 12:31:51 +0200
committerMichael Albinus2018-05-02 12:31:51 +0200
commit8ae7c424c409aa31fa52304752ba62d4b5a9a4d0 (patch)
treeea18bd161145904adcf9bbe43557b29108f746dc /test
parent3e7ec620d4d49ee82bb2f4c5b9ac4095f06a15e7 (diff)
downloademacs-8ae7c424c409aa31fa52304752ba62d4b5a9a4d0.tar.gz
emacs-8ae7c424c409aa31fa52304752ba62d4b5a9a4d0.zip
Fix some edge cases of tramp-smb
* lisp/net/tramp-smb.el (tramp-smb-errors): Add "NT_STATUS_REVISION_MISMATCH". (tramp-smb-handle-delete-directory): Check, that the directory has been removed indeed. (tramp-smb-get-localname): Add further checks on filename syntax. * lisp/net/tramp.el (tramp-localname-regexp): Do not allow linefeeds. * test/lisp/net/tramp-tests.el (tramp-smb-get-localname): Declare. (auth-source-save-behavior): Set it to nil. (tramp-test01-file-name-syntax): Extend, checking for linefeeds. (tramp-test03-file-name-host-rules, tramp--test-utf8): Refine tests. (tramp-test03-file-name-method-rules): New test. (tramp--test-ignore-add-name-to-file-error): New defmacro. (tramp-test21-file-links): Use it.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/tramp-tests.el130
1 files changed, 85 insertions, 45 deletions
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 3ca401b2fa1..1843be71862 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -52,8 +52,10 @@
52 52
53(declare-function tramp-find-executable "tramp-sh") 53(declare-function tramp-find-executable "tramp-sh")
54(declare-function tramp-get-remote-path "tramp-sh") 54(declare-function tramp-get-remote-path "tramp-sh")
55(declare-function tramp-get-remote-stat "tramp-sh")
56(declare-function tramp-get-remote-perl "tramp-sh") 55(declare-function tramp-get-remote-perl "tramp-sh")
56(declare-function tramp-get-remote-stat "tramp-sh")
57(declare-function tramp-method-out-of-band-p "tramp-sh")
58(declare-function tramp-smb-get-localname "tramp-smb")
57(defvar auto-save-file-name-transforms) 59(defvar auto-save-file-name-transforms)
58(defvar tramp-copy-size-limit) 60(defvar tramp-copy-size-limit)
59(defvar tramp-persistency-file-name) 61(defvar tramp-persistency-file-name)
@@ -91,7 +93,8 @@
91 (format "/mock::%s" temporary-file-directory))) 93 (format "/mock::%s" temporary-file-directory)))
92 "Temporary directory for Tramp tests.") 94 "Temporary directory for Tramp tests.")
93 95
94(setq password-cache-expiry nil 96(setq auth-source-save-behavior nil
97 password-cache-expiry nil
95 tramp-verbose 0 98 tramp-verbose 0
96 tramp-cache-read-persistent-data t ;; For auth-sources. 99 tramp-cache-read-persistent-data t ;; For auth-sources.
97 tramp-copy-size-limit nil 100 tramp-copy-size-limit nil
@@ -248,6 +251,9 @@ handled properly. BODY shall not contain a timeout."
248 ;; No strings. 251 ;; No strings.
249 (should-not (tramp-tramp-file-p nil)) 252 (should-not (tramp-tramp-file-p nil))
250 (should-not (tramp-tramp-file-p 'symbol)) 253 (should-not (tramp-tramp-file-p 'symbol))
254 ;; No newline or linefeed.
255 (should-not (tramp-tramp-file-p "/method::file\nname"))
256 (should-not (tramp-tramp-file-p "/method::file\rname"))
251 ;; Ange-ftp syntax. 257 ;; Ange-ftp syntax.
252 (should-not (tramp-tramp-file-p "/host:")) 258 (should-not (tramp-tramp-file-p "/host:"))
253 (should-not (tramp-tramp-file-p "/user@host:")) 259 (should-not (tramp-tramp-file-p "/user@host:"))
@@ -1733,18 +1739,36 @@ handled properly. BODY shall not contain a timeout."
1733 ;; Host names must match rules in case the command template of a 1739 ;; Host names must match rules in case the command template of a
1734 ;; method doesn't use them. 1740 ;; method doesn't use them.
1735 (dolist (m '("su" "sg" "sudo" "doas" "ksu")) 1741 (dolist (m '("su" "sg" "sudo" "doas" "ksu"))
1736 ;; Single hop. The host name must match `tramp-local-host-regexp'. 1742 (let (tramp-default-proxies-alist)
1737 (should-error 1743 ;; Single hop. The host name must match `tramp-local-host-regexp'.
1738 (find-file (format "/%s:foo:" m)) 1744 (should-error
1739 :type 'user-error) 1745 (find-file (format "/%s:foo:" m))
1740 ;; Multi hop. The host name must match the previous hop. 1746 :type 'user-error)
1741 (should-error 1747 ;; Multi hop. The host name must match the previous hop.
1742 (find-file 1748 (should-error
1743 (format 1749 (find-file
1744 "%s|%s:foo:" 1750 (format
1745 (substring (file-remote-p tramp-test-temporary-file-directory) nil -1) 1751 "%s|%s:foo:"
1746 m)) 1752 (substring (file-remote-p tramp-test-temporary-file-directory) 0 -1)
1747 :type 'user-error))) 1753 m))
1754 :type
1755 (if (tramp-method-out-of-band-p
1756 (tramp-dissect-file-name tramp-test-temporary-file-directory) 0)
1757 'file-error 'user-error)))))
1758
1759(ert-deftest tramp-test03-file-name-method-rules ()
1760 "Check file name rules for some methods."
1761 (skip-unless (tramp--test-enabled))
1762
1763 ;; Samba does not support file names with periods followed by
1764 ;; spaces, and trailing periods or spaces.
1765 (when (tramp-smb-file-name-p tramp-test-temporary-file-directory)
1766 (dolist (file '("foo." "foo. bar" "foo "))
1767 (should-error
1768 (tramp-smb-get-localname
1769 (tramp-dissect-file-name
1770 (expand-file-name file tramp-test-temporary-file-directory)))
1771 :type 'file-error))))
1748 1772
1749(ert-deftest tramp-test04-substitute-in-file-name () 1773(ert-deftest tramp-test04-substitute-in-file-name ()
1750 "Check `substitute-in-file-name'." 1774 "Check `substitute-in-file-name'."
@@ -2888,11 +2912,23 @@ This tests also `file-executable-p', `file-writable-p' and `set-file-modes'."
2888 ;; Cleanup. 2912 ;; Cleanup.
2889 (ignore-errors (delete-file tmp-name)))))) 2913 (ignore-errors (delete-file tmp-name))))))
2890 2914
2915;; Method "smb" could run into "NT_STATUS_REVISION_MISMATCH" error.
2916(defmacro tramp--test-ignore-add-name-to-file-error (&rest body)
2917 "Run BODY, ignoring \"error with add-name-to-file\" file error."
2918 (declare (indent defun) (debug t))
2919 `(condition-case err
2920 (progn ,@body)
2921 ((error quit debug)
2922 (unless (and (eq (car err) 'file-error)
2923 (string-match "^error with add-name-to-file"
2924 (error-message-string err)))
2925 (signal (car err) (cdr err))))))
2926
2891(ert-deftest tramp-test21-file-links () 2927(ert-deftest tramp-test21-file-links ()
2892 "Check `file-symlink-p'. 2928 "Check `file-symlink-p'.
2893This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." 2929This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2894 (skip-unless (tramp--test-enabled)) 2930 (skip-unless (tramp--test-enabled))
2895 ;; The semantics has changed heavily in Emacs 26.1. We cannot test 2931 ;; The semantics have changed heavily in Emacs 26.1. We cannot test
2896 ;; older Emacsen, therefore. 2932 ;; older Emacsen, therefore.
2897 (skip-unless (tramp--test-emacs26-p)) 2933 (skip-unless (tramp--test-emacs26-p))
2898 2934
@@ -2990,37 +3026,39 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'."
2990 ;; Check `add-name-to-file'. 3026 ;; Check `add-name-to-file'.
2991 (unwind-protect 3027 (unwind-protect
2992 (when (tramp--test-expensive-test) 3028 (when (tramp--test-expensive-test)
2993 (write-region "foo" nil tmp-name1) 3029 (tramp--test-ignore-add-name-to-file-error
2994 (should (file-exists-p tmp-name1)) 3030 (write-region "foo" nil tmp-name1)
2995 (add-name-to-file tmp-name1 tmp-name2) 3031 (should (file-exists-p tmp-name1))
2996 (should (file-regular-p tmp-name2))
2997 (should-error
2998 (add-name-to-file tmp-name1 tmp-name2) 3032 (add-name-to-file tmp-name1 tmp-name2)
2999 :type 'file-already-exists) 3033 (should (file-regular-p tmp-name2))
3000 ;; A number means interactive case. 3034 (should-error
3001 (cl-letf (((symbol-function 'yes-or-no-p) 'ignore)) 3035 (add-name-to-file tmp-name1 tmp-name2)
3002 (should-error 3036 :type 'file-already-exists)
3003 (add-name-to-file tmp-name1 tmp-name2 0) 3037 ;; A number means interactive case.
3004 :type 'file-already-exists)) 3038 (cl-letf (((symbol-function 'yes-or-no-p) 'ignore))
3005 (cl-letf (((symbol-function 'yes-or-no-p) (lambda (_prompt) t))) 3039 (should-error
3040 (add-name-to-file tmp-name1 tmp-name2 0)
3041 :type 'file-already-exists))
3042 (cl-letf (((symbol-function 'yes-or-no-p) (lambda (_prompt) t)))
3006 (add-name-to-file tmp-name1 tmp-name2 0) 3043 (add-name-to-file tmp-name1 tmp-name2 0)
3007 (should (file-regular-p tmp-name2))) 3044 (should (file-regular-p tmp-name2)))
3008 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists) 3045 (add-name-to-file tmp-name1 tmp-name2 'ok-if-already-exists)
3009 (should-not (file-symlink-p tmp-name2)) 3046 (should-not (file-symlink-p tmp-name2))
3010 (should (file-regular-p tmp-name2)) 3047 (should (file-regular-p tmp-name2))
3011 ;; `tmp-name3' is a local file name. 3048 ;; `tmp-name3' is a local file name.
3012 (should-error 3049 (should-error
3013 (add-name-to-file tmp-name1 tmp-name3) 3050 (add-name-to-file tmp-name1 tmp-name3)
3014 :type 'file-error) 3051 :type 'file-error)
3015 ;; Check directory as newname. 3052 ;; Check directory as newname.
3016 (make-directory tmp-name4) 3053 (make-directory tmp-name4)
3017 (should-error 3054 (should-error
3018 (add-name-to-file tmp-name1 tmp-name4) 3055 (add-name-to-file tmp-name1 tmp-name4)
3019 :type 'file-already-exists) 3056 :type 'file-already-exists)
3020 (add-name-to-file tmp-name1 (file-name-as-directory tmp-name4)) 3057 (add-name-to-file tmp-name1 (file-name-as-directory tmp-name4))
3021 (should 3058 (should
3022 (file-regular-p 3059 (file-regular-p
3023 (expand-file-name (file-name-nondirectory tmp-name1) tmp-name4)))) 3060 (expand-file-name
3061 (file-name-nondirectory tmp-name1) tmp-name4)))))
3024 3062
3025 ;; Cleanup. 3063 ;; Cleanup.
3026 (ignore-errors 3064 (ignore-errors
@@ -4669,9 +4707,11 @@ Use the `ls' command."
4669 (setq x (eval (cdr (assoc 'sample-text x)))) 4707 (setq x (eval (cdr (assoc 'sample-text x))))
4670 (unless (or (null x) 4708 (unless (or (null x)
4671 (unencodable-char-position 4709 (unencodable-char-position
4672 nil nil file-name-coding-system nil x) 4710 0 nil file-name-coding-system nil x)
4673 (string-match "TaiViet" x)) 4711 (string-match "TaiViet" x))
4674 (replace-regexp-in-string "[\n/]" "" x))) 4712 ;; ?\n and ?/ shouldn't be part of any file name. ?\t,
4713 ;; ?. and ?? do not work for "smb" method.
4714 (replace-regexp-in-string "[\t\n/.?]" "" x)))
4675 language-info-alist)) 4715 language-info-alist))
4676 4716
4677 (list 4717 (list