Skip to content

Commit

Permalink
Tests: added test for uploading files with SSL.
Browse files Browse the repository at this point in the history
* * *
[mq]: multipart
  • Loading branch information
i4ki committed Feb 5, 2020
1 parent d3e218a commit 12e15ba
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/python/upload/wsgi.py
@@ -0,0 +1,27 @@
from tempfile import TemporaryFile
import os, cgi

def read(environ):
length = int(environ.get('CONTENT_LENGTH', 0))

body = TemporaryFile(mode='w+b')
body.write(bytes(environ['wsgi.input'].read(length)))
body.seek(0)

environ['wsgi.input'] = body
return body

def application(environ, start_response):
file = read(environ)

form = cgi.FieldStorage(fp=file, environ=environ, keep_blank_values=True)

filename = form['file'].filename
data = filename.encode() + form['file'].file.read()

start_response('200 OK', [
('Content-Type', 'text/plain'),
('Content-Length', str(len(data))),
])

return data
22 changes: 22 additions & 0 deletions test/test_tls.py
@@ -1,3 +1,5 @@
import io
import os
import re
import ssl
import subprocess
Expand Down Expand Up @@ -591,5 +593,25 @@ def test_tls_url_scheme(self):
'url scheme https',
)

def test_tls_big_upload(self):
self.load('upload')

self.certificate()

self.add_tls(application='upload')

filename = 'test.txt'
data = '0123456789' * 9000

res = self.post_ssl(body={
'file': {
'filename': filename,
'type': 'text/plain',
'data': io.StringIO(data),
}
})
self.assertEqual(res['status'], 200, 'status ok')
self.assertEqual(res['body'], filename + data)

if __name__ == '__main__':
TestTLS.main()

0 comments on commit 12e15ba

Please sign in to comment.