Ejemplo n.º 1
0
    def testParseFileData(self):
        """Tests the _ParseFileData function."""
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile('/etc/passwd', self._FILE_DATA)

        mount_point = fake_path_spec.FakePathSpec(location='/')

        plugin = linux.LinuxUserAccountsPlugin()
        knowledge_base = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, plugin)

        users = sorted(knowledge_base.user_accounts,
                       key=lambda user_account: user_account.identifier)
        self.assertEqual(len(users), 13)

        user_account = users[4]

        self.assertEqual(user_account.identifier, '14')
        self.assertEqual(user_account.group_identifier, '50')
        self.assertEqual(user_account.user_directory, '/var/ftp')
        self.assertEqual(user_account.username, 'ftp')
        self.assertEqual(user_account.shell, '/sbin/nologin')
Ejemplo n.º 2
0
    def testParseFileData(self):
        """Tests the _ParseFileData function."""
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile('/etc/passwd', self._FILE_DATA)
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 0)

        users = sorted(test_mediator.knowledge_base.user_accounts,
                       key=lambda user_account: user_account.identifier)
        self.assertEqual(len(users), 13)

        user_account = users[4]

        self.assertEqual(user_account.identifier, '14')
        self.assertEqual(user_account.group_identifier, '50')
        self.assertEqual(user_account.user_directory, '/var/ftp')
        self.assertEqual(user_account.username, 'ftp')
        self.assertEqual(user_account.shell, '/sbin/nologin')

        # Test on /etc/passwd with missing field.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd', b'error:99:99:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with empty username.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd', b':x:99:99:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with empty user identifier.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd', b'error:x::99:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 username.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'er\xbfor:x:99:99:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 user identifier.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'error:x:\xbf9:99:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 group identifier.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'error:x:99:\xbf9:Nobody:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 full name.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'error:x:99:99:Nob\xbfdy:/home/error:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 user directory.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'error:x:99:99:Nobody:/home/er\xbfor:/sbin/nologin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)

        # Test on /etc/passwd with non UTF-8 shell.
        file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
        file_system_builder.AddFile(
            '/etc/passwd',
            b'error:x:99:99:Nobody:/home/error:/sbin/nol\xbfgin\n')
        mount_point = fake_path_spec.FakePathSpec(location='/')

        storage_writer = self._CreateTestStorageWriter()

        plugin = linux.LinuxUserAccountsPlugin()
        test_mediator = self._RunPreprocessorPluginOnFileSystem(
            file_system_builder.file_system, mount_point, storage_writer,
            plugin)

        self.assertEqual(storage_writer.number_of_preprocessing_warnings, 1)