Add more testcases

This commit is contained in:
0x1eef 2024-03-07 22:28:48 -03:00
parent ecf0395a2f
commit 05a5f3c8af
4 changed files with 45 additions and 5 deletions

View file

@ -2,10 +2,11 @@
set -e
if [ $(id -u) = 0 ]; then
rake clean clobber compile
rm -rf tmp/
for file in test/superuser/*_test.rb; do
ruby -Ilib ${file} --no-use-color
done
else
echo "You must be root to run superuser tests."
echo "You must be the root user to run these tests."
exit 1
fi

View file

@ -1,6 +1,11 @@
#!/bin/sh
set -e
rake clean clobber compile
for file in test/unprivileged/*_test.rb; do
ruby -Ilib ${file} --no-use-color
done
if [ $(id -u) -ne 0 ]; then
rake clean clobber compile
for file in test/unprivileged/*_test.rb; do
ruby -Ilib ${file} --no-use-color
done
else
echo "You must be an unprivileged user to run these tests."
exit 1
fi

View file

@ -12,6 +12,15 @@ module BSD::Control
rm(file)
end
def test_enable_mprotect_zero_permissions
touch(file)
chmod(0, file)
assert BSD::Control.feature!(:mprotect).enable!(file),
"The enable! method should have returned true"
ensure
rm(file)
end
def test_enable_mprotect_nonexistent_file
assert_raises(BSD::Control::Error) do
BSD::Control.feature!(:mprotect).enable!(file)

View file

@ -0,0 +1,25 @@
require_relative "../setup"
module BSD::Control
class EnableFeatureTest < Test::Unit::TestCase
require "fileutils"
include FileUtils
def test_enable_feature_lacks_privileges
touch(file)
assert_raises(
BSD::Control::Error,
"This operation requires root privileges."
) do
BSD::Control.feature!(:mprotect).enable!(file)
end
ensure
rm(file)
end
private
def file
File.join(__dir__, "file")
end
end
end