mirror of
https://github.com/calebstewart/pwncat.git
synced 2024-11-30 20:34:15 +01:00
b998470297
Added a test workflow. Only for triggering manually for now.
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
import io
|
|
|
|
import pwncat.manager
|
|
|
|
|
|
def test_config_fileobj():
|
|
|
|
configuration = io.StringIO(
|
|
"""
|
|
set -g db "memory://"
|
|
set -g prefix c-k
|
|
set -g on_load { }
|
|
set -g backdoor_user "config_test"
|
|
"""
|
|
)
|
|
|
|
with pwncat.manager.Manager(config=configuration) as manager:
|
|
assert manager.config["backdoor_user"] == "config_test"
|
|
|
|
|
|
def test_user_config(tmp_path):
|
|
|
|
import os
|
|
|
|
# Ensure we don't muck up the environment for this process
|
|
old_home = os.environ.get("XDG_DATA_HOME", None)
|
|
|
|
try:
|
|
# Set the data home to our temp path
|
|
os.environ["XDG_DATA_HOME"] = str(tmp_path)
|
|
|
|
# Create the pwncat directory
|
|
(tmp_path / "pwncat").mkdir(exist_ok=True, parents=True)
|
|
|
|
# Create our user configuration
|
|
with (tmp_path / "pwncat" / "pwncatrc").open("w") as filp:
|
|
filp.writelines(["""set -g backdoor_user "config_test"\n"""])
|
|
|
|
os.chdir(tmp_path)
|
|
|
|
# Create a manager object with default config to load our
|
|
# user configuration.
|
|
with pwncat.manager.Manager(config=None) as manager:
|
|
assert manager.config["backdoor_user"] == "config_test"
|
|
finally:
|
|
# Restore the environment
|
|
if old_home is not None:
|
|
os.environ["XDG_DATA_HOME"] = old_home
|
|
else:
|
|
del os.environ["XDG_DATA_HOME"]
|