2017-04-29 21:53:47 +00:00
|
|
|
|
require 'date'
|
|
|
|
|
|
2017-04-28 18:36:42 +00:00
|
|
|
|
Vagrant.configure(2) do |config|
|
|
|
|
|
config.vm.provider :virtualbox do |v|
|
|
|
|
|
v.name = 'exa'
|
2016-10-07 18:31:03 +00:00
|
|
|
|
v.memory = 1024
|
|
|
|
|
v.cpus = 1
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-28 18:36:42 +00:00
|
|
|
|
|
|
|
|
|
# We use Ubuntu instead of Debian because the image comes with two-way
|
|
|
|
|
# shared folder support by default.
|
|
|
|
|
config.vm.box = 'ubuntu/xenial64'
|
|
|
|
|
config.vm.hostname = 'exa'
|
2016-10-07 18:31:03 +00:00
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2017-04-30 10:06:52 +00:00
|
|
|
|
# Install the dependencies needed for exa to build, as quietly as
|
|
|
|
|
# apt can do.
|
2016-10-07 18:31:03 +00:00
|
|
|
|
config.vm.provision :shell, privileged: true, inline:
|
2017-04-30 10:06:52 +00:00
|
|
|
|
%[apt-get install -qq -o=Dpkg::Use-Pty=0 -y git cmake libssl-dev libgit2-dev libssh2-1-dev curl attr pkg-config]
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
|
|
|
|
|
# Guarantee that the timezone is UTC -- some of the tests
|
|
|
|
|
# depend on this (for now).
|
|
|
|
|
config.vm.provision :shell, privileged: true, inline:
|
|
|
|
|
%[timedatectl set-timezone UTC]
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
# Install Rust.
|
|
|
|
|
# This is done as vagrant, not root, because it’s vagrant
|
|
|
|
|
# who actually uses it. Sent to /dev/null because the progress
|
2017-04-28 18:34:23 +00:00
|
|
|
|
# bar produces a ton of output.
|
2016-10-07 18:31:03 +00:00
|
|
|
|
config.vm.provision :shell, privileged: false, inline:
|
|
|
|
|
%[hash rustc &>/dev/null || curl -sSf https://static.rust-lang.org/rustup.sh | sh &> /dev/null]
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
# Use a different ‘target’ directory on the VM than on the host.
|
|
|
|
|
# By default it just uses the one in /vagrant/target, which can
|
|
|
|
|
# cause problems if it has different permissions than the other
|
|
|
|
|
# directories, or contains object files compiled for the host.
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline:
|
2017-04-28 18:34:23 +00:00
|
|
|
|
%[echo "export CARGO_TARGET_DIR=/home/ubuntu/target" >> ~/.bashrc]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# We create two users that own the test files.
|
|
|
|
|
# The first one just owns the ordinary ones, because we don’t want to
|
|
|
|
|
# depend on “vagrant” or “ubuntu” existing.
|
|
|
|
|
user = "cassowary"
|
|
|
|
|
config.vm.provision :shell, privileged: true, inline:
|
|
|
|
|
%[id -u #{user} &>/dev/null || useradd #{user}]
|
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
# The second one has a long name, to test that the file owner column
|
|
|
|
|
# widens correctly. The benefit of Vagrant is that we don’t need to
|
|
|
|
|
# set this up on the *actual* system!
|
2016-10-07 18:31:03 +00:00
|
|
|
|
longuser = "antidisestablishmentarienism"
|
|
|
|
|
config.vm.provision :shell, privileged: true, inline:
|
|
|
|
|
%[id -u #{longuser} &>/dev/null || useradd #{longuser}]
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2017-04-28 18:26:57 +00:00
|
|
|
|
# Because the timestamps are formatted differently depending on whether
|
|
|
|
|
# they’re in the current year or not (see `details.rs`), we have to make
|
|
|
|
|
# sure that the files are created in the current year, so they get shown
|
|
|
|
|
# in the format we expect.
|
|
|
|
|
current_year = Date.today.year
|
|
|
|
|
some_date = "#{current_year}01011234.56" # 1st January, 12:34:56
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
|
|
|
|
# We also need an UID and a GID that are guaranteed to not exist, to
|
|
|
|
|
# test what happen when they don’t.
|
2016-10-07 18:31:03 +00:00
|
|
|
|
invalid_uid = 666
|
|
|
|
|
invalid_gid = 616
|
|
|
|
|
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
# Delete old testcases if they exist already, then create a
|
|
|
|
|
# directory to house new ones.
|
|
|
|
|
test_dir = "/testcases"
|
|
|
|
|
config.vm.provision :shell, privileged: true, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
rm -rfv #{test_dir}
|
|
|
|
|
mkdir #{test_dir}
|
|
|
|
|
chmod 777 #{test_dir}
|
|
|
|
|
EOF
|
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
|
|
|
|
|
# Awkward file size testcases.
|
2017-04-28 18:34:23 +00:00
|
|
|
|
# This needs sudo to set the files’ users at the very end.
|
2016-10-07 18:31:03 +00:00
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/files"
|
|
|
|
|
for i in {1..13}; do
|
|
|
|
|
fallocate -l "$i" "#{test_dir}/files/$i"_bytes
|
|
|
|
|
fallocate -l "$i"KiB "#{test_dir}/files/$i"_KiB
|
|
|
|
|
fallocate -l "$i"MiB "#{test_dir}/files/$i"_MiB
|
|
|
|
|
done
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
touch -t #{some_date} "#{test_dir}/files/"*
|
2017-04-28 18:34:23 +00:00
|
|
|
|
chmod 644 "#{test_dir}/files/"*
|
|
|
|
|
sudo chown #{user}:#{user} "#{test_dir}/files/"*
|
2016-10-07 18:31:03 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-29 18:25:07 +00:00
|
|
|
|
# File name extension testcases.
|
2017-04-28 18:34:23 +00:00
|
|
|
|
# These are tested in grid view, so we don’t need to bother setting
|
|
|
|
|
# owners or timestamps or anything.
|
2016-10-29 18:25:07 +00:00
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
2017-04-28 19:07:31 +00:00
|
|
|
|
mkdir "#{test_dir}/file-names-exts"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/Makefile"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/image.png"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/image.svg"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/video.avi"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/video.wmv"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/music.mp3"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/music.ogg"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/lossless.flac"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/lossless.wav"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/crypto.asc"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/crypto.signature"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/document.pdf"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/document.xlsx"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/compressed.zip"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/compressed.tar.gz"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/compressed.tgz"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/backup~"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/#SAVEFILE#"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/file.tmp"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
|
2017-04-28 19:07:31 +00:00
|
|
|
|
touch "#{test_dir}/file-names-exts/compiled.class"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/compiled.o"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/compiled.js"
|
|
|
|
|
touch "#{test_dir}/file-names-exts/compiled.coffee"
|
2016-10-29 18:25:07 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2017-04-28 22:24:19 +00:00
|
|
|
|
# Special file testcases.
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/specials"
|
|
|
|
|
|
|
|
|
|
sudo mknod "#{test_dir}/specials/block-device" b 3 60
|
|
|
|
|
sudo mknod "#{test_dir}/specials/char-device" c 14 40
|
|
|
|
|
sudo mknod "#{test_dir}/specials/named-pipe" p
|
2017-04-29 08:21:31 +00:00
|
|
|
|
|
|
|
|
|
sudo touch -t #{some_date} "#{test_dir}/specials/"*
|
2017-04-28 22:24:19 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
# Awkward symlink testcases.
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/links"
|
2017-04-30 10:58:29 +00:00
|
|
|
|
|
|
|
|
|
ln -s / "#{test_dir}/links/root"
|
|
|
|
|
ln -s /usr "#{test_dir}/links/usr"
|
|
|
|
|
ln -s nowhere "#{test_dir}/links/broken"
|
2016-10-29 18:58:34 +00:00
|
|
|
|
ln -s /proc/1/root "#{test_dir}/links/forbidden"
|
2017-04-30 10:58:29 +00:00
|
|
|
|
|
|
|
|
|
touch "#{test_dir}/links/some_file"
|
|
|
|
|
ln -s "#{test_dir}/links/some_file" "#{test_dir}/links/some_file_absolute"
|
|
|
|
|
(cd "#{test_dir}/links"; ln -s "some_file" "some_file_relative")
|
|
|
|
|
(cd "#{test_dir}/links"; ln -s "." "current_dir")
|
|
|
|
|
(cd "#{test_dir}/links"; ln -s ".." "parent_dir")
|
|
|
|
|
(cd "#{test_dir}/links"; ln -s "itself" "itself")
|
2016-10-07 18:31:03 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
# Awkward passwd testcases.
|
|
|
|
|
# sudo is needed for these because we technically aren’t a member
|
|
|
|
|
# of the groups (because they don’t exist), and chown and chgrp
|
|
|
|
|
# are smart enough to disallow it!
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/passwd"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
touch -t #{some_date} "#{test_dir}/passwd/unknown-uid"
|
|
|
|
|
chmod 644 "#{test_dir}/passwd/unknown-uid"
|
|
|
|
|
sudo chown #{invalid_uid}:#{user} "#{test_dir}/passwd/unknown-uid"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
touch -t #{some_date} "#{test_dir}/passwd/unknown-gid"
|
|
|
|
|
chmod 644 "#{test_dir}/passwd/unknown-gid"
|
|
|
|
|
sudo chown #{user}:#{invalid_gid} "#{test_dir}/passwd/unknown-gid"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
2016-10-07 18:31:03 +00:00
|
|
|
|
# Awkward permission testcases.
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/permissions"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
touch "#{test_dir}/permissions/all-permissions"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
chmod 777 "#{test_dir}/permissions/all-permissions"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
touch "#{test_dir}/permissions/no-permissions"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
chmod 000 "#{test_dir}/permissions/no-permissions"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
mkdir "#{test_dir}/permissions/forbidden-directory"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
chmod 000 "#{test_dir}/permissions/forbidden-directory"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
for perms in 001 002 004 010 020 040 100 200 400; do
|
|
|
|
|
touch "#{test_dir}/permissions/$perms"
|
|
|
|
|
chmod $perms "#{test_dir}/permissions/$perms"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
touch -t #{some_date} "#{test_dir}/permissions/"*
|
|
|
|
|
sudo chown #{user}:#{user} "#{test_dir}/permissions/"*
|
2016-10-07 18:31:03 +00:00
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Awkward extended attribute testcases.
|
|
|
|
|
config.vm.provision :shell, privileged: false, inline: <<-EOF
|
|
|
|
|
set -xe
|
|
|
|
|
mkdir "#{test_dir}/attributes"
|
|
|
|
|
|
|
|
|
|
touch "#{test_dir}/attributes/none"
|
|
|
|
|
|
|
|
|
|
touch "#{test_dir}/attributes/one"
|
|
|
|
|
setfattr -n user.greeting -v hello "#{test_dir}/attributes/one"
|
|
|
|
|
|
|
|
|
|
touch "#{test_dir}/attributes/two"
|
|
|
|
|
setfattr -n user.greeting -v hello "#{test_dir}/attributes/two"
|
|
|
|
|
setfattr -n user.another_greeting -v hi "#{test_dir}/attributes/two"
|
|
|
|
|
|
|
|
|
|
#touch "#{test_dir}/attributes/forbidden"
|
|
|
|
|
#setfattr -n user.greeting -v hello "#{test_dir}/attributes/forbidden"
|
|
|
|
|
#chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/forbidden"
|
|
|
|
|
|
|
|
|
|
mkdir "#{test_dir}/attributes/dirs"
|
|
|
|
|
|
|
|
|
|
mkdir "#{test_dir}/attributes/dirs/empty-with-attribute"
|
|
|
|
|
setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/empty-with-attribute"
|
|
|
|
|
|
|
|
|
|
mkdir "#{test_dir}/attributes/dirs/full-with-attribute"
|
|
|
|
|
touch "#{test_dir}/attributes/dirs/full-with-attribute/file"
|
|
|
|
|
setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-with-attribute"
|
|
|
|
|
|
|
|
|
|
mkdir "#{test_dir}/attributes/dirs/full-but-forbidden"
|
|
|
|
|
touch "#{test_dir}/attributes/dirs/full-but-forbidden/file"
|
|
|
|
|
#setfattr -n user.greeting -v hello "#{test_dir}/attributes/dirs/full-but-forbidden"
|
|
|
|
|
#chmod 000 "#{test_dir}/attributes/dirs/full-but-forbidden"
|
|
|
|
|
#chmod +a "$YOU deny readextattr" "#{test_dir}/attributes/dirs/full-but-forbidden"
|
|
|
|
|
|
2017-04-28 18:34:23 +00:00
|
|
|
|
touch -t #{some_date} "#{test_dir}/attributes"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
touch -t #{some_date} "#{test_dir}/attributes/"*
|
|
|
|
|
touch -t #{some_date} "#{test_dir}/attributes/dirs/"*
|
|
|
|
|
touch -t #{some_date} "#{test_dir}/attributes/dirs/"*/*
|
2017-04-28 18:34:23 +00:00
|
|
|
|
|
|
|
|
|
sudo chown #{user}:#{user} -R "#{test_dir}/attributes"
|
2016-10-07 18:31:03 +00:00
|
|
|
|
EOF
|
|
|
|
|
end
|