Skip to content

Commit 6e3df14

Browse files
authored
Unit tests to cover most of mig/shared/base.py (#366)
Unit tests to cover about 90% of `mig/shared/base.py` wrapping existing self-tests and adding tests for most helper functions. Uses shared `before_each` method and `testconfig` provisioning to isolate configuration between tests. * Adds fundamental coverage of client_dir_id, get_site_base_url, mask_creds, extract_field, distinguished_name_to_user, fill_distinguished_name, fill_user, canonical_user, generate_https_urls, allow_script, canonical_user_with_peers, invisible_path, requested_page, verify_local_url, brief_list and auth_type_description. * Cover requested_url_base with some pending TODOs in corner cases of the implementation. * Splits out legacy self-tests as suggested in GH review explicitly wrapping it as legacy_main for simplicity.
1 parent 9327dae commit 6e3df14

File tree

2 files changed

+1348
-3
lines changed

2 files changed

+1348
-3
lines changed

mig/shared/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def canonical_user(configuration, user_dict, limit_fields):
303303
# TODO: is this right for py2+3 support now?
304304
# IMPORTANT: we get utf8 coded bytes here and title() treats such
305305
# chars as word termination. Temporarily force to unicode.
306-
#val = force_utf8(force_unicode(val).title())
306+
# val = force_utf8(force_unicode(val).title())
307307
val = force_native_str(force_unicode(val).title())
308308
elif key == 'email':
309309
val = val.lower()
@@ -951,7 +951,8 @@ def auth_type_description(configuration, auth_type=keyword_all):
951951
return auth_map.get(auth_type, 'UNKNOWN')
952952

953953

954-
if __name__ == '__main__':
954+
def legacy_main(_exit=sys.exit, _print=print):
955+
"""Run module self-tests"""
955956
orig_id = '/C=DK/ST=NA/L=NA/O=Ajax Inc/OU=NA/CN=John Doe/emailAddress=john.doe@ajaxinc.org'
956957
client_dir = client_id_dir(orig_id)
957958
client_id = client_dir_id(client_dir)
@@ -986,7 +987,8 @@ def auth_type_description(configuration, auth_type=keyword_all):
986987
print(" %s: %s" % (path, not invisible_path(path)))
987988

988989
from mig.shared.conf import get_configuration_object
989-
configuration = get_configuration_object()
990+
configuration = get_configuration_object(
991+
skip_log=True, disable_auth_log=True)
990992
print("check script restrictions:")
991993
for script_name in ['reqoid.py', 'ls.py', 'sharelink.py', 'put']:
992994
(allow, msg) = allow_script(configuration, script_name, '')
@@ -1032,3 +1034,7 @@ def auth_type_description(configuration, auth_type=keyword_all):
10321034
(script_uri, requested_url_base()))
10331035
print("Found unsafe page for %r : %s" %
10341036
(script_uri, requested_page(include_unsafe=True)))
1037+
1038+
1039+
if __name__ == '__main__':
1040+
legacy_main()

0 commit comments

Comments
 (0)