From 08068e0a5c70ef8d5ef94c20952d9aa15ba6c8dc Mon Sep 17 00:00:00 2001 From: Steven Guikal Date: Mon, 4 Oct 2021 13:30:25 -0400 Subject: [PATCH] fix(FastAPI): use configured letter case for SSH fingerprints Currently, the config parser converts all keys to lowercase which is inconsistent with the old PHP behavior. This has been fixed and relevant fingerprint-getting functions have been simplified without changes in behavior. Signed-off-by: Steven Guikal --- aurweb/config.py | 8 ++++---- aurweb/util.py | 8 +------- test/test_homepage.py | 4 +++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/aurweb/config.py b/aurweb/config.py index 52fadda2..aa111f15 100644 --- a/aurweb/config.py +++ b/aurweb/config.py @@ -17,6 +17,7 @@ def _get_parser(): defaults = os.environ.get('AUR_CONFIG_DEFAULTS', path + '.defaults') _parser = configparser.RawConfigParser() + _parser.optionxform = lambda option: option if os.path.isfile(defaults): with open(defaults) as f: _parser.read_file(f) @@ -48,7 +49,6 @@ def getint(section, option, fallback=None): return _get_parser().getint(section, option, fallback=fallback) -def get_section(section_name): - for section in _get_parser().sections(): - if section == section_name: - return _get_parser()[section] +def get_section(section): + if section in _get_parser().sections(): + return _get_parser()[section] diff --git a/aurweb/util.py b/aurweb/util.py index f9181811..08e6d7c6 100644 --- a/aurweb/util.py +++ b/aurweb/util.py @@ -166,10 +166,4 @@ def add_samesite_fields(response: Response, value: str): def get_ssh_fingerprints(): - fingerprints = {} - fingerprint_section = aurweb.config.get_section("fingerprints") - - if fingerprint_section: - fingerprints = {key: fingerprint_section[key] for key in fingerprint_section.keys()} - - return fingerprints + return aurweb.config.get_section("fingerprints") or {} diff --git a/test/test_homepage.py b/test/test_homepage.py index fef3532d..5c678b71 100644 --- a/test/test_homepage.py +++ b/test/test_homepage.py @@ -96,7 +96,9 @@ def test_homepage_ssh_fingerprints(get_ssh_fingerprints_mock): with client as request: response = request.get("/") - assert list(fingerprints.values())[0] in response.content.decode() + for key, value in fingerprints.items(): + assert key in response.content.decode() + assert value in response.content.decode() assert 'The following SSH fingerprints are used for the AUR' in response.content.decode()