0001-misc-limit-filename-length-72567.patch
fargo/fargo/models.py | ||
---|---|---|
129 | 129 |
self.content_hash = utils.sha256_of_file(self.content) |
130 | 130 |
if not self.mime_type: |
131 | 131 |
self.mime_type = utils.get_mime_type(self.content.file.name) or '' |
132 |
if self.content.name and len(self.content.name) > 200: |
|
133 |
file_root, file_ext = os.path.splitext(self.content.name) |
|
134 |
file_root, file_ext = file_root[:150], file_ext[:50] |
|
135 |
self.content.name = file_root + file_ext |
|
132 | 136 |
super().save(*args, **kwargs) |
133 | 137 | |
134 | 138 |
@property |
tests/test_api.py | ||
---|---|---|
139 | 139 |
assert doc.get_download_url() == '/%s/download/monfichier%%252018-06-2017.pdf' % doc.pk |
140 | 140 |
login(app, user=john_doe) |
141 | 141 |
app.get(doc.get_download_url(), status=200) |
142 | ||
143 | ||
144 |
def test_push_document_long_filename(app, admin_user, john_doe): |
|
145 |
login(app) |
|
146 |
url = '/api/documents/push/' |
|
147 |
data = { |
|
148 |
'user_email': john_doe.email, |
|
149 |
'origin': 'wcs', |
|
150 |
'file_b64_content': base64.b64encode(b'whatever').decode(), |
|
151 |
'file_name': '%s.pdf' % ('abc' * 100), |
|
152 |
} |
|
153 |
response = app.post_json(url, params=data, status=200) |
|
154 |
assert response.json['result'] == 1 |
|
155 |
assert models.Document.objects.count() == 1 |
|
156 |
doc = models.UserDocument.objects.first() |
|
157 |
assert doc.filename.startswith('abc') and doc.filename.endswith('.pdf') |
|
158 |
assert doc.get_download_url().endswith('.pdf') |
|
159 |
login(app, user=john_doe) |
|
160 |
app.get(doc.get_download_url(), status=200) |
|
142 |
- |