Best Python code snippet using avocado_python
test_kernel_config.py
Source:test_kernel_config.py
...119 assert decompressor.decompress(test_file.binary) != b''120def test_checksec_existing_config():121 test_file = TEST_DATA_DIR / 'configs/CONFIG'122 kernel_config = test_file.read_text()123 result = check_kernel_config(kernel_config)124 assert result != {}125 assert 'kernel' in result126 assert 'selinux' in result127 assert 'randomize_va_space' not in result['kernel']128 assert result['kernel']['kernel_heap_randomization'] == 'yes'129def test_checksec_no_valid_json(monkeypatch):130 monkeypatch.setattr('plugins.analysis.kernel_config.internal.checksec_check_kernel.execute_shell_command', lambda _: 'invalid json')131 assert check_kernel_config('no_real_config') == {}132def test_check_kernel_hardening():133 test_file = TEST_DATA_DIR / 'configs/CONFIG'134 kernel_config = test_file.read_text()135 result = check_kernel_hardening(kernel_config)136 assert isinstance(result, list)137 assert all(isinstance(tup, tuple) for tup in result)138 assert len(result) > 50139 assert all(len(tup) == 7 for tup in result), 'all results should have 6 elements'140 assert any(len(tup[5]) > 0 for tup in result), 'some "protection against" info shouldn\'t be empty'141def test_check_hardening_no_results():...
kernel_config.py
Source:kernel_config.py
...36 if self.probably_kernel_config(maybe_config):37 self.add_kernel_config_to_analysis(file_object, maybe_config)38 file_object.processed_analysis[self.NAME]['summary'] = self._get_summary(file_object.processed_analysis[self.NAME])39 if 'kernel_config' in file_object.processed_analysis[self.NAME]:40 file_object.processed_analysis[self.NAME]['checksec'] = check_kernel_config(file_object.processed_analysis[self.NAME]['kernel_config'])41 file_object.processed_analysis[self.NAME]['hardening'] = check_kernel_hardening(file_object.processed_analysis[self.NAME]['kernel_config'])42 return file_object43 @staticmethod44 def _get_summary(results: dict) -> List[str]:45 if 'is_kernel_config' in results and results['is_kernel_config'] is True:46 return ['Kernel Config']47 return []48 def add_kernel_config_to_analysis(self, file_object: FileObject, config_bytes: bytes):49 file_object.processed_analysis[self.NAME]['is_kernel_config'] = True50 file_object.processed_analysis[self.NAME]['kernel_config'] = config_bytes.decode()51 self.add_analysis_tag(file_object, 'IKCONFIG', 'Kernel Configuration')52 def probably_kernel_config(self, raw_data: bytes) -> bool:53 try:54 content = raw_data.decode()...
utils_linux_modules.py
Source:utils_linux_modules.py
...3"""4import logging5from avocado.utils import linux_modules6LOG = logging.getLogger(__name__)7def check_kernel_config(config_name, session=None):8 """9 Reports the configuration of $config_name of the current kernel10 :param config_name: Name of kernel config to search11 E.g. CONFIG_VIRTIO_IOMMU12 :type config_name: str13 :param session: guest session, command is run on host if None14 :type session: aexpect.ShellSession15 :return: Config status in running kernel (NOT_SET, BUILTIN, MODULE)16 :rtype: :class:`ModuleConfig`17 """18 def check_session_kernel_config(config_name, session):19 """20 Reports the configuration of $config_name of session's kernel21 :param config_name: Name of kernel config to search22 E.g. CONFIG_VIRTIO_IOMMU23 :type config_name: str24 :param session: remote session25 :type session: aexpect.ShellSession26 :return: Config status in running kernel (NOT_SET, BUILTIN, MODULE)27 :rtype: :class:`ModuleConfig`28 """29 config_file = '/boot/config-' + session.cmd_output('uname -r').strip()30 config_info = session.cmd_output(f'grep ^"{config_name}"= \31 {config_file}').strip()32 LOG.debug("Get config info %s", config_info)33 line = config_info.split('=')34 if len(line) != 2:35 return linux_modules.ModuleConfig.NOT_SET36 LOG.debug("Get config %s, target is %s", line[0].strip(), config_name)37 if line[0].strip() == config_name:38 if line[1].strip() == "m":39 return linux_modules.ModuleConfig.MODULE40 else:41 return linux_modules.ModuleConfig.BUILTIN42 return linux_modules.ModuleConfig.NOT_SET43 return linux_modules.check_kernel_config(config_name) if session is None \44 else check_session_kernel_config(config_name, session)45def kconfig_is_builtin(config_name, session=None):46 """47 Check if the kernel config is BUILTIN48 :param config_name: Name of kernel config to check49 E.g. CONFIG_VIRTIO_IOMMU50 :type config_name: str51 :param session: Guest session, command is run on host if None52 :type session: aexpect.ShellSession53 :return: Return True if kernel config is BUILTIN, otherwise False.54 :rtype: Bool55 """56 return check_kernel_config(config_name, session) is \57 linux_modules.ModuleConfig.BUILTIN58def kconfig_is_module(config_name, session=None):59 """60 Check if the kernel config is MODULE61 :param config_name: Name of kernel config to check62 E.g. CONFIG_VIRTIO_IOMMU63 :type config_name: str64 :param session: Guest session, command is run on host if None65 :type session: aexpect.ShellSession66 :return: Return True if kernel config is MODULE, otherwise False.67 :rtype: Bool68 """69 return check_kernel_config(config_name, session) is \70 linux_modules.ModuleConfig.MODULE71def kconfig_is_not_set(config_name, session=None):72 """73 Check if the kernel config is NOT_SET74 :param config_name: Name of kernel config to check75 E.g. CONFIG_VIRTIO_IOMMU76 :type config_name: str77 :param session: Guest session, command is run on host if None78 :type session: aexpect.ShellSession79 :return: Return True if kernel config is NOT_SET, otherwise False.80 :rtype: Bool81 """82 return check_kernel_config(config_name, session) is \...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!