1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-24 17:45:40 +01:00
pwncat/tests/test_manager.py

52 lines
1.3 KiB
Python
Raw Normal View History

2021-04-10 21:52:47 +02:00
#!/usr/bin/env python3
import io
import pwncat.manager
def test_config_fileobj():
configuration = io.StringIO(
"""
set -g db "memory://"
2021-04-10 21:52:47 +02:00
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)
2021-04-10 21:52:47 +02:00
# 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"]