diff --git a/mutalyzer.conf b/mutalyzer.conf index 2a35880dc0df2fc702be0235de055b7920c3c854..1cd39d230268f803b49e0f8fa55587b8b52a3004 100644 --- a/mutalyzer.conf +++ b/mutalyzer.conf @@ -117,6 +117,9 @@ resultsDir = "./var/cache" # Location of the PID file. PIDfile = "./var/batch.pid" +# Maximum size for uploaded batch input files in megabytes. +batchInputMaxSize = 5 + # The output header for NameChecking nameCheckOutHeader = "Input", "Errors | Messages", "AccNo", "Genesymbol", "Variant", "Reference Sequence Start Descr.", "Coding DNA Descr.", "Protein Descr.", "GeneSymbol Coding DNA Descr.", "GeneSymbol Protein Descr.", "Genomic Reference", "Coding Reference", "Protein Reference", "Affected Transcripts", "Affected Proteins" diff --git a/src/Modules/Config.py b/src/Modules/Config.py index f066272116e3aaffcf73bafa367b5fd32f74ecbd..62f329c4fa2a70ff3e447edaba6a23e574a1116c 100644 --- a/src/Modules/Config.py +++ b/src/Modules/Config.py @@ -108,6 +108,7 @@ class Config() : Public variables: - PIDfile ; Location of the PID file. + - batchInputMaxSize ; Max size for batch input files in bytes. """ pass @@ -208,6 +209,7 @@ class Config() : # Set thte variables neede for the Batch module. self.Batch.PIDfile = config["PIDfile"] + self.Batch.batchInputMaxSize = int(config["batchInputMaxSize"]) * 1048576 # Set the variables needed by the File module. self.File.bufSize = int(config["bufSize"]) diff --git a/src/tests/test_wsgi.py b/src/tests/test_wsgi.py index 559cd0c9c27f1c2b7153eec227dd428c0806afdc..759ffc2315476c44535222e01838893cefcb458c 100755 --- a/src/tests/test_wsgi.py +++ b/src/tests/test_wsgi.py @@ -361,6 +361,45 @@ class TestWSGI(unittest.TestCase): size=len(variants), header='Input\tStatus') + def test_batch_syntaxchecker_oldstyle(self): + """ + Submit the batch syntax checker form with old style input file. + """ + variants = ['AccNo\tGenesymbol\tMutation', + 'AB026906.1\tSDHD\tg.7872G>T', + 'NM_003002.1\t\tc.3_4insG', + 'AL449423.14\tCDKN2A_v002\tc.5_400del'] + self._batch('SyntaxChecker', + file='\n'.join(variants), + size=len(variants)-1, + header='Input\tStatus') + + def test_batch_syntaxchecker_toobig(self): + """ + Submit the batch syntax checker with a too big input file. + """ + seed = """ +Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy +nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi +enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis +nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in +hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu +feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui +blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla +facilisi.""" + file = seed + # Very crude way of creating something at least 6MB in size + while len(file) < 6000000: + file += file + r = self.app.get('/batch') + form = r.forms[0] + form['batchType'] = 'SyntaxChecker' + form['batchEmail'] = 'm.vermaat.hg@lumc.nl' + form.set('batchFile', ('test_batch_toobig.txt', + file)) + r = form.submit(status=413) + self.assertEqual(r.content_type, 'text/plain') + def test_download_py(self): """ Download a Python example client for the webservice. diff --git a/src/wsgi.py b/src/wsgi.py index 3bac3d0040756cfd6fed05d3e72636f4b8034cb7..cb5059bbc1da91f69fb69b04b499400f4f451cde 100644 --- a/src/wsgi.py +++ b/src/wsgi.py @@ -792,9 +792,12 @@ class BatchChecker: """ O = Output.Output(__file__, C.Output) + maxUploadSize = C.Batch.batchInputMaxSize + attr = {"messages" : [], "errors" : [], "debug" : [], + "maxSize" : float(maxUploadSize) / 1048576, "batchTypes" : ["NameChecker", "SyntaxChecker", "PositionConverter", @@ -823,6 +826,17 @@ class BatchChecker: # to the truth value False, so 'if inFile: ...' is not useful. if email and isEMail(email) and not inFile == None and inFile.file: + + # Todo: These error messages could be delivered trough a template + if not 'CONTENT_LENGTH' in web.ctx.environ.keys(): + web.header('Content-Type', 'text/plain') + web.ctx.status = '411 Length required' + return 'Content length required' + if int(web.ctx.environ.get('CONTENT_LENGTH')) > maxUploadSize: + web.header('Content-Type', 'text/plain') + web.ctx.status = '413 Request entity too large' + return 'Sorry, only files up to %s megabytes are accepted.' % (float(maxUploadSize) / 1048576) + D = Db.Batch(C.Db) S = Scheduler.Scheduler(C.Scheduler, D) FileInstance = File.File(C.File, O) @@ -976,11 +990,13 @@ class Uploader: try: if i.invoermethode == "file" : - if not 'Content-Length' in web.ctx.environ: + if not 'CONTENT_LENGTH' in web.ctx.environ.keys(): + web.header('Content-Type', 'text/plain') web.ctx.status = '411 Length required' return 'Content length required.' #if - if int(web.ctx.environ['Content-Length']) > maxUploadSize : + if int(web.ctx.environ.get('CONTENT_LENGTH')) > maxUploadSize : + web.header('Content-Type', 'text/plain') web.ctx.status = '413 Request entity too large' return 'Upload limit exceeded.' #if diff --git a/templates/batch.html b/templates/batch.html index a83ef9825ed80e6b4953a83768adff8c03d4fbfe..2143f8c55ca206949dd1e8904a9085c9d284f387 100644 --- a/templates/batch.html +++ b/templates/batch.html @@ -16,6 +16,7 @@ <li>Microsoft Excel file</li> <li>OpenOffice ODS file</li> </ul> + and the maximum size is <span tal:content = "maxSize"></span> megabytes. </p> <h5>We accept two types of input files, you can download examples below</h5> <h5>Old Style: