aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2018-12-06 15:25:22 +0100
committerMichael Albinus2018-12-06 15:25:22 +0100
commit8f3fde3884d818eb2eef39f8295c5884bc371cc4 (patch)
tree4d07b579f77263a2f7f04bd7b12f318d87a84ae3
parent8e8b8115386570ce186eea349ae937dbccbd61ed (diff)
downloademacs-8f3fde3884d818eb2eef39f8295c5884bc371cc4.tar.gz
emacs-8f3fde3884d818eb2eef39f8295c5884bc371cc4.zip
Make stronger tests for Tramp multi hops
* lisp/net/tramp.el (tramp-dissect-file-name, tramp-dissect-hop-name): Check, that method is capable of multi hops. * test/lisp/net/tramp-tests.el (tramp-test02-file-name-dissect) (tramp-test02-file-name-dissect-simplified) (tramp-test02-file-name-dissect-separate): Suppress check for multihops. (tramp-test03-file-name-method-rules): Check for error if multi hops cannot be applied.
-rw-r--r--lisp/net/tramp.el35
-rw-r--r--test/lisp/net/tramp-tests.el21
2 files changed, 46 insertions, 10 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index fe0ba94f4c7..ab30a43de0d 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1391,19 +1391,36 @@ default values are used."
1391 (and hop 1391 (and hop
1392 (format-spec hop (format-spec-make ?h host ?u user)))))) 1392 (format-spec hop (format-spec-make ?h host ?u user))))))
1393 1393
1394 (make-tramp-file-name 1394 ;; Return result.
1395 :method method :user user :domain domain :host host :port port 1395 (prog1
1396 :localname localname :hop hop))))) 1396 (setq v (make-tramp-file-name
1397 :method method :user user :domain domain :host host
1398 :port port :localname localname :hop hop))
1399 ;; Only some methods from tramp-sh.el do support multi-hops.
1400 (when (and
1401 hop
1402 (or (not (tramp-get-method-parameter v 'tramp-login-program))
1403 (tramp-get-method-parameter v 'tramp-copy-program)))
1404 (tramp-user-error
1405 v "Method `%s' is not supported for multi-hops." method)))))))
1397 1406
1398(defun tramp-dissect-hop-name (name &optional nodefault) 1407(defun tramp-dissect-hop-name (name &optional nodefault)
1399 "Return a `tramp-file-name' structure of `hop' part of NAME. 1408 "Return a `tramp-file-name' structure of `hop' part of NAME.
1400See `tramp-dissect-file-name' for details." 1409See `tramp-dissect-file-name' for details."
1401 (tramp-dissect-file-name 1410 (let ((v (tramp-dissect-file-name
1402 (concat 1411 (concat tramp-prefix-format
1403 tramp-prefix-format 1412 (replace-regexp-in-string
1404 (replace-regexp-in-string 1413 (concat tramp-postfix-hop-regexp "$")
1405 (concat tramp-postfix-hop-regexp "$") tramp-postfix-host-format name)) 1414 tramp-postfix-host-format name))
1406 nodefault)) 1415 nodefault)))
1416 ;; Only some methods from tramp-sh.el do support multi-hops.
1417 (when (or (not (tramp-get-method-parameter v 'tramp-login-program))
1418 (tramp-get-method-parameter v 'tramp-copy-program))
1419 (tramp-user-error
1420 v "Method `%s' is not supported for multi-hops."
1421 (tramp-file-name-method v)))
1422 ;; Return result.
1423 v))
1407 1424
1408(defun tramp-buffer-name (vec) 1425(defun tramp-buffer-name (vec)
1409 "A name for the connection buffer VEC." 1426 "A name for the connection buffer VEC."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 4016ece94d3..15a120704eb 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -399,7 +399,10 @@ handled properly. BODY shall not contain a timeout."
399 (tramp-default-host "default-host") 399 (tramp-default-host "default-host")
400 tramp-default-method-alist 400 tramp-default-method-alist
401 tramp-default-user-alist 401 tramp-default-user-alist
402 tramp-default-host-alist) 402 tramp-default-host-alist
403 ;; Suppress check for multihops.
404 (tramp-cache-data (make-hash-table :test 'equal))
405 (tramp-connection-properties '((nil "login-program" t))))
403 ;; Expand `tramp-default-user' and `tramp-default-host'. 406 ;; Expand `tramp-default-user' and `tramp-default-host'.
404 (should (string-equal 407 (should (string-equal
405 (file-remote-p "/method::") 408 (file-remote-p "/method::")
@@ -836,6 +839,9 @@ handled properly. BODY shall not contain a timeout."
836 (tramp-default-host "default-host") 839 (tramp-default-host "default-host")
837 tramp-default-user-alist 840 tramp-default-user-alist
838 tramp-default-host-alist 841 tramp-default-host-alist
842 ;; Suppress check for multihops.
843 (tramp-cache-data (make-hash-table :test 'equal))
844 (tramp-connection-properties '((nil "login-program" t)))
839 (syntax tramp-syntax)) 845 (syntax tramp-syntax))
840 (unwind-protect 846 (unwind-protect
841 (progn 847 (progn
@@ -1157,6 +1163,9 @@ handled properly. BODY shall not contain a timeout."
1157 tramp-default-method-alist 1163 tramp-default-method-alist
1158 tramp-default-user-alist 1164 tramp-default-user-alist
1159 tramp-default-host-alist 1165 tramp-default-host-alist
1166 ;; Suppress check for multihops.
1167 (tramp-cache-data (make-hash-table :test 'equal))
1168 (tramp-connection-properties '((nil "login-program" t)))
1160 (syntax tramp-syntax)) 1169 (syntax tramp-syntax))
1161 (unwind-protect 1170 (unwind-protect
1162 (progn 1171 (progn
@@ -1851,6 +1860,16 @@ handled properly. BODY shall not contain a timeout."
1851(ert-deftest tramp-test03-file-name-method-rules () 1860(ert-deftest tramp-test03-file-name-method-rules ()
1852 "Check file name rules for some methods." 1861 "Check file name rules for some methods."
1853 (skip-unless (tramp--test-enabled)) 1862 (skip-unless (tramp--test-enabled))
1863 ;; `user-error' has appeared in Emacs 24.3.
1864 (skip-unless (fboundp 'user-error))
1865
1866 ;; Multi hops are allowed for inline methods only.
1867 (should-error
1868 (file-remote-p "/ssh:user1@host1|method:user2@host2:/path/to/file")
1869 :type 'user-error)
1870 (should-error
1871 (file-remote-p "/method:user1@host1|ssh:user2@host2:/path/to/file")
1872 :type 'user-error)
1854 1873
1855 ;; Samba does not support file names with periods followed by 1874 ;; Samba does not support file names with periods followed by
1856 ;; spaces, and trailing periods or spaces. 1875 ;; spaces, and trailing periods or spaces.