Univention Bugzilla – Bug 50894
check check username scheme syntax
Last modified: 2020-06-10 14:36:15 CEST
Create a config check function that verifies that schemes in the import configuration below {"scheme" (email, record_uid and username→(default, student, ...)) is valid. Check the following: * number of opening '<' and closing '>' is equal and in correct order * '[' and ']' is only allowed for '[\d*:\d*]', '[ALWAYSCOUNTER]' and '[COUNTER2]'
Test function added to checks/default.py It checks the format for each value in the "scheme" field. It can be tested by trying to import a manipulated configuration. The solution was pushed to branch troehmey/bug50894 with commit commit 07017b8a44c1b40e5a1eaa4117027ab60f05b2c7 Bug #50894: added config check function Waiting for QA
QA [troehmey/bug50894] 07017b8a4 Bug #50894: added config check function Tested with UCS: 4.4-4 errata499 UCS@school 4.4 v5 -------------------------------- Code Why is this a global value? # If a '[' or a ']' appears in a "scheme" field, it should be in one of these contexts SCHEME_ALLOWED_OCCURENCES = ("[\d*:\d*]", "[ALWAYSCOUNTER]", "[COUNTER2]") Unallowed use __of__ symbol '[' or ']'. Why do you use string? opening = string.find(value, "<", start) the same can be done with (if you use this, don't forget to remove the import) opening = value.find("<", start) I would remove the '' around the brackets, e.g. '<'. Maybe use another name like scheme_field dictionary -------------------------------- Functionality Before change: Change email-scheme: "email": "<:umlauts><firstname>.<lastname><:lower>[OUNTER2]@<maildomain>", leads to -> clara.meyer[ounter2]@wenzel-univention.intranet After change: InitialisationError: Unallowed use symbol '[' or ']'. -> also [cOUNTER2] <:umlauts><firstname>[:].<lastname><:lower>[COUNTER2]@<maildomain> -> clara.meyer3@wenzel-univention.intranet [hi [COUNTER2] -> was allowed since [COUNTER2] is in string. -> clara.meyer[hi@wenzel-univention.intranet Resulting from if any(symbol in value for symbol in ["[", "]"]): if not any(element in value for element in SCHEME_ALLOWED_OCCURENCES): raise InitialisationError("Unallowed use symbol '[' or ']'.") Suggestion: First remove the allowed cases from the string and then check if any brackets are remaining. import re # ... scheme_allowed_occurencences scheme_allowed_occurencences = ("\[\d*:\d*\]", "\[ALWAYSCOUNTER\]", "\[COUNTER2\]") rest = re.sub("|".join(scheme_allowed_occurencences), "", value) if any(symbol in rest for symbol in ["[", "]"]): raise InitialisationError("Unallowed use symbol '[' or ']'.")
As discussed also add [\d] to the allowed occurrences -> https://docs.software-univention.de/ucsschool-import-handbuch-4.4.html#configuration:unique_usernames_and_email
Issues were resolved with commit 21656e985988188082dfde852e404766652787cd Bug #50894: applied small fixes on branch troehmey/bug50894.
Thanks for the code changes! Please Merge&Build Code -> looks good. Functionality -> same as before.
Reopen for merge&build
Feature branch troehmey/bug50894 merged into 4.4 with commit d3f7f293309d1ecc27c917f5415d548355090ad4 Bug #50894: added yaml entry commit ac412b3e752dc019d692e1f48c1e4bcef93f609b Bug #50894: add changelog entry commit 865735f94150e9a96bc291fd3d017386053397ec Bug #50894: Merge branch 'troehmey/bug50894' into 4.4 successful build: Package: ucs-school-import Version: 17.0.33A~4.4.0.202004291659 Branch: ucs_4.4-0 Scope: ucs-school-4.4
Please double-check your code after merging: NameError: global name 'string' is not defined -> add the missing import string [4.4] 865735f94 Bug #50894: Merge branch 'troehmey/bug50894' into 4.4
Issue resolved with commits commit 175f8c96e71306c714cf8c6731984c5357f1c08f Bug #50894: updated yaml commit df02a6fd9b99d48e2ed330e56932987a8fe47fd6 Bug #51190: added changelog entry commit 661b733fa3bd61019b40cb619966cd72576e6507 Bug #51190: added import string on branch 4.4 Successful build: Package: ucs-school-import Version: 17.0.34A~4.4.0.202004301134 Branch: ucs_4.4-0 Scope: ucs-school-4.4 Please apologize my mistake.
Of course - No problem. Code -> ok changelog -> ok yaml -> ok Functionality -> works like before (tested in 4.4)
Sorry to reopen this. The test function "test_username_handler()" in 113_import_factory_configurability fails in Jenkins: https://jenkins.knut.univention.de:8181/job/UCSschool-4.4/job/Install%20Singleserver/467/Config=s4,TestGroup=base1,UCSRelease=public/testReport/junit/90_ucsschool/113_import_factory_configurability/master201/ I forgot to mention this before: The UCS@school import supports creating additional COUNTER variables. The test test_username_handler() in 113_import_factory_configurability tests that functionality. To fill "scheme_allowed_occurences" in ucs-school-import/.../checks/defaults.py -> DefaultConfigurationChecks.test_scheme_valid_format() don't statically add "[ALWAYSCOUNTER]" and "[COUNTER2]", but use "<UsernameHandler [subclass] instance>.counter_variable_to_function.keys()". In test_scheme_valid_format() create a UsernameHandler instance using "factory.make_username_handler()". This will make sure possible class overrides (like in the test) will have been activated. To get a factory instance run "factory = setup_factory(config['factory'])" factory.make_username_handler(15).counter_variable_to_function.keys() ['[COUNTER2]', '[FOO]', '[ALWAYSCOUNTER]']
Sorry - was easier to code than to explain. [4.4] d44c9829a Bug #50894: include custom username counter variables in schema test [4.4] e53b76f2b Bug #50894: advisory update
@Daniel thanks for the improvements! code -> looks even better. changelog -> ok yaml -> ok functionality -> works test -> passed locally and on jenkins https://jenkins.knut.univention.de:8181/job/UCSschool-4.4/job/Install%20Singleserver/474/Config=s4,TestGroup=base1,UCSRelease=public/testReport/90_ucsschool/113_import_factory_configurability/
UCS@school 4.4 v5 has been released (errata update to the release). https://docs.software-univention.de/changelog-ucsschool-4.4v5-de.html If this error occurs again, please clone this bug.