Add shortcut for BSD::Control.feature

This commit is contained in:
0x1eef 2024-10-13 02:05:01 -03:00
parent c7ab44a868
commit d4373e1eab
8 changed files with 69 additions and 47 deletions

View file

@ -4,17 +4,19 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class DisableFeatureTest < BSD::Control::Test class DisableFeatureTest < BSD::Control::Test
def test_disable_pageexec def test_disable_pageexec
assert_equal true, assert_equal true, feature(:pageexec).disable!(file)
BSD::Control.feature(:pageexec).disable!(file) assert_equal :disabled, feature(:pageexec).status(file)
assert_equal :disabled,
BSD::Control.feature(:pageexec).status(file)
end end
def test_disable_pageexec_nonexistent_file def test_disable_pageexec_nonexistent_file
rm(file) rm(file)
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) { feature(:pageexec).disable!(file) }
BSD::Control.feature(:pageexec).disable!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,21 +4,23 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class EnableFeatureTest < BSD::Control::Test class EnableFeatureTest < BSD::Control::Test
def test_enable_pageexec def test_enable_pageexec
assert_equal true, assert_equal true, feature(:pageexec).enable!(file)
BSD::Control.feature(:pageexec).enable!(file)
end end
def test_enable_pageexec_mode_zero def test_enable_pageexec_mode_zero
chmod(0, file) chmod(0, file)
assert_equal true, assert_equal true, feature(:pageexec).enable!(file)
BSD::Control.feature(:pageexec).enable!(file)
end end
def test_enable_pageexec_nonexistent_file def test_enable_pageexec_nonexistent_file
rm(file) rm(file)
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) { feature(:pageexec).enable!(file) }
BSD::Control.feature(:pageexec).enable!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,20 +4,23 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class FeatureStatusTest < BSD::Control::Test class FeatureStatusTest < BSD::Control::Test
def test_pageexec_sysdef_status def test_pageexec_sysdef_status
assert_equal :sysdef, assert_equal :sysdef, feature(:pageexec).status(file)
BSD::Control.feature(:pageexec).status(file)
end end
def test_pageexec_enabled_status def test_pageexec_enabled_status
BSD::Control.feature(:pageexec).enable!(file) feature(:pageexec).enable!(file)
assert_equal :enabled, assert_equal :enabled, feature(:pageexec).status(file)
BSD::Control.feature(:pageexec).status(file)
end end
def test_pageexec_disabled_status def test_pageexec_disabled_status
BSD::Control.feature(:pageexec).disable!(file) feature(:pageexec).disable!(file)
assert_equal :disabled, assert_equal :disabled, feature(:pageexec).status(file)
BSD::Control.feature(:pageexec).status(file) end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,21 +4,21 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class SysDefFeatureTest < BSD::Control::Test class SysDefFeatureTest < BSD::Control::Test
def test_sysdef_pageexec def test_sysdef_pageexec
assert_equal true, assert_equal true, feature(:pageexec).enable!(file)
BSD::Control.feature(:pageexec).enable!(file) assert_equal :enabled, feature(:pageexec).status(file)
assert_equal :enabled, assert_equal true, feature(:pageexec).sysdef!(file)
BSD::Control.feature(:pageexec).status(file) assert_equal :sysdef, feature(:pageexec).status(file)
assert_equal true,
BSD::Control.feature(:pageexec).sysdef!(file)
assert_equal :sysdef,
BSD::Control.feature(:pageexec).status(file)
end end
def test_enable_pageexec_nonexistent_file def test_enable_pageexec_nonexistent_file
rm(file) rm(file)
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) { feature(:pageexec).sysdef!(file) }
BSD::Control.feature(:pageexec).sysdef!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -5,9 +5,13 @@ module BSD::Control
class DisableFeatureTest < BSD::Control::Test class DisableFeatureTest < BSD::Control::Test
def test_disable_pageexec_nonexistent_file def test_disable_pageexec_nonexistent_file
rm(file) rm(file)
assert_raises(Errno::ENOENT) do assert_raises(Errno::ENOENT) { feature(:pageexec).disable!(file) }
BSD::Control.feature(:pageexec).disable!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,9 +4,13 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class EnableFeatureTest < BSD::Control::Test class EnableFeatureTest < BSD::Control::Test
def test_enable_feature_insufficient_permissions def test_enable_feature_insufficient_permissions
assert_raises(Errno::EPERM) do assert_raises(Errno::EPERM) { feature(:pageexec).enable!(file) }
BSD::Control.feature(:pageexec).enable!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,14 +4,17 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class FeatureTest < BSD::Control::Test class FeatureTest < BSD::Control::Test
def test_pageexec_feature def test_pageexec_feature
assert_instance_of BSD::Control::Feature, assert_instance_of BSD::Control::Feature, feature(:pageexec)
BSD::Control.feature(:pageexec)
end end
def test_nonexistent_feature def test_nonexistent_feature
assert_raises(BSD::Control::Error) do assert_raises(BSD::Control::Error) { feature(:non_existent_feature) }
BSD::Control.feature(:non_existent_feature)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end

View file

@ -4,9 +4,13 @@ require_relative "../setup"
module BSD::Control module BSD::Control
class SysDefTest < BSD::Control::Test class SysDefTest < BSD::Control::Test
def test_sysdef!_insufficient_permissions def test_sysdef!_insufficient_permissions
assert_raises(Errno::EPERM) do assert_raises(Errno::EPERM) { feature(:pageexec).sysdef!(file) }
BSD::Control.feature(:pageexec).sysdef!(file)
end end
private
def feature(name)
BSD::Control.feature(name)
end end
end end
end end