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:
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.
Checking for text 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):
assert imghdr.what(None, value) == 'jpeg'
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.
code still uses base64.encodestring
(In reply to Erik Damrose from comment #9)
> code still uses base64.encodestring
Code + Changelog OK
UCS 3.2 has been released:
If this error occurs again, please use "Clone This Bug".