(defun tramp-postfix-host-regexp ()
"Regexp matching delimiter between host names and localnames.
-nDerived from `tramp-postfix-host-format'."
+Derived from `tramp-postfix-host-format'."
(regexp-quote (tramp-postfix-host-format)))
(defconst tramp-localname-regexp ".*$"
;; * Use also port to distinguish connections. This is needed for
;; different hosts sitting behind a single router (distinguished by
;; different port numbers). (Tzvi Edelman)
+;; Also needed for different systems serve SSH on different ports of
+;; the same IP address. (Bug#27009)
;;
;; * Refactor code from different handlers. Start with
;; *-process-file. One idea is to generalize `tramp-send-command'
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-args ("-c"))
(tramp-connection-timeout 10)))
+ (add-to-list
+ 'tramp-default-host-alist
+ `("\\`mock\\'" nil ,(system-name)))
(format "/mock::%s" temporary-file-directory)))
"Temporary directory for Tramp tests.")
(regexp-quote envvar)
(funcall this-shell-command-to-string "set")))))))))
+;; This test is inspired by Bug#27009.
+(ert-deftest tramp-test29-environment-variables-and-port-numbers ()
+ "Check that two connections with separate ports are different."
+ ;; Mark as failed until bug has been fixed.
+ :expected-result :failed
+ (skip-unless (tramp--test-enabled))
+ ;; We test it only for the mock-up connection; otherwise there might
+ ;; be problems with the used ports.
+ (skip-unless
+ (and
+ (eq tramp-syntax 'default)
+ (string-equal
+ "mock" (file-remote-p tramp-test-temporary-file-directory 'method))))
+
+ ;; We force a reconnect, in order to have a clean environment.
+ (dolist (dir
+ `(,tramp-test-temporary-file-directory
+ "/mock:localhost#11111:" "/mock:localhost#22222:"))
+ (tramp-cleanup-connection
+ (tramp-dissect-file-name dir) 'keep-debug 'keep-password))
+
+ (dolist (port '(11111 22222))
+ (let* ((default-directory
+ (format "/mock:localhost#%d:%s" port temporary-file-directory))
+ (shell-file-name "/bin/sh")
+ (envvar (concat "VAR_" (upcase (md5 (current-time-string)))))
+ ;; We cannot use `process-environment', because this would
+ ;; be applied in `process-file'.
+ (tramp-remote-process-environment
+ (cons
+ (format "%s=%d" envvar port) tramp-remote-process-environment)))
+ (should
+ (string-equal
+ (number-to-string port)
+ (shell-command-to-string (format "echo -n $%s" envvar)))))))
+
;; The functions were introduced in Emacs 26.1.
(ert-deftest tramp-test30-explicit-shell-file-name ()
"Check that connection-local `explicit-shell-file-name' is set."
;; * Fix `tramp-test05-expand-file-name-relative' in `expand-file-name'.
;; * Fix `tramp-test06-directory-file-name' for `ftp'.
;; * Fix `tramp-test27-start-file-process' on MS Windows (`process-send-eof'?).
+;; * Fix Bug#27009. Set expected error of
+;; `tramp-test29-environment-variables-and-port-numbers'.
;; * Fix Bug#16928. Set expected error of `tramp-test36-asynchronous-requests'.
;; * Fix `tramp-test38-unload' (Not all symbols are unbound). Set
;; expected error.