Vagrantfile 9.3 KB

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