add load_test_credentials
This commit is contained in:
parent
f49029aeed
commit
27a0ff8a2e
1 changed files with 22 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import importlib
|
import importlib
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -9,7 +10,7 @@ from pytest_abra.dir_manager import DirManager
|
||||||
from pytest_abra.env_manager import EnvFile, EnvManager
|
from pytest_abra.env_manager import EnvFile, EnvManager
|
||||||
from pytest_abra.html_helper import merge_html_reports
|
from pytest_abra.html_helper import merge_html_reports
|
||||||
from pytest_abra.runner import Runner
|
from pytest_abra.runner import Runner
|
||||||
from pytest_abra.utils import rmtree
|
from pytest_abra.utils import generate_random_string, load_json_to_environ, rmtree
|
||||||
|
|
||||||
|
|
||||||
class Coordinator:
|
class Coordinator:
|
||||||
|
|
@ -36,7 +37,7 @@ class Coordinator:
|
||||||
logger.info("calling prepare_tests()")
|
logger.info("calling prepare_tests()")
|
||||||
self.DIR.create_all_dirs()
|
self.DIR.create_all_dirs()
|
||||||
self.ENV.copy_env_files(self.DIR)
|
self.ENV.copy_env_files(self.DIR)
|
||||||
# todo: create random testuser creds and load them
|
self.load_test_credentials()
|
||||||
|
|
||||||
def run_tests(self) -> None:
|
def run_tests(self) -> None:
|
||||||
logger.info("calling run_tests()")
|
logger.info("calling run_tests()")
|
||||||
|
|
@ -87,6 +88,25 @@ class Coordinator:
|
||||||
f.parent.rename(new_path)
|
f.parent.rename(new_path)
|
||||||
rmtree(trace_root_dir)
|
rmtree(trace_root_dir)
|
||||||
|
|
||||||
|
def load_test_credentials(self):
|
||||||
|
"""Load test user credentials. If not available, create them randomly.
|
||||||
|
|
||||||
|
Test users are created during testing but should be deleted after the test. In case test
|
||||||
|
users are not deleted after tests by accident, the user credentials are not known to an
|
||||||
|
attacker."""
|
||||||
|
|
||||||
|
test_credentials_path = self.DIR.STATES / "credentials_test.json"
|
||||||
|
if not test_credentials_path.is_file():
|
||||||
|
test_credentials = {
|
||||||
|
"TEST_USER": "test-" + generate_random_string(6),
|
||||||
|
"TEST_PASS": generate_random_string(12, punctuation=True),
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(test_credentials_path, "w") as json_file:
|
||||||
|
json.dump(test_credentials, json_file)
|
||||||
|
|
||||||
|
load_json_to_environ(test_credentials_path)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_runner_dict(recipes_dir: Path) -> dict[str, type[Runner]]:
|
def create_runner_dict(recipes_dir: Path) -> dict[str, type[Runner]]:
|
||||||
"""Creates a dictionary holding all the RunnerClasses that can be discovered in recipes_dir
|
"""Creates a dictionary holding all the RunnerClasses that can be discovered in recipes_dir
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue