Univention Bugzilla – Bug 42478
Simplify UsernameHandler.format_username() and increase robustness
Last modified: 2016-12-12 13:10:19 CET
Created attachment 8027 [details]
The rewritten function makes things like:
only once instead of for each case once.
It raises always an error if the username was shortened to an empty string (not only in one special case).
It has a mccabe complexity of 7 instead of 14.
It raises already if two [ALWAYSCOUNTER] patterns are used instead of 3.
It allows [foo] in the username not to raise an error but actually leave it this way (the [ ] are replaced by the bad character removal).
The maxlength is only substracted by 3 len('999') if a counter is used.
For each case a doctest is written. It has 100% coverage.
Another thing in the original function is that:
Will use the same number. Resulting in username like:
But I kept this because we already released this and there might be existing LDAP entries which needed to be cared about in the counter functions.
The best idea would be to replace the [..] part by an unique string.
The function doesn't produce illegal usernames anymore. Currently it might produces the following:
Username 'abcd.ef' too long, shortened to 'abcd.'.
→ A username with trailing dot
*** Bug 42472 has been marked as a duplicate of this bug. ***
r74308 | Bug #42478: Simplify UsernameHandler.format_username() and increase robustness
r74309 | YAML Bug #42478
Created attachment 8215 [details]
For the 100% coverage of the docstring:
# apt-get install python-coverage
# python-coverage run cover_username_handler.py
# python-coverage report | grep username_handler
/usr/share/pyshared/ucsschool/importer/utils/username_handler 78 13 83%
cover_username_handler 17 0 100%
→ the 17% missing percent are the overridden methods which would do LDAP interaction
# python-coverage html
r74370: fixed 90_ucsschool/215_import-users_illegal_chars_in_username_v2
r74372: add test with moved COUNTER variable to 90_ucsschool/215_import-users_illegal_chars_in_username
OK: code (very concise:)
OK: automated tests:
OK: "[..]" other than those in counter_variable_to_function.keys() don't lead to an error anymore
OK: correct handling of username length and dot-at-ends
OK: [VARIABLE] can move inside scheme:username (as long as the rest of the template isn't changed) and the counter keeps being used (nice!)
(In reply to Daniel Tröder from comment #5)
> r74370: fixed 90_ucsschool/215_import-users_illegal_chars_in_username_v2
> r74372: add test with moved COUNTER variable to
Forgot to build it yesterday - won't be in jenkins today.
OK: r74388 + 74389 (remove duplicated code, advisory update)
UCS@school 4.1 R2 v9 has been released.