Bad Assumption in AcceptableMimeType, Leading to "Invalid MIME type"
- Dominant language
- Python
- Stars
- 157
- Forks
- 131
- PR merge metrics
- No merged PRs in 30d
Description
The function `AcceptableMimeType` in `base/py/util.py` incorrectly assumes that all mimetypes will have a forward slash within them:
```
def AcceptableMimeType(accept_patterns, mime_type):
"""Return True iff mime_type is acceptable for one of accept_patterns.
Note that this function assumes that all patterns in accept_patterns
will be simple types of the form "type/subtype", where one or both
of these can be "*". We do not support parameters (i.e. "; q=") in
patterns.
Args:
accept_patterns: list of acceptable MIME types.
mime_type: the mime type we would like to match.
Returns:
Whether or not mime_type matches (at least) one of these patterns.
"""
if '/' not in mime_type:
raise exceptions.InvalidUserInputError(
'Invalid MIME type: "%s"' % mime_type)
```
This assumption fails for `.p12` files, which are used for server-to-server authentication. The function `mimetypes.guess_type` returns `x-pkcs12` for `.p12` files instead of `application/x-pkcs12`. This may be a bug with `mimetypes`, but it should nevertheless be handled properly by the `apitools`.
Contributor guide
Assessment
This issue has not been assessed yet.