示例#1
0
    def test_scan_when_two_failures(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        test_subject.scan_worldwritable_files_starting_with_dot = MagicMock(
            return_value=[])
        test_subject.scan_worldwritable_directories_with_no_sticky_bit_set = MagicMock(
            return_value=['/some/failure'])
        test_subject.scan_worldwritable_files_owned_by_root = MagicMock(
            return_value=['/other/failure'])
        test_subject.get_scan_text = MagicMock(
            side_effect=['Test2 Failed', 'Test3 Failed'])

        # Run test scenario
        result = test_subject.scan()

        # Assertions
        test_subject.get_scan_text.assert_has_calls([
            call('World writable directories with no sticky bit set',
                 ['/some/failure']),
            call('World writable files owned by root', ['/other/failure']),
        ])
        test_subject.scan_worldwritable_files_starting_with_dot.assert_called_once_with(
        )
        test_subject.scan_worldwritable_directories_with_no_sticky_bit_set.assert_called_once_with(
        )
        test_subject.scan_worldwritable_files_owned_by_root.assert_called_once_with(
        )
        self.assertEqual(result[0], ScanStatus.fail)
        self.assertEqual(result[1], 'Test2 Failed\nTest3 Failed')
示例#2
0
    def test_get_scan_text_when_list_has_items(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)

        # Run test scenario
        result = test_subject.get_scan_text('Check name', ['file1', 'file2'])

        # Assertions
        self.assertEqual(result, 'Failure: Check name:\n\tfile1\n\tfile2')
示例#3
0
    def test_get_scan_text_when_list_does_not_have_items(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)

        # Run test scenario
        result = test_subject.get_scan_text('Check name', [])

        # Assertions
        self.assertEqual(result, 'Success: Check name')
示例#4
0
    def test_get_scan_text_when_list_has_items(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)

        # Run test scenario
        result = test_subject.get_scan_text('Check name', ['file1', 'file2'])

        # Assertions
        self.assertEqual(result, 'Failure: Check name:\n\tfile1\n\tfile2')
示例#5
0
    def test_get_scan_text_when_list_does_not_have_items(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)

        # Run test scenario
        result = test_subject.get_scan_text('Check name', [])

        # Assertions
        self.assertEqual(result, 'Success: Check name')
示例#6
0
    def test_scan_when_two_failures(self):
        # Prepare data and mocks
        test_subject = WorldWritable(None)
        test_subject.scan_worldwritable_files_starting_with_dot = MagicMock(return_value=[])
        test_subject.scan_worldwritable_directories_with_no_sticky_bit_set = MagicMock(return_value=['/some/failure'])
        test_subject.scan_worldwritable_files_owned_by_root = MagicMock(return_value=['/other/failure'])
        test_subject.get_scan_text = MagicMock(side_effect=['Test2 Failed', 'Test3 Failed'])

        # Run test scenario
        result = test_subject.scan()

        # Assertions
        test_subject.get_scan_text.assert_has_calls(
            [
                call('World writable directories with no sticky bit set', ['/some/failure']),
                call('World writable files owned by root', ['/other/failure']),
            ]
        )
        test_subject.scan_worldwritable_files_starting_with_dot.assert_called_once_with()
        test_subject.scan_worldwritable_directories_with_no_sticky_bit_set.assert_called_once_with()
        test_subject.scan_worldwritable_files_owned_by_root.assert_called_once_with()
        self.assertEqual(result[0], ScanStatus.fail)
        self.assertEqual(result[1], 'Test2 Failed\nTest3 Failed')