Bug 54535 - make validation of ucsschool roles more robust
make validation of ucsschool roles more robust
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: Ucsschool-lib
UCS@school 5.0
Other Linux
: P5 normal (vote)
: UCS@school 5.0 v2
Assigned To: Amir Teymuri
Tobias Wenzel
:
Depends on:
Blocks: 54653
  Show dependency treegraph
 
Reported: 2022-03-10 12:02 CET by Tobias Wenzel
Modified: 2022-07-15 08:31 CEST (History)
5 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 3: Simply Wrong: The implementation doesn't match the docu
Who will be affected by this bug?: 2: Will only affect a few installed domains
How will those affected feel about the bug?: 2: A Pain – users won’t like this once they notice it
User Pain: 0.069
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Wenzel univentionstaff 2022-03-10 12:02:54 CET
ucsschool-roles with a format other than role:school:context will raise errors, e.g. in the umc

Interner Server-Fehler in "schoolwizards/users/query (schoolwizards/users)".
Request: schoolwizards/users/query (schoolwizards/users)


ucsschool/lib/models/validator.py

    errors.append(cls.validate_part_of_school(roles, schools))
  File "/usr/lib/python2.7/dist-packages/ucsschool/lib/models/validator.py", line 228, in validate_part_of_school
    missing_schools = set([s for r, c, s in roles if c == "school" and s.lower() not in schools])
ValueError: need more than 2 values to unpack


These errors come from an incorrect of the school role, but we should log an error with a better description of whats wrong.


...
e.g. the function split_roles could be refactored into one of the validation classes, log and a) return only values as tuples (r,c,s) or b) return an empty list.
Comment 2 Ole Schwiegert univentionstaff 2022-03-28 07:06:31 CEST
split_roles is a more simple implementation of get_role_info in roles.py.

I would like to see the validation module use the common function to split the roles, instead of using its own implementation. The common get_role_info also already throws exceptions for wrong and malformed roles. This could be catched and transformed into an error message.

-> I propose replacing split_role with get_role_info
Comment 3 Amir Teymuri univentionstaff 2022-03-31 17:12:10 CEST
The validate method now logs in /var/log/univention/management-console-web-server.log if non-canonical ucsschool-role strings are encountered (instead of throwing exceptions), and passes spitted strings to part_of_school and student_roles validatores otherwise.
Comment 6 Amir Teymuri univentionstaff 2022-04-05 14:03:47 CEST
Package was built!

Package: ucs-school-lib
Version: 13.0.13A~5.0.0.202204051400
Branch: ucs_5.0-0
Scope: ucs-school-5.0
Comment 7 Ole Schwiegert univentionstaff 2022-04-08 08:13:02 CEST
Manual & Automatic tests look fine,
change works,
- VERIFIED
Comment 8 Ole Schwiegert univentionstaff 2022-04-08 09:48:49 CEST
The fix for Kelvin will be implemented in Bug #54653
Comment 9 Daniel Tröder univentionstaff 2022-04-08 19:49:01 CEST
flake8...................................................................Failed
- hook id: flake8
- exit code: 1

ucs-school-lib/unittests/test_roles_valid.py:4:1: E402 module level import not at top of file
ucs-school-lib/unittests/test_roles_valid.py:5:1: E402 module level import not at top of file
ucs-school-lib/unittests/test_roles_valid.py:6:1: E402 module level import not at top of file
ucs-school-lib/unittests/test_roles_valid.py:6:1: F401 'ucsschool.lib.roles.all_roles' imported but unused
ucs-school-lib/unittests/test_roles_valid.py:36:106: E501 line too long (140 > 105 characters)
ucs-school-lib/unittests/test_roles_valid.py:146:106: E501 line too long (126 > 105 characters)
ucs-school-lib/unittests/test_roles_valid.py:158:106: E501 line too long (137 > 105 characters)
Comment 11 Amir Teymuri univentionstaff 2022-04-13 13:07:21 CEST
Package: ucs-test-ucsschool
Version: 7.3.37A~5.0.0.202204131244
Branch: ucs_5.0-0
Scope: ucs-school-5.0

Package: ucs-school-lib
Version: 13.0.15A~5.0.0.202204131253
Branch: ucs_5.0-0
Scope: ucs-school-5.0

fixed in:
1da048dcc8c10c5e516898cfc9879c8e5c1417c1
13105648be47448d593ccbc02ca072bd58bb896e
Comment 12 Tobias Wenzel univentionstaff 2022-04-14 09:25:56 CEST
QA: All OK

- changelog OK
- advisory OK
- jenkins looks good OK

-> verify
Comment 13 Tobias Wenzel univentionstaff 2022-07-15 08:31:10 CEST
UCS@school 5.0 v2 has been released.

https://docs.software-univention.de/changelog-ucsschool-5.0v2-de.html

If this error occurs again, please clone this bug.