Vagrantfile 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. Vagrant.configure("2") do |config|
  2. config.vm.provider "virtualbox" do |v|
  3. v.memory = 1024
  4. v.cpus = 1
  5. end
  6. config.vm.box = "debian/jessie64"
  7. config.vm.hostname = "exa"
  8. # Install the dependencies needed for exa to build.
  9. config.vm.provision :shell, privileged: true, inline:
  10. %[apt-get install -y git cmake libssl-dev libgit2-dev libssh2-1-dev curl attr pkg-config]
  11. # Guarantee that the timezone is UTC -- some of the tests
  12. # depend on this (for now).
  13. config.vm.provision :shell, privileged: true, inline:
  14. %[timedatectl set-timezone UTC]
  15. # Install Rust.
  16. # This is done as vagrant, not root, because it’s vagrant
  17. # who actually uses it. Sent to /dev/null because the progress
  18. # bar produces a ton of output.
  19. config.vm.provision :shell, privileged: false, inline:
  20. %[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
  21. # Use a different ‘target’ directory on the VM than on the host.
  22. # By default it just uses the one in /vagrant/target, which can
  23. # cause problems if it has different permissions than the other
  24. # directories, or contains object files compiled for the host.
  25. config.vm.provision :shell, privileged: false, inline:
  26. %[echo "export CARGO_TARGET_DIR=/home/ubuntu/target" >> ~/.bashrc]
  27. # We create two users that own the test files.
  28. # The first one just owns the ordinary ones, because we don’t want to
  29. # depend on “vagrant” or “ubuntu” existing.
  30. user = "cassowary"
  31. config.vm.provision :shell, privileged: true, inline:
  32. %[id -u #{user} &>/dev/null || useradd #{user}]
  33. # The second one has a long name, to test that the file owner column
  34. # widens correctly. The benefit of Vagrant is that we don’t need to
  35. # set this up on the *actual* system!
  36. longuser = "antidisestablishmentarienism"
  37. config.vm.provision :shell, privileged: true, inline:
  38. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  39. # Because the timestamps are formatted differently depending on whether
  40. # they’re in the current year or not (see `details.rs`), we have to make
  41. # sure that the files are created in the current year, so they get shown
  42. # in the format we expect.
  43. current_year = Date.today.year
  44. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  45. # We also need an UID and a GID that are guaranteed to not exist, to
  46. # test what happen when they don’t.
  47. invalid_uid = 666
  48. invalid_gid = 616
  49. # Delete old testcases if they exist already, then create a
  50. # directory to house new ones.
  51. test_dir = "/testcases"
  52. config.vm.provision :shell, privileged: true, inline: <<-EOF
  53. set -xe
  54. rm -rfv #{test_dir}
  55. mkdir #{test_dir}
  56. chmod 777 #{test_dir}
  57. EOF
  58. # Awkward file size testcases.
  59. # This needs sudo to set the files’ users at the very end.
  60. config.vm.provision :shell, privileged: false, inline: <<-EOF
  61. set -xe
  62. mkdir "#{test_dir}/files"
  63. for i in {1..13}; do
  64. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  65. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  66. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  67. done
  68. touch -t #{some_date} "#{test_dir}/files/"*
  69. chmod 644 "#{test_dir}/files/"*
  70. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  71. EOF
  72. # File name extension testcases.
  73. # These are tested in grid view, so we don’t need to bother setting
  74. # owners or timestamps or anything.
  75. config.vm.provision :shell, privileged: false, inline: <<-EOF
  76. set -xe
  77. mkdir "#{test_dir}/file-types"
  78. touch "#{test_dir}/file-types/Makefile"
  79. touch "#{test_dir}/file-types/image.png"
  80. touch "#{test_dir}/file-types/image.svg"
  81. touch "#{test_dir}/file-types/video.avi"
  82. touch "#{test_dir}/file-types/video.wmv"
  83. touch "#{test_dir}/file-types/music.mp3"
  84. touch "#{test_dir}/file-types/music.ogg"
  85. touch "#{test_dir}/file-types/lossless.flac"
  86. touch "#{test_dir}/file-types/lossless.wav"
  87. touch "#{test_dir}/file-types/crypto.asc"
  88. touch "#{test_dir}/file-types/crypto.signature"
  89. touch "#{test_dir}/file-types/document.pdf"
  90. touch "#{test_dir}/file-types/document.xlsx"
  91. touch "#{test_dir}/file-types/compressed.zip"
  92. touch "#{test_dir}/file-types/compressed.tar.gz"
  93. touch "#{test_dir}/file-types/compressed.tgz"
  94. touch "#{test_dir}/file-types/backup~"
  95. touch "#{test_dir}/file-types/#SAVEFILE#"
  96. touch "#{test_dir}/file-types/file.tmp"
  97. touch "#{test_dir}/file-types/compiled.class"
  98. touch "#{test_dir}/file-types/compiled.o"
  99. touch "#{test_dir}/file-types/compiled.js"
  100. touch "#{test_dir}/file-types/compiled.coffee"
  101. EOF
  102. # Awkward symlink testcases.
  103. config.vm.provision :shell, privileged: false, inline: <<-EOF
  104. set -xe
  105. mkdir "#{test_dir}/links"
  106. ln -s / "#{test_dir}/links/root"
  107. ln -s /usr "#{test_dir}/links/usr"
  108. ln -s nowhere "#{test_dir}/links/broken"
  109. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  110. EOF
  111. # Awkward passwd testcases.
  112. # sudo is needed for these because we technically aren’t a member
  113. # of the groups (because they don’t exist), and chown and chgrp
  114. # are smart enough to disallow it!
  115. config.vm.provision :shell, privileged: false, inline: <<-EOF
  116. set -xe
  117. mkdir "#{test_dir}/passwd"
  118. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  119. chmod 644 "#{test_dir}/passwd/unknown-uid"
  120. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  121. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  122. chmod 644 "#{test_dir}/passwd/unknown-gid"
  123. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  124. EOF
  125. # Awkward permission testcases.
  126. config.vm.provision :shell, privileged: false, inline: <<-EOF
  127. set -xe
  128. mkdir "#{test_dir}/permissions"
  129. touch "#{test_dir}/permissions/all-permissions"
  130. chmod 777 "#{test_dir}/permissions/all-permissions"
  131. touch "#{test_dir}/permissions/no-permissions"
  132. chmod 000 "#{test_dir}/permissions/no-permissions"
  133. mkdir "#{test_dir}/permissions/forbidden-directory"
  134. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  135. for perms in 001 002 004 010 020 040 100 200 400; do
  136. touch "#{test_dir}/permissions/$perms"
  137. chmod $perms "#{test_dir}/permissions/$perms"
  138. done
  139. touch -t #{some_date} "#{test_dir}/permissions/"*
  140. sudo chown #{user}:#{user} "#{test_dir}/permissions/"*
  141. EOF
  142. # Awkward extended attribute testcases.
  143. config.vm.provision :shell, privileged: false, inline: <<-EOF
  144. set -xe
  145. mkdir "#{test_dir}/attributes"
  146. touch "#{test_dir}/attributes/none"
  147. touch "#{test_dir}/attributes/one"
  148. setfattr -n user.greeting -v hello "#{test_dir}/attributes/one"
  149. touch "#{test_dir}/attributes/two"
  150. setfattr -n user.greeting -v hello "#{test_dir}/attributes/two"
  151. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes/two"
  152. #touch "#{test_dir}/attributes/forbidden"
  153. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/forbidden"
  154. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/forbidden"
  155. mkdir "#{test_dir}/attributes/dirs"
  156. mkdir "#{test_dir}/attributes/dirs/empty-with-attribute"
  157. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/empty-with-attribute"
  158. mkdir "#{test_dir}/attributes/dirs/full-with-attribute"
  159. touch "#{test_dir}/attributes/dirs/full-with-attribute/file"
  160. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-with-attribute"
  161. mkdir "#{test_dir}/attributes/dirs/full-but-forbidden"
  162. touch "#{test_dir}/attributes/dirs/full-but-forbidden/file"
  163. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-but-forbidden"
  164. #chmod 000 "#{test_dir}/attributes/dirs/full-but-forbidden"
  165. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/dirs/full-but-forbidden"
  166. touch -t #{some_date} "#{test_dir}/attributes"
  167. touch -t #{some_date} "#{test_dir}/attributes/"*
  168. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*
  169. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*/*
  170. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  171. EOF
  172. end