24 lines
943 B
C++
24 lines
943 B
C++
// Route: POST /uploads/file
|
|||
|
|
#include "support/Assert.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
using molo::example::fw::Method;
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
Fixture f;
|
||
|
|
auto ok = f.client->post("/uploads/file?filename=note.txt", "hello",
|
||
|
|
"text/plain");
|
||
|
|
check(ok.status == 201, "allowed upload is 201");
|
||
|
|
check(contains(ok.body, "\"size\":5"), "size reported");
|
||
|
|
auto evil = f.client->request(Method::Post,
|
||
|
|
"/uploads/file?filename=x.bin", "data",
|
||
|
|
{{"Content-Type", "application/x-evil"}});
|
||
|
|
check(evil.status == 415, "blocked content type is 415");
|
||
|
|
auto traversal = f.client->post("/uploads/file?filename=../x.txt", "d",
|
||
|
|
"text/plain");
|
||
|
|
check(traversal.status == 400, "unsafe filename is 400");
|
||
|
|
check(f.services.uploads->list().size() == 1,
|
||
|
|
"side effect: one upload stored");
|
||
|
|
return finish("uploads/file");
|
||
|
|
}
|