2024-03-08 00:27:20 +01:00
|
|
|
require_relative "../setup"
|
|
|
|
module BSD::Control
|
|
|
|
class EnableFeatureTest < Test::Unit::TestCase
|
|
|
|
require 'fileutils'
|
|
|
|
include FileUtils
|
|
|
|
|
|
|
|
def test_enable_mprotect
|
|
|
|
touch(file)
|
2024-03-08 05:23:16 +01:00
|
|
|
assert BSD::Control.feature(:mprotect).enable!(file),
|
2024-03-08 00:27:20 +01:00
|
|
|
"The enable! method should have returned true"
|
|
|
|
ensure
|
|
|
|
rm(file)
|
|
|
|
end
|
|
|
|
|
2024-03-08 02:28:48 +01:00
|
|
|
def test_enable_mprotect_zero_permissions
|
|
|
|
touch(file)
|
|
|
|
chmod(0, file)
|
2024-03-08 05:23:16 +01:00
|
|
|
assert BSD::Control.feature(:mprotect).enable!(file),
|
2024-03-08 02:28:48 +01:00
|
|
|
"The enable! method should have returned true"
|
|
|
|
ensure
|
|
|
|
rm(file)
|
|
|
|
end
|
|
|
|
|
2024-03-08 00:27:20 +01:00
|
|
|
def test_enable_mprotect_nonexistent_file
|
|
|
|
assert_raises(BSD::Control::Error) do
|
2024-03-08 05:23:16 +01:00
|
|
|
BSD::Control.feature(:mprotect).enable!(file)
|
2024-03-08 00:27:20 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def file
|
|
|
|
File.join(__dir__, "file")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|