;; Cleanup.
(ignore-errors (delete-file tmp-name))))))
+;; This test is inspired by Bug#29149.
(ert-deftest tramp-test24-file-acl ()
"Check that `file-acl' and `set-file-acl' work proper."
(skip-unless (tramp--test-enabled))
(ignore-errors (delete-file tmp-name1))
(ignore-errors (delete-file tmp-name3))))))
-;; TODO: This test didn't run in reality yet. Pls report if it
-;; doesn't work as expected.
(ert-deftest tramp-test25-file-selinux ()
"Check `file-selinux-context' and `set-file-selinux-context'."
(skip-unless (tramp--test-enabled))
;; Both files are remote.
(unwind-protect
(progn
- ;; Two files with same SELINUX context.
+ ;; Two files with same SELinux context.
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
(should (file-selinux-context tmp-name1))
(equal
(file-selinux-context tmp-name1)
(file-selinux-context tmp-name2)))
- ;; Different permissions mean different SELINUX context.
- (set-file-modes tmp-name1 #o777)
- (set-file-modes tmp-name2 #o444)
- (should-not
- (equal
- (file-selinux-context tmp-name1)
- (file-selinux-context tmp-name2)))
- ;; Copy SELINUX context.
+ ;; Check different SELinux context. We cannot support
+ ;; different ranges in this test; let's assume the most
+ ;; likely one.
+ (let ((context (file-selinux-context tmp-name1)))
+ (when (and (string-equal (nth 3 context) "s0")
+ (setcar (nthcdr 3 context) "s0:c0")
+ (set-file-selinux-context tmp-name1 context))
+ (should-not
+ (equal
+ (file-selinux-context tmp-name1)
+ (file-selinux-context tmp-name2)))))
+ ;; Copy SELinux context.
(should
(set-file-selinux-context
tmp-name2 (file-selinux-context tmp-name1)))
(equal
(file-selinux-context tmp-name1)
(file-selinux-context tmp-name2)))
- ;; An invalid SELINUX context does not harm.
+ ;; An invalid SELinux context does not harm.
(should-not (set-file-selinux-context tmp-name2 "foo")))
;; Cleanup.
;; Remote and local file.
(unwind-protect
- (when (not (or (equal (file-selinux-context temporary-file-directory)
- '(nil nil nil nil))
- (tramp--test-windows-nt-or-smb-p)))
- ;; Two files with same SELINUX context.
+ (when (and (not
+ (or (equal (file-selinux-context temporary-file-directory)
+ '(nil nil nil nil))
+ (tramp--test-windows-nt-or-smb-p)))
+ ;; Both users shall use the same SELinux context.
+ (string-equal
+ (let ((default-directory temporary-file-directory))
+ (shell-command-to-string "id -Z"))
+ (let ((default-directory
+ tramp-test-temporary-file-directory))
+ (shell-command-to-string "id -Z"))))
+
+ ;; Two files with same SELinux context.
(write-region "foo" nil tmp-name1)
(should (file-exists-p tmp-name1))
(should (file-selinux-context tmp-name1))
(copy-file tmp-name1 tmp-name3)
(should (file-selinux-context tmp-name3))
+ ;; We cannot expect that copying over file system
+ ;; boundaries keeps SELinux context. So we copy it
+ ;; explicitely.
+ (should
+ (set-file-selinux-context
+ tmp-name3 (file-selinux-context tmp-name1)))
(should
(equal
(file-selinux-context tmp-name1)
(file-selinux-context tmp-name3)))
- ;; Different permissions mean different SELINUX context.
- (set-file-modes tmp-name1 #o777)
- (set-file-modes tmp-name3 #o444)
- (should-not
- (equal
- (file-selinux-context tmp-name1)
- (file-selinux-context tmp-name3)))
- ;; Copy SELINUX context.
- (set-file-selinux-context
- tmp-name3 (file-selinux-context tmp-name1))
+ ;; Check different SELinux context. We cannot support
+ ;; different ranges in this test; let's assume the most
+ ;; likely one.
+ (let ((context (file-selinux-context tmp-name1)))
+ (when (and (string-equal (nth 3 context) "s0")
+ (setcar (nthcdr 3 context) "s0:c0")
+ (set-file-selinux-context tmp-name1 context))
+ (should-not
+ (equal
+ (file-selinux-context tmp-name1)
+ (file-selinux-context tmp-name3)))))
+ ;; Copy SELinux context.
+ (should
+ (set-file-selinux-context
+ tmp-name3 (file-selinux-context tmp-name1)))
(should
(equal
(file-selinux-context tmp-name1)
(file-selinux-context tmp-name3)))
- ;; Two files with same SELINUX context.
+ ;; Two files with same SELinux context.
(delete-file tmp-name1)
(copy-file tmp-name3 tmp-name1)
(should (file-selinux-context tmp-name1))
+ ;; We cannot expect that copying over file system
+ ;; boundaries keeps SELinux context. So we copy it
+ ;; explicitely.
+ (should
+ (set-file-selinux-context
+ tmp-name1 (file-selinux-context tmp-name3)))
(should
(equal
(file-selinux-context tmp-name1)
(file-selinux-context tmp-name3)))
- ;; Different permissions mean different SELINUX context.
- (set-file-modes tmp-name1 #o777)
- (set-file-modes tmp-name3 #o444)
- (should-not
- (equal
- (file-selinux-context tmp-name1)
- (file-selinux-context tmp-name3)))
- ;; Copy SELINUX context.
- (set-file-selinux-context
- tmp-name1 (file-selinux-context tmp-name2))
+ ;; Check different SELinux context. We cannot support
+ ;; different ranges in this test; let's assume the most
+ ;; likely one.
+ (let ((context (file-selinux-context tmp-name3)))
+ (when (and (string-equal (nth 3 context) "s0")
+ (setcar (nthcdr 3 context) "s0:c0")
+ (set-file-selinux-context tmp-name3 context))
+ (should-not
+ (equal
+ (file-selinux-context tmp-name1)
+ (file-selinux-context tmp-name3)))))
+ ;; Copy SELinux context.
+ (should
+ (set-file-selinux-context
+ tmp-name1 (file-selinux-context tmp-name3)))
(should
(equal
(file-selinux-context tmp-name1)
(fboundp 'connection-local-set-profiles)))
;; `connection-local-set-profile-variables' and
- ;; `connection-local-set-profiles' exist since Emacs 26. We don't
+ ;; `connection-local-set-profiles' exist since Emacs 26.1. We don't
;; want to see compiler warnings for older Emacsen.
(let ((default-directory tramp-test-temporary-file-directory)
explicit-shell-file-name kill-buffer-query-functions)
(and (fboundp 'make-nearby-temp-file) (fboundp 'temporary-file-directory)))
;; `make-nearby-temp-file' and `temporary-file-directory' exists
- ;; since Emacs 26. We don't want to see compiler warnings for older
- ;; Emacsen.
+ ;; since Emacs 26.1. We don't want to see compiler warnings for
+ ;; older Emacsen.
(let ((default-directory tramp-test-temporary-file-directory)
tmp-file)
;; The remote host shall know a temporary file directory.
(message \"Tramp loaded: %%s\" (featurep 'tramp)) \
(file-name-all-completions \"/foo:\" \"/\") \
(message \"Tramp loaded: %%s\" (featurep 'tramp)))"))
- (dolist (tm '(t nil))
+ ;; Tramp doesn't load when `tramp-mode' is nil since Emacs 26.1.
+ (dolist (tm (if (tramp--test-emacs26-p) '(t nil) '(nil)))
(should
(string-match
(format