fix: Improve validation on documents.import endpoint
This commit is contained in:
@ -815,7 +815,12 @@ router.post("documents.unstar", auth(), async (ctx) => {
|
|||||||
|
|
||||||
router.post("documents.create", auth(), createDocumentFromContext);
|
router.post("documents.create", auth(), createDocumentFromContext);
|
||||||
router.post("documents.import", auth(), async (ctx) => {
|
router.post("documents.import", auth(), async (ctx) => {
|
||||||
|
if (!ctx.is("multipart/form-data")) {
|
||||||
|
throw new InvalidRequestError("Request type must be multipart/form-data");
|
||||||
|
}
|
||||||
|
|
||||||
const file: any = Object.values(ctx.request.files)[0];
|
const file: any = Object.values(ctx.request.files)[0];
|
||||||
|
ctx.assertPresent(file, "file is required");
|
||||||
|
|
||||||
const user = ctx.state.user;
|
const user = ctx.state.user;
|
||||||
authorize(user, "create", Document);
|
authorize(user, "create", Document);
|
||||||
|
@ -1524,6 +1524,18 @@ describe("#documents.unstar", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#documents.import", () => {
|
||||||
|
it("should error if no file is passed", async () => {
|
||||||
|
const user = await buildUser();
|
||||||
|
const res = await server.post("/api/documents.import", {
|
||||||
|
body: {
|
||||||
|
token: user.getJwtToken(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res.status).toEqual(400);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("#documents.create", () => {
|
describe("#documents.create", () => {
|
||||||
it("should create as a new document", async () => {
|
it("should create as a new document", async () => {
|
||||||
const { user, collection } = await seed();
|
const { user, collection } = await seed();
|
||||||
|
Reference in New Issue
Block a user