Vagrantfile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. require 'date'
  2. Vagrant.configure(2) do |config|
  3. config.vm.provider :virtualbox do |v|
  4. v.name = 'exa'
  5. v.memory = 1024
  6. v.cpus = 1
  7. end
  8. # We use Ubuntu instead of Debian because the image comes with two-way
  9. # shared folder support by default.
  10. config.vm.box = 'ubuntu/xenial64'
  11. config.vm.hostname = 'exa'
  12. # Install the dependencies needed for exa to build, as quietly as
  13. # apt can do.
  14. config.vm.provision :shell, privileged: true, inline:
  15. %[apt-get install -qq -o=Dpkg::Use-Pty=0 -y git cmake libssl-dev libgit2-dev libssh2-1-dev curl attr pkg-config]
  16. # Guarantee that the timezone is UTC -- some of the tests
  17. # depend on this (for now).
  18. config.vm.provision :shell, privileged: true, inline:
  19. %[timedatectl set-timezone UTC]
  20. # Install Rust.
  21. # This is done as vagrant, not root, because it’s vagrant
  22. # who actually uses it. Sent to /dev/null because the progress
  23. # bar produces a ton of output.
  24. config.vm.provision :shell, privileged: false, inline:
  25. %[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
  26. # Use a different ‘target’ directory on the VM than on the host.
  27. # By default it just uses the one in /vagrant/target, which can
  28. # cause problems if it has different permissions than the other
  29. # directories, or contains object files compiled for the host.
  30. config.vm.provision :shell, privileged: false, inline:
  31. %[echo "export CARGO_TARGET_DIR=/home/ubuntu/target" >> ~/.bashrc]
  32. # We create two users that own the test files.
  33. # The first one just owns the ordinary ones, because we don’t want to
  34. # depend on “vagrant” or “ubuntu” existing.
  35. user = "cassowary"
  36. config.vm.provision :shell, privileged: true, inline:
  37. %[id -u #{user} &>/dev/null || useradd #{user}]
  38. # The second one has a long name, to test that the file owner column
  39. # widens correctly. The benefit of Vagrant is that we don’t need to
  40. # set this up on the *actual* system!
  41. longuser = "antidisestablishmentarienism"
  42. config.vm.provision :shell, privileged: true, inline:
  43. %[id -u #{longuser} &>/dev/null || useradd #{longuser}]
  44. # Because the timestamps are formatted differently depending on whether
  45. # they’re in the current year or not (see `details.rs`), we have to make
  46. # sure that the files are created in the current year, so they get shown
  47. # in the format we expect.
  48. current_year = Date.today.year
  49. some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
  50. # We also need an UID and a GID that are guaranteed to not exist, to
  51. # test what happen when they don’t.
  52. invalid_uid = 666
  53. invalid_gid = 616
  54. # Delete old testcases if they exist already, then create a
  55. # directory to house new ones.
  56. test_dir = "/testcases"
  57. config.vm.provision :shell, privileged: true, inline: <<-EOF
  58. set -xe
  59. rm -rfv #{test_dir}
  60. mkdir #{test_dir}
  61. chmod 777 #{test_dir}
  62. EOF
  63. # Awkward file size testcases.
  64. # This needs sudo to set the files’ users at the very end.
  65. config.vm.provision :shell, privileged: false, inline: <<-EOF
  66. set -xe
  67. mkdir "#{test_dir}/files"
  68. for i in {1..13}; do
  69. fallocate -l "$i" "#{test_dir}/files/$i"_bytes
  70. fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
  71. fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
  72. done
  73. touch -t #{some_date} "#{test_dir}/files/"*
  74. chmod 644 "#{test_dir}/files/"*
  75. sudo chown #{user}:#{user} "#{test_dir}/files/"*
  76. EOF
  77. # File name extension testcases.
  78. # These are tested in grid view, so we don’t need to bother setting
  79. # owners or timestamps or anything.
  80. config.vm.provision :shell, privileged: false, inline: <<-EOF
  81. set -xe
  82. mkdir "#{test_dir}/file-names-exts"
  83. touch "#{test_dir}/file-names-exts/Makefile"
  84. touch "#{test_dir}/file-names-exts/image.png"
  85. touch "#{test_dir}/file-names-exts/image.svg"
  86. touch "#{test_dir}/file-names-exts/video.avi"
  87. touch "#{test_dir}/file-names-exts/video.wmv"
  88. touch "#{test_dir}/file-names-exts/music.mp3"
  89. touch "#{test_dir}/file-names-exts/music.ogg"
  90. touch "#{test_dir}/file-names-exts/lossless.flac"
  91. touch "#{test_dir}/file-names-exts/lossless.wav"
  92. touch "#{test_dir}/file-names-exts/crypto.asc"
  93. touch "#{test_dir}/file-names-exts/crypto.signature"
  94. touch "#{test_dir}/file-names-exts/document.pdf"
  95. touch "#{test_dir}/file-names-exts/document.xlsx"
  96. touch "#{test_dir}/file-names-exts/compressed.zip"
  97. touch "#{test_dir}/file-names-exts/compressed.tar.gz"
  98. touch "#{test_dir}/file-names-exts/compressed.tgz"
  99. touch "#{test_dir}/file-names-exts/backup~"
  100. touch "#{test_dir}/file-names-exts/#SAVEFILE#"
  101. touch "#{test_dir}/file-names-exts/file.tmp"
  102. touch "#{test_dir}/file-names-exts/compiled.class"
  103. touch "#{test_dir}/file-names-exts/compiled.o"
  104. touch "#{test_dir}/file-names-exts/compiled.js"
  105. touch "#{test_dir}/file-names-exts/compiled.coffee"
  106. EOF
  107. # File name testcases.
  108. # bash really doesn’t want you to create a file with escaped characters
  109. # in its name, so we have to resort to the echo builtin and touch!
  110. #
  111. # The double backslashes are not strictly necessary; without them, Ruby
  112. # will interpolate them instead of bash, but because Vagrant prints out
  113. # each command it runs, your *own* terminal will go “ding” from the alarm!
  114. config.vm.provision :shell, privileged: false, inline: <<-EOF
  115. set -xe
  116. mkdir "#{test_dir}/file-names"
  117. echo -ne "#{test_dir}/file-names/ascii: hello" | xargs -0 touch
  118. echo -ne "#{test_dir}/file-names/emoji: [🆒]" | xargs -0 touch
  119. echo -ne "#{test_dir}/file-names/utf-8: pâté" | xargs -0 touch
  120. echo -ne "#{test_dir}/file-names/bell: [\\a]" | xargs -0 touch
  121. echo -ne "#{test_dir}/file-names/backspace: [\\b]" | xargs -0 touch
  122. echo -ne "#{test_dir}/file-names/form-feed: [\\f]" | xargs -0 touch
  123. echo -ne "#{test_dir}/file-names/new-line: [\\n]" | xargs -0 touch
  124. echo -ne "#{test_dir}/file-names/return: [\\r]" | xargs -0 touch
  125. echo -ne "#{test_dir}/file-names/tab: [\\t]" | xargs -0 touch
  126. echo -ne "#{test_dir}/file-names/vertical-tab: [\\v]" | xargs -0 touch
  127. echo -ne "#{test_dir}/file-names/escape: [\\033]" | xargs -0 touch
  128. echo -ne "#{test_dir}/file-names/ansi: [\\033[34mblue\\033[0m]" | xargs -0 touch
  129. echo -ne "#{test_dir}/file-names/invalid-utf8-1: [\\xFF]" | xargs -0 touch
  130. echo -ne "#{test_dir}/file-names/invalid-utf8-2: [\\xc3\\x28]" | xargs -0 touch
  131. echo -ne "#{test_dir}/file-names/invalid-utf8-3: [\\xe2\\x82\\x28]" | xargs -0 touch
  132. echo -ne "#{test_dir}/file-names/invalid-utf8-4: [\\xf0\\x28\\x8c\\x28]" | xargs -0 touch
  133. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]" | xargs -0 mkdir
  134. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/subfile" | xargs -0 touch
  135. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/another: [\\n]" | xargs -0 touch
  136. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 touch
  137. mkdir "#{test_dir}/file-names/links"
  138. ln -s "#{test_dir}/file-names/new-line-dir"*/* "#{test_dir}/file-names/links"
  139. echo -ne "#{test_dir}/file-names/new-line-dir: [\\n]/broken" | xargs -0 rm
  140. EOF
  141. # Special file testcases.
  142. config.vm.provision :shell, privileged: false, inline: <<-EOF
  143. set -xe
  144. mkdir "#{test_dir}/specials"
  145. sudo mknod "#{test_dir}/specials/block-device" b 3 60
  146. sudo mknod "#{test_dir}/specials/char-device" c 14 40
  147. sudo mknod "#{test_dir}/specials/named-pipe" p
  148. sudo touch -t #{some_date} "#{test_dir}/specials/"*
  149. EOF
  150. # Awkward symlink testcases.
  151. config.vm.provision :shell, privileged: false, inline: <<-EOF
  152. set -xe
  153. mkdir "#{test_dir}/links"
  154. ln -s / "#{test_dir}/links/root"
  155. ln -s /usr "#{test_dir}/links/usr"
  156. ln -s nowhere "#{test_dir}/links/broken"
  157. ln -s /proc/1/root "#{test_dir}/links/forbidden"
  158. touch "#{test_dir}/links/some_file"
  159. ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
  160. (cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
  161. (cd "#{test_dir}/links"; ln -s "." "current_dir")
  162. (cd "#{test_dir}/links"; ln -s ".." "parent_dir")
  163. (cd "#{test_dir}/links"; ln -s "itself" "itself")
  164. EOF
  165. # Awkward passwd testcases.
  166. # sudo is needed for these because we technically aren’t a member
  167. # of the groups (because they don’t exist), and chown and chgrp
  168. # are smart enough to disallow it!
  169. config.vm.provision :shell, privileged: false, inline: <<-EOF
  170. set -xe
  171. mkdir "#{test_dir}/passwd"
  172. touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
  173. chmod 644 "#{test_dir}/passwd/unknown-uid"
  174. sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
  175. touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
  176. chmod 644 "#{test_dir}/passwd/unknown-gid"
  177. sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
  178. EOF
  179. # Awkward permission testcases.
  180. config.vm.provision :shell, privileged: false, inline: <<-EOF
  181. set -xe
  182. mkdir "#{test_dir}/permissions"
  183. touch "#{test_dir}/permissions/all-permissions"
  184. chmod 777 "#{test_dir}/permissions/all-permissions"
  185. touch "#{test_dir}/permissions/no-permissions"
  186. chmod 000 "#{test_dir}/permissions/no-permissions"
  187. mkdir "#{test_dir}/permissions/forbidden-directory"
  188. chmod 000 "#{test_dir}/permissions/forbidden-directory"
  189. for perms in 001 002 004 010 020 040 100 200 400; do
  190. touch "#{test_dir}/permissions/$perms"
  191. chmod $perms "#{test_dir}/permissions/$perms"
  192. done
  193. touch -t #{some_date} "#{test_dir}/permissions/"*
  194. sudo chown #{user}:#{user} "#{test_dir}/permissions/"*
  195. EOF
  196. # Awkward extended attribute testcases.
  197. config.vm.provision :shell, privileged: false, inline: <<-EOF
  198. set -xe
  199. mkdir "#{test_dir}/attributes"
  200. touch "#{test_dir}/attributes/none"
  201. touch "#{test_dir}/attributes/one"
  202. setfattr -n user.greeting -v hello "#{test_dir}/attributes/one"
  203. touch "#{test_dir}/attributes/two"
  204. setfattr -n user.greeting -v hello "#{test_dir}/attributes/two"
  205. setfattr -n user.another_greeting -v hi "#{test_dir}/attributes/two"
  206. #touch "#{test_dir}/attributes/forbidden"
  207. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/forbidden"
  208. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/forbidden"
  209. mkdir "#{test_dir}/attributes/dirs"
  210. mkdir "#{test_dir}/attributes/dirs/empty-with-attribute"
  211. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/empty-with-attribute"
  212. mkdir "#{test_dir}/attributes/dirs/full-with-attribute"
  213. touch "#{test_dir}/attributes/dirs/full-with-attribute/file"
  214. setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-with-attribute"
  215. mkdir "#{test_dir}/attributes/dirs/full-but-forbidden"
  216. touch "#{test_dir}/attributes/dirs/full-but-forbidden/file"
  217. #setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-but-forbidden"
  218. #chmod 000 "#{test_dir}/attributes/dirs/full-but-forbidden"
  219. #chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/dirs/full-but-forbidden"
  220. touch -t #{some_date} "#{test_dir}/attributes"
  221. touch -t #{some_date} "#{test_dir}/attributes/"*
  222. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*
  223. touch -t #{some_date} "#{test_dir}/attributes/dirs/"*/*
  224. sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
  225. EOF
  226. end