-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: rewrite testing script in python #241
base: master
Are you sure you want to change the base?
Conversation
9b30a9b
to
5660484
Compare
There are some versioning issues with the dependencies. Fedora 40->41 jumps to a new maintained fork of requests-unixsockets2 which is supposed to be a drop in replacement for the original, however it breaks the tests as I've written them (which was on fedora 40). The right thing to do is likely to use a virtualenv to enforce consistent versioning A bunch of relevant link: msabramo/requests-unixsocket#73 (comment) https://src.fedoraproject.org/rpms/python-requests-unixsocket https://gitlab.com/thelabnyc/requests-unixsocket2/-/commit/6f3b5757adf480c360b91acf5776009136c9496a |
5660484
to
f5e8cdd
Compare
Leveraging the pytest framework, refactor the tests one-for-one from test.sh into individual python functions that run in the same order and with the same dependencies on earlier tests. Signed-off-by: Joel Savitz <joel@underground.software>
f5e8cdd
to
c18a131
Compare
Fixes #242 |
b3a63f9
to
7f9583d
Compare
429a67e
to
1b1bef9
Compare
Signed-off-by: Joel Savitz <joel@underground.software>
Signed-off-by: Joel Savitz <joel@underground.software>
1b1bef9
to
926377b
Compare
…rary If radius was so good, why didn't they make a... Signed-off-by: Joel Savitz <joel@underground.software>
pipe patchsets into append_journal to accomplish the same functionality Signed-off-by: Joel Savitz <joel@underground.software>
926377b
to
0927481
Compare
Signed-off-by: Joel Savitz <joel@underground.software>
This project uses podman primarily. Signed-off-by: Joel Savitz <joel@underground.software>
Add an API to the RocketCrew to create a user, including a simple caching mechanism exposed to the caller. Simplifies to focus on more important information about what's being checked. Signed-off-by: Joel Savitz <joel@underground.software>
Signed-off-by: Joel Savitz <joel@underground.software>
Everything there runs at startup together. Signed-off-by: Joel Savitz <joel@underground.software>
general_test.py is reduced to under 100 lines. Signed-off-by: Joel Savitz <joel@underground.software>
test/general_test.py
Outdated
class SSLUnixSocketConnection(HTTPConnection): | ||
"""Custom HTTPConnection that wraps a Unix socket with SSL.""" | ||
|
||
def __init__(self, unix_socket_path, **kwargs): | ||
super().__init__("localhost", **kwargs) # Dummy host (not used) | ||
self.unix_socket_path = unix_socket_path | ||
self.ssl_context = create_urllib3_context() | ||
self.ssl_context.load_verify_locations(CERT_PATH) | ||
|
||
def _new_conn(self): | ||
"""Create a new wrapped SSL connection over a Unix domain socket.""" | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.connect(self.unix_socket_path) | ||
return self.ssl_context.wrap_socket(sock, server_hostname="localhost") | ||
|
||
|
||
class SSLUnixSocketConnectionPool(HTTPConnectionPool): | ||
"""Custom ConnectionPool for Unix socket wrapped with SSL.""" | ||
|
||
def __init__(self, socket_path, **kwargs): | ||
super().__init__("localhost", **kwargs) # Dummy host (not used) | ||
self.socket_path = socket_path | ||
|
||
def _new_conn(self): | ||
return SSLUnixSocketConnection(self.socket_path) | ||
|
||
|
||
class SSLUnixSocketAdapter(HTTPAdapter): | ||
"""Transport adapter to route requests over a Unix socket with SSL.""" | ||
|
||
def __init__(self, socket_path, **kwargs): | ||
self.socket_path = socket_path | ||
super().__init__(**kwargs) | ||
|
||
def get_connection(self, url, proxies=None): | ||
return SSLUnixSocketConnectionPool(self.socket_path) | ||
|
||
|
||
class UnixPOP3(poplib.POP3): | ||
def __init__(self, socket_path, certfile, timeout=30): | ||
self.timeout = timeout | ||
# Create SSL context and load certificate | ||
ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) | ||
ssl_context.load_verify_locations(certfile) | ||
|
||
# Create and connect Unix domain socket | ||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
sock.connect(socket_path) | ||
# Wrap with SSL | ||
self.sock = ssl_context.wrap_socket(sock, server_hostname='localhost.localdomain') | ||
self.file = self.sock.makefile('rb') | ||
self._debugging = 0 | ||
|
||
|
||
def singularity_pop_login(user, pass_): | ||
mailbox = UnixPOP3(POP3S_SOCKET_PATH, CERT_PATH) | ||
mailbox.user(user) | ||
mailbox.pass_(pass_) | ||
return mailbox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I am insane, but like can't we just use pycurl to actually one to one map the curl commands we were using instead of contorting python's request library to do things it does not want to?
Also not totally sure I understand the motivation behind these changes more broadly. What benefit exactly does hundreds of lines of code churn and a half dozen new dependencies offer? Some of the code in the resulting general_test.py is kinda nice, but the fact that it now requires a bunch of support code where the prior was literally just a shell script that I could copy and paste the failing command from to debug what is going on nullifies a lot of that. |
This is just a preparation step for more broad testing enhancements I'm working on, such as rewriting the email testing script as a part of the test suite and enabling more test driven development of automation features that we can't afford to ship broken. Using pytest you can also run specific tests from the suite with pytest -k which will more useful for tests that don't have dependencies on previous tests in the suite. That being said it's now much easier to write many clear tests of our existing code and also eliminates the issue with curl-minimal |
Leveraging the pytest framework, refactor the tests one-for-one from test.sh into individual python functions that run in the same order and with the same dependencies on earlier tests.