1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the Linux preprocess plug-ins."""
from __future__ import unicode_literals
import unittest
from dfvfs.helpers import fake_file_system_builder
from dfvfs.path import fake_path_spec
from plaso.preprocessors import linux
from tests.preprocessors import test_lib
class LinuxHostnamePluginTest(test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux hostname plugin."""
_FILE_DATA = b'plaso.kiddaland.net\n'
def testParseFileData(self):
"""Tests the _ParseFileData function."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFile('/etc/hostname', self._FILE_DATA)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxHostnamePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
self.assertEqual(knowledge_base.hostname, 'plaso.kiddaland.net')
class LinuxDistributionPluginTest(test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux distribution plugin."""
_FILE_DATA = b'Fedora release 26 (Twenty Six)\n'
def testParseFileData(self):
"""Tests the _ParseFileData function."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFile('/etc/system-release', self._FILE_DATA)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxDistributionPlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
system_product = knowledge_base.GetValue('operating_system_product')
self.assertEqual(system_product, 'Fedora release 26 (Twenty Six)')
class LinuxIssueFilePluginTest(test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux issue file plugin."""
_FILE_DATA = b"""\
Debian GNU/Linux 5.0 \\n \\l
"""
def testParseFileData(self):
"""Tests the _ParseFileData function."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFile('/etc/issue', self._FILE_DATA)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxIssueFilePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
system_product = knowledge_base.GetValue('operating_system_product')
self.assertEqual(system_product, 'Debian GNU/Linux 5.0')
class LinuxStandardBaseReleasePluginTest(
test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux standard base (LSB) release plugin."""
_FILE_DATA = b"""\
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04"""
def testParseFileData(self):
"""Tests the _ParseFileData function."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFile('/etc/lsb-release', self._FILE_DATA)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxStandardBaseReleasePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
system_product = knowledge_base.GetValue('operating_system_product')
self.assertEqual(system_product, 'Ubuntu 14.04 LTS')
class LinuxSystemdOperatingSystemPluginTest(
test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux operating system release plugin."""
_FILE_DATA = b"""\
NAME=Fedora
VERSION="26 (Workstation Edition)"
ID=fedora
VERSION_ID=26
PRETTY_NAME="Fedora 26 (Workstation Edition)"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:26"
HOME_URL="https://fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=26
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=26
PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy
VARIANT="Workstation Edition"
VARIANT_ID=workstation"""
def testParseFileData(self):
"""Tests the _ParseFileData function."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFile('/etc/os-release', self._FILE_DATA)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxSystemdOperatingSystemPlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
system_product = knowledge_base.GetValue('operating_system_product')
self.assertEqual(system_product, 'Fedora 26 (Workstation Edition)')
class LinuxTimeZonePluginTest(test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux time zone plugin."""
def testParseFileEntryWithLink(self):
"""Tests the _ParseFileEntry function on a symbolic link."""
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddSymbolicLink(
'/etc/localtime', '/usr/share/zoneinfo/Europe/Zurich')
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxTimeZonePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
self.assertEqual(knowledge_base.timezone.zone, 'Europe/Zurich')
def testParseFileEntryWithTZif(self):
"""Tests the _ParseFileEntry function on a timezone information file."""
test_file_path = self._GetTestFilePath(['localtime.tzif'])
self._SkipIfPathNotExists(test_file_path)
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFileReadData('/etc/localtime', test_file_path)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxTimeZonePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
self.assertEqual(knowledge_base.timezone.zone, 'CET')
def testParseFileEntryWithBogusTZif(self):
"""Tests the _ParseFileEntry function on a bogus TZif file."""
test_file_path = self._GetTestFilePath(['syslog'])
self._SkipIfPathNotExists(test_file_path)
file_system_builder = fake_file_system_builder.FakeFileSystemBuilder()
file_system_builder.AddFileReadData('/etc/localtime', test_file_path)
mount_point = fake_path_spec.FakePathSpec(location='/')
plugin = linux.LinuxTimeZonePlugin()
knowledge_base = self._RunPreprocessorPluginOnFileSystem(
file_system_builder.file_system, mount_point, plugin)
self.assertEqual(knowledge_base.timezone.zone, 'UTC')
class LinuxUserAccountsPluginTest(test_lib.ArtifactPreprocessorPluginTestCase):
"""Tests for the Linux user accounts plugin."""
_FILE_DATA = (
b'root:x:0:0:root:/root:/bin/bash\n'
b'bin:x:1:1:bin:/bin:/sbin/nologin\n'
b'daemon:x:2:2:daemon:/sbin:/sbin/nologin\n'
b'adm:x:3:4:adm:/var/adm:/sbin/nologin\n'
b'lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin\n'
b'sync:x:5:0:sync:/sbin:/bin/sync\n'
b'shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown\n'
b'halt:x:7:0:halt:/sbin:/sbin/halt\n'
b'mail:x:8:12:mail:/var/spool/mail:/sbin/nologin\n'
b'operator:x:11:0:operator:/root:/sbin/nologin\n'
b'games:x:12:100:games:/usr/games:/sbin/nologin\n'
b'ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin\n'
b'nobody:x:99:99:Nobody:/:/sbin/nologin\n')
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')
if __name__ == '__main__':
unittest.main()
|