;; remote host, set this environment variable to "/dev/null" or
;; whatever is appropriate on your system.
+;; All temporary Tramp test files are removed prior test run.
+;; Therefore, two test runs cannot be performed in parallel.
+
+;; The environment variable $TRAMP_TEST_CLEANUP_TEMP_FILES, when set,
+;; forces the removal of all temporary Tramp files prior test run.
+;; This shouldn't be set if the test suite runs in parallel using
+;; Tramp on a production system.
+
;; For slow remote connections, `tramp-test45-asynchronous-requests'
;; might be too heavy. Setting $REMOTE_PARALLEL_PROCESSES to a proper
;; value less than 10 could help.
(tramp-dissect-file-name ert-remote-temporary-file-directory))
"The used `tramp-file-name' structure.")
-(setq auth-source-save-behavior nil
+(setq auth-source-cache-expiry nil
+ auth-source-save-behavior nil
password-cache-expiry nil
remote-file-name-inhibit-cache nil
tramp-allow-unsafe-temporary-files t
tramp-persistency-file-name nil
tramp-verbose 0)
-(defvar tramp--test-enabled-checked nil
- "Cached result of `tramp--test-enabled'.
-If the function did run, the value is a cons cell, the `cdr'
-being the result.")
-
-(defun tramp--test-enabled ()
- "Whether remote file access is enabled."
- (unless (consp tramp--test-enabled-checked)
- (setq
- tramp--test-enabled-checked
- (cons
- t (ignore-errors
- (and
- (file-remote-p ert-remote-temporary-file-directory)
- (file-directory-p ert-remote-temporary-file-directory)
- (file-writable-p ert-remote-temporary-file-directory))))))
-
- (when (cdr tramp--test-enabled-checked)
- ;; Remove old test files.
- (dolist (dir `(,temporary-file-directory
- ,tramp-compat-temporary-file-directory
- ,ert-remote-temporary-file-directory))
- (dolist (file (directory-files dir 'full (rx bos (? ".#") "tramp-test")))
- (ignore-errors
- (if (file-directory-p file)
- (delete-directory file 'recursive)
- (delete-file file)))))
- ;; Cleanup connection.
- (ignore-errors
- (tramp-cleanup-connection tramp-test-vec nil 'keep-password)))
-
- ;; Return result.
- (cdr tramp--test-enabled-checked))
+(defconst tramp-test-name-prefix "tramp-test"
+ "Prefix to use for temporary test files.")
(defun tramp--test-make-temp-name (&optional local quoted)
"Return a temporary file name for test.
(funcall
(if quoted #'file-name-quote #'identity)
(expand-file-name
- (make-temp-name "tramp-test")
+ (make-temp-name tramp-test-name-prefix)
(if local temporary-file-directory ert-remote-temporary-file-directory))))
;; Method "smb" supports `make-symbolic-link' only if the remote host
(tramp--test-message
"%s %f sec" ,message (float-time (time-subtract nil start))))))
+(defvar tramp--test-enabled-checked nil
+ "Cached result of `tramp--test-enabled'.
+If the function did run, the value is a cons cell, the `cdr'
+being the result.")
+
+(defun tramp--test-enabled ()
+ "Whether remote file access is enabled."
+ (unless (consp tramp--test-enabled-checked)
+ (setq
+ tramp--test-enabled-checked
+ (cons
+ t (ignore-errors
+ (and
+ (file-remote-p ert-remote-temporary-file-directory)
+ (file-directory-p ert-remote-temporary-file-directory)
+ (file-writable-p ert-remote-temporary-file-directory))))))
+
+ (when (cdr tramp--test-enabled-checked)
+ ;; Remove old test files.
+ (dolist (dir `(,temporary-file-directory
+ ,tramp-compat-temporary-file-directory
+ ,ert-remote-temporary-file-directory))
+ (dolist
+ (file
+ (directory-files
+ dir 'full
+ (rx bos (? ".#")
+ (| (literal tramp-test-name-prefix)
+ (eval (if (getenv "TRAMP_TEST_CLEANUP_TEMP_FILES")
+ tramp-temp-name-prefix 'unmatchable))))))
+
+ ;; Exclude sockets and FUSE mount points.
+ (ignore-errors
+ (unless
+ (or (string-prefix-p
+ "srw" (file-attribute-modes (file-attributes file)))
+ (string-match-p (rx bos (literal tramp-fuse-name-prefix)
+ (regexp tramp-method-regexp) ".")
+ (file-name-nondirectory file)))
+ (tramp--test-message "Delete %s" file)
+ (if (file-directory-p file)
+ (delete-directory file 'recursive)
+ (delete-file file))))))
+ ;; Cleanup connection.
+ (ignore-errors
+ (tramp-cleanup-connection tramp-test-vec nil 'keep-password)))
+
+ ;; Return result.
+ (cdr tramp--test-enabled-checked))
+
(ert-deftest tramp-test00-availability ()
"Test availability of Tramp functions."
:expected-result (if (tramp--test-enabled) :passed :failed)
;; Suppress check for multihops.
(tramp-cache-data (make-hash-table :test #'equal))
(tramp-connection-properties '((nil "login-program" t)))
- (syntax tramp-syntax))
+ (syntax tramp-syntax)
+ ;; We must transform `tramp-crypt-directories'.
+ (tramp-crypt-directories
+ (mapcar #'tramp-dissect-file-name tramp-crypt-directories)))
(unwind-protect
(progn
(tramp-change-syntax 'separate)
+ ;; We must transform `tramp-crypt-directories'.
+ (setq tramp-crypt-directories
+ (mapcar
+ (lambda (vec)
+ (tramp-make-tramp-file-name
+ vec (tramp-file-name-localname vec)))
+ tramp-crypt-directories))
;; An unknown method shall raise an error.
(let (non-essential)
(should-error
(when (assoc m tramp-methods)
(let (tramp-connection-properties tramp-default-proxies-alist)
(ignore-errors
- (tramp-cleanup-connection tramp-test-vec nil 'keep-password))
+ (tramp-cleanup-connection tramp-test-vec 'keep-debug 'keep-password))
;; Single hop. The host name must match `tramp-local-host-regexp'.
(should-error
(find-file (format "/%s:foo:" m))
(file-remote-p (temporary-file-directory))))
;; The temporary file shall be located on the remote host.
- (setq tmp-file (make-nearby-temp-file "tramp-test"))
+ (setq tmp-file (make-nearby-temp-file tramp-test-name-prefix))
(should (file-exists-p tmp-file))
(should (file-regular-p tmp-file))
(should
(delete-file tmp-file)
(should-not (file-exists-p tmp-file))
- (setq tmp-file (make-nearby-temp-file "tramp-test" 'dir))
+ (setq tmp-file (make-nearby-temp-file tramp-test-name-prefix 'dir))
(should (file-exists-p tmp-file))
(should (file-directory-p tmp-file))
(delete-directory tmp-file)
(let ((pass "secret")
(mock-entry (copy-tree (assoc "mock" tramp-methods)))
- mocked-input tramp-methods)
+ mocked-input tramp-methods auth-sources)
;; We must mock `read-string', in order to avoid interactive
;; arguments.
(cl-letf* (((symbol-function #'read-string)
(setq mocked-input nil)
(auth-source-forget-all-cached)
(ert-with-temp-file netrc-file
- :prefix "tramp-test" :suffix ""
+ :prefix tramp-test-name-prefix :suffix ""
:text (format
"machine %s port mock password %s"
(file-remote-p ert-remote-temporary-file-directory 'host) pass)
(let ((auth-sources `(,netrc-file)))
- (should (file-exists-p ert-remote-temporary-file-directory)))))))))
+ (should (file-exists-p ert-remote-temporary-file-directory))))))
+
+ ;; Checking session-timeout.
+ (with-no-warnings (when (symbol-plist 'ert-with-temp-file)
+ (tramp-cleanup-connection tramp-test-vec 'keep-debug)
+ (let ((tramp-connection-properties
+ (cons '(nil "session-timeout" 1)
+ tramp-connection-properties)))
+ (setq mocked-input nil)
+ (auth-source-forget-all-cached)
+ (ert-with-temp-file netrc-file
+ :prefix tramp-test-name-prefix :suffix ""
+ :text (format
+ "machine %s port mock password %s"
+ (file-remote-p ert-remote-temporary-file-directory 'host)
+ pass)
+ (let ((auth-sources `(,netrc-file)))
+ (should (file-exists-p ert-remote-temporary-file-directory))))
+ ;; Session established, password cached.
+ (should
+ (password-in-cache-p
+ (auth-source-format-cache-entry
+ (tramp-get-connection-property tramp-test-vec " pw-spec"))))
+ ;; We want to see the timeout message.
+ (tramp--test-instrument-test-case 3
+ (sleep-for 2))
+ ;; Session cancelled, no password in cache.
+ (should-not
+ (password-in-cache-p
+ (auth-source-format-cache-entry
+ (tramp-get-connection-property tramp-test-vec " pw-spec"))))))))))
(ert-deftest tramp-test47-read-otp-password ()
"Check Tramp one-time password handling."
(setq mocked-input nil)
(auth-source-forget-all-cached)
(ert-with-temp-file netrc-file
- :prefix "tramp-test" :suffix ""
+ :prefix tramp-test-name-prefix :suffix ""
:text (format
"machine %s port mock password %s"
(file-remote-p ert-remote-temporary-file-directory 'host)