Example #1
0
    def test_create_submit_multi(self):
        obj = json.loads(self.post("/tasks/create/submit", data={
            "files": [
                werkzeug.FileStorage(open("tests/files/pdf0.pdf", "rb")),
                werkzeug.FileStorage(open("tests/files/pdf0.zip", "rb")),
                werkzeug.FileStorage(open("tests/files/pdf0.tgz", "rb")),
            ],
        }).data)
        assert obj["submit_id"] == 1
        assert obj["task_ids"] == [1, 2, 3]

        t1 = db.view_task(1)
        assert t1.category == "file"
        assert t1.target.endswith("pdf0.pdf")
        assert t1.options == {
            "procmemdump": "yes",
        }
        assert os.path.getsize(t1.target) == 680

        t2 = db.view_task(2)
        assert t2.category == "archive"
        assert t2.target.endswith("pdf0.zip")
        assert t2.options == {
            "filename": "files/pdf0.pdf",
            "procmemdump": "yes",
        }

        t3 = db.view_task(3)
        assert t3.category == "archive"
        assert t3.target.endswith("pdf0.zip")
        assert t3.options == {
            "filename": "files/pdf0.pdf",
            "procmemdump": "yes",
        }
Example #2
0
 def create_task(self, filename="a.js", content="eval('alert(1)')"):
     r = self.post("/tasks/create/file",
                   data={
                       "file":
                       werkzeug.FileStorage(io.BytesIO(content), filename),
                   })
     return json.loads(r.data)["task_id"]
Example #3
0
 def test_create_file_abs(self):
     filepath = os.path.join(temppath(), "foobar.txt")
     r = self.post("/tasks/create/file", data={
         "file": werkzeug.FileStorage(io.BytesIO("foobar"), filepath),
     })
     t = db.view_task(json.loads(r.data)["task_id"])
     assert open(t.target, "rb").read() == "foobar"
     assert t.target != filepath
     assert t.target.endswith("foobar.txt")
Example #4
0
 def ajax_upload(self, path, extension):
     """ """
     file = werkzeug.FileStorage(stream=request.stream)
     timestamp = str(int(time.time() * 1000000000))
     self.filename = timestamp + '.' + extension
     image_path = os.path.join(path, self.filename)
     file.save(image_path)
     self.image = Image.open(image_path)
     self.extension = self.image.format.lower()
     return self.filename
Example #5
0
 def test_create_submit_abs(self):
     filepath = os.path.join(temppath(), "foobar.bat")
     r = self.post("/tasks/create/submit", data={
         "file": werkzeug.FileStorage(io.BytesIO("foobar"), filepath),
     })
     task_ids = json.loads(r.data)["task_ids"]
     assert len(task_ids) == 1
     t = db.view_task(task_ids[0])
     assert open(t.target, "rb").read() == "foobar"
     assert t.target != filepath
     assert t.target.endswith("foobar.bat")
def get_input_file(request):
    """Returns the input file from the POST request (no matter if it was sent as
    a file named 'input' or a form field named 'input').
    Returns None if the POST request does not have an 'input' file.
    """
    if 'input' in request.files:
        return request.files['input']
    elif 'input' in request.form:
        input_string = request.form['input']
        stringio_file = io.StringIO(input_string)
        return werkzeug.FileStorage(stringio_file, 'input.ext')
Example #7
0
 def test_create_submit_opts(self):
     obj = json.loads(self.post("/tasks/create/submit", data={
         "files": werkzeug.FileStorage(open("tests/files/pdf0.pdf", "rb")),
         "options": "procmemdump=no,free=yes",
         "memory": True,
         "enforce_timeout": True,
     }).data)
     assert obj["submit_id"] == 1
     assert obj["task_ids"] == [1]
     t = db.view_task(1)
     assert t.memory is True
     assert t.enforce_timeout is True
     assert t.options == {
         "free": "yes", "procmemdump": "no"
     }