Skip to content

Instantly share code, notes, and snippets.

View abadger's full-sized avatar

Toshio Kuratomi abadger

View GitHub Profile
@abadger
abadger / gist:2e6c53fb524d1a5f4a01109ce4e1c184
Created August 8, 2022 16:36
full pytest testcase using get_marker on older pytest.
import pytest
@pytest.fixture
def system_cert_with_target_path(request):
print(pytest.__version__)
print(request.node)
print(dir(request.node))
if pytest.__version__.split('.') <= ('3', '6', '0'):
mark = request.node.get_marker("cert_filename")
@abadger
abadger / gist:3b7a1cb42ae736cc9f25145969812817
Created August 5, 2022 18:16
get_marker for older pytest
diff --git a/convert2rhel/unit_tests/conftest.py b/convert2rhel/unit_tests/conftest.py
index 40ccf0b..acdd1d1 100644
--- a/convert2rhel/unit_tests/conftest.py
+++ b/convert2rhel/unit_tests/conftest.py
@@ -82,8 +82,11 @@ def system_cert_with_target_path(monkeypatch, tmpdir, request):
.. seealso::
https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#using-markers-to-pass-data-to-fixtures
"""
+ if pytest.__version__.split('.') <= ('3', '6', '0'):
+ mark = request.node.get_marker("cert_filename")
@abadger
abadger / gist:ea56e68798d792853315096017307077
Created July 8, 2022 17:13
Get some introspected info from objects. This is only prof-of-concept level code. Good for a one-off but needs work if you want it in production.
def obj_inspector(obj):
attributes = {}
functions = {}
special_functions = {}
for attribute_name in dir(obj):
attribute_value = getattr(obj, attribute_name)
attribute_category = attributes
diff --git a/tests/integration/tier0/check-cve-2022-1662/main.fmf b/tests/integration/tier0/check-cve-2022-1662/main.fmf
index 7da180d..bf7c36b 100644
--- a/tests/integration/tier0/check-cve-2022-1662/main.fmf
+++ b/tests/integration/tier0/check-cve-2022-1662/main.fmf
@@ -3,4 +3,6 @@ summary: check cve-2022-1662 is fixed
tier: 0
test: |
+ yum install -y python3-devel
+ pip install psutil
+-------------------------------+------------+
|message id |occurrences |
+===============================+============+
|consider-using-f-string |182 | Disable until we can require python-3.6+
+-------------------------------+------------+
|logging-not-lazy |123 | `log.warn("Message %s" % var)` => `log.warn("Message %s", var)`
+-------------------------------+------------+
|useless-object-inheritance |17 | Add `__metaclass__ = type` to the top of all files and remove `object` from class
+-------------------------------+------------+
|logging-format-interpolation |13 |
# Bad code:
class Foo:
def one(self, normalize):
self.normalize = normalize
self.username = os.geteuid()
self.token = os.environ['TOKEN']
data = self.do_a_thing()
if some_check():
data2 = self.do_a_thing()
# Three ways to do for loops:
## The common way
Most of the time, you have an iterable (a list, dictionary, string, etc) and want to loop over it.
Python makes this the easiest way to use a for loop:
``` python
contestants = ["First place finisher", "Second is still good", "the first civilized age"]
for contestant in contestants:
@abadger
abadger / .vimrc.py
Created December 10, 2021 18:46
My .vimrc.py Requires amoffat/snake
import snake
@snake.key_map("<leader>R")
def reverse():
"""Test mapping. Reverse a word"""
snake.replace_word(snake.get_word()[::-1])
@snake.key_map("<c-p>")
@abadger
abadger / gist:615c9d85a201c3f61c6673172e3a7b46
Created December 2, 2021 16:47
Example of easy porting of run_suprocess to use a list
diff --git a/convert2rhel/checks.py b/convert2rhel/checks.py
index 1bb5dff..ebe481f 100644
--- a/convert2rhel/checks.py
+++ b/convert2rhel/checks.py
@@ -105,7 +105,7 @@ def check_tainted_kmods():
system76_io 16384 0 - Live 0x0000000000000000 (OE) <<<<<< Tainted
system76_acpi 16384 0 - Live 0x0000000000000000 (OE) <<<<< Tainted
"""
- unsigned_modules, _ = run_subprocess("grep '(' /proc/modules")
+ unsigned_modules, _ = run_subprocess(["grep", "('", "/proc/modules"])
@abadger
abadger / gist:ea234ee7a7238b343bcfd6537d6e92e7
Last active November 30, 2021 20:34
Calling subprocess.Popen with strings.

Background of security problem

When you call suprocess.Popen, you can pass the command to execute in two ways:

  1. A string that corresponds to the commandline that you would run at the shell prompt command = "yum whatprovides 'java = 1.8.0'"
  2. A list where each argument to the command is a separate entry: command = ["yum", "whatprovides", "java = 1.8.0"]

When you pass a string to subprocess.Popen, the command has to either have no arguments or be passed through the shell