def test_mode(): """ Test to verifies the mode SELinux is running in, can be set to enforcing or permissive. """ ret = { "name": "unknown", "changes": {}, "result": False, "comment": "unknown is not an accepted mode", } assert selinux.mode("unknown") == ret mock_en = MagicMock(return_value="Enforcing") mock_pr = MagicMock(side_effect=["Permissive", "Enforcing"]) with patch.dict( selinux.__salt__, { "selinux.getenforce": mock_en, "selinux.getconfig": mock_en, "selinux.setenforce": mock_pr, }, ): comt = "SELinux is already in Enforcing mode" ret = {"name": "Enforcing", "comment": comt, "result": True, "changes": {}} assert selinux.mode("Enforcing") == ret with patch.dict(selinux.__opts__, {"test": True}): comt = "SELinux mode is set to be changed to Permissive" ret = { "name": "Permissive", "comment": comt, "result": None, "changes": {"new": "Permissive", "old": "Enforcing"}, } assert selinux.mode("Permissive") == ret with patch.dict(selinux.__opts__, {"test": False}): comt = "SELinux has been set to Permissive mode" ret = { "name": "Permissive", "comment": comt, "result": True, "changes": {"new": "Permissive", "old": "Enforcing"}, } assert selinux.mode("Permissive") == ret comt = "Failed to set SELinux to Permissive mode" ret.update( {"name": "Permissive", "comment": comt, "result": False, "changes": {}} ) assert selinux.mode("Permissive") == ret
def test_mode(self): ''' Test to verifies the mode SELinux is running in, can be set to enforcing or permissive. ''' ret = {'name': '', 'changes': {}, 'result': False, 'comment': ''} comt = ('unknown is not an accepted mode') ret.update({'name': 'unknown', 'comment': comt}) self.assertDictEqual(selinux.mode('unknown'), ret) mock_en = MagicMock(return_value='Enforcing') mock_pr = MagicMock(side_effect=['Permissive', 'Enforcing']) with patch.dict(selinux.__salt__, { 'selinux.getenforce': mock_en, 'selinux.setenforce': mock_pr }): comt = ('SELinux is already in Enforcing mode') ret.update({'name': 'Enforcing', 'comment': comt, 'result': True}) self.assertDictEqual(selinux.mode('Enforcing'), ret) with patch.dict(selinux.__opts__, {'test': True}): comt = ('SELinux mode is set to be changed to Permissive') ret.update({ 'name': 'Permissive', 'comment': comt, 'result': None }) self.assertDictEqual(selinux.mode('Permissive'), ret) with patch.dict(selinux.__opts__, {'test': False}): comt = ('SELinux has been set to Permissive mode') ret.update({ 'name': 'Permissive', 'comment': comt, 'result': True }) self.assertDictEqual(selinux.mode('Permissive'), ret) comt = ('Failed to set SELinux to Permissive mode') ret.update({ 'name': 'Permissive', 'comment': comt, 'result': False }) self.assertDictEqual(selinux.mode('Permissive'), ret)
def test_mode(self): ''' Test to verifies the mode SELinux is running in, can be set to enforcing or permissive. ''' ret = {'name': '', 'changes': {}, 'result': False, 'comment': ''} comt = ('unknown is not an accepted mode') ret.update({'name': 'unknown', 'comment': comt}) self.assertDictEqual(selinux.mode('unknown'), ret) mock_en = MagicMock(return_value='Enforcing') mock_pr = MagicMock(side_effect=['Permissive', 'Enforcing']) with patch.dict(selinux.__salt__, {'selinux.getenforce': mock_en, 'selinux.setenforce': mock_pr}): comt = ('SELinux is already in Enforcing mode') ret.update({'name': 'Enforcing', 'comment': comt, 'result': True}) self.assertDictEqual(selinux.mode('Enforcing'), ret) with patch.dict(selinux.__opts__, {'test': True}): comt = ('SELinux mode is set to be changed to Permissive') ret.update({'name': 'Permissive', 'comment': comt, 'result': None}) self.assertDictEqual(selinux.mode('Permissive'), ret) with patch.dict(selinux.__opts__, {'test': False}): comt = ('SELinux has been set to Permissive mode') ret.update({'name': 'Permissive', 'comment': comt, 'result': True}) self.assertDictEqual(selinux.mode('Permissive'), ret) comt = ('Failed to set SELinux to Permissive mode') ret.update({'name': 'Permissive', 'comment': comt, 'result': False}) self.assertDictEqual(selinux.mode('Permissive'), ret)