Univention Bugzilla – Bug 30342
udm users/user returns broken jpegPhoto data (double base64 encoded)
Last modified: 2013-11-19 06:43:29 CET
udm users/user returns broken jpegPhoto data: jpegPhoto: Lw== This is caused by double base64 encoding (unmapBase64 + syntax.jpegPhoto).
Created attachment 5057 [details] avoid broken jpegPhoto syntax
How did the problem happen? Via the CLI? An even better syntax choice would be Base64Upload (as it is used for userCertificate).
Created attachment 5422 [details] fixBase64Syntax and jpegPhoto @Alex: you are right. For another case I implemented a specialized GzipBase64Upload syntax, maybe its a good idea to define a similar thing here which uses e.g. the builtin imghdr python module to do basic content validation. Looking at this stuff again, I think the base64 en/decoding should be done in univention.admin.syntax only and removed from univention.admin.mapping. It's useless to parse the input in univention.admin.syntax and then throw the result away just to do the same again in the mapping part on the way to LDAP. The mapping was introduced for users/user jpegPhoto and userCertificate only. The attached patch fixes this , so base64 handling is done in the syntax.parse/tostring part exclusively.
I simply corrected the jpegPhoto syntax. Though, it would be a good idea to think about the mapping concept in general. Everything the mappings do right now could be moved to the syntax classes as well: Bug #32564. svn 43912
Checking for text[0] does not make to much sense, does it?
Also, as noted above, I would recommend the inclusion of a parse method, which does def parse(self, text): try: value=base64.decode(text) assert imghdr.what(None, value) == 'jpeg' except: raise uexceptions.valueError('Value must be Base64 encoded jpeg') Otherwise the syntax is not very useful at all.
Should use base64.b64encode and base64.b64decode to avoid line wrapping.
Adapted.
REOPEN: code still uses base64.encodestring
(In reply to Erik Damrose from comment #9) > REOPEN: > code still uses base64.encodestring Corrected. univention-directory-manager-modules (9.0.41-1) svn r44622
Code + Changelog OK -> Verified
UCS 3.2 has been released: http://docs.univention.de/release-notes-3.2-en.html http://docs.univention.de/release-notes-3.2-de.html If this error occurs again, please use "Clone This Bug".