mirror of
https://github.com/outline/outline.git
synced 2026-11-23 06:11:04 +03:00
fix: Validate that shares contain only a documentId or collectionId (#12098)
* fix: Validate that shares contain only a documentId or collectionId * Restore test
This commit is contained in:
1 parent
04debcb607
commit
4dd24b59ad
2 files changed
+63
-14
No files matched your search
@@ -87,7 +87,13 @@ export const SharesCreateSchema = BaseSchema.extend({
|
||||
})
|
||||
.refine((obj) => !(isEmpty(obj.collectionId) && isEmpty(obj.documentId)), {
|
||||
error: "one of collectionId or documentId is required",
|
||||
}),
|
||||
})
|
||||
.refine(
|
||||
(obj) => !(!isEmpty(obj.collectionId) && !isEmpty(obj.documentId)),
|
||||
{
|
||||
error: "only one of collectionId or documentId may be provided",
|
||||
}
|
||||
),
|
||||
});
|
||||
|
||||
export type SharesCreateReq = z.infer<typeof SharesCreateSchema>;
|
||||
|
||||
@@ -573,18 +573,11 @@ describe("#shares.create", () => {
|
||||
|
||||
it("should not allow creating a share for a document in another team", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
// document belongs to a completely different team
|
||||
const otherDocument = await buildDocument();
|
||||
|
||||
const res = await server.post("/api/shares.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: collection.id,
|
||||
documentId: otherDocument.id,
|
||||
},
|
||||
});
|
||||
@@ -593,23 +586,73 @@ describe("#shares.create", () => {
|
||||
|
||||
it("should not allow creating a published share for a document in another team", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
const otherDocument = await buildDocument();
|
||||
|
||||
const res = await server.post("/api/shares.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: collection.id,
|
||||
documentId: otherDocument.id,
|
||||
published: true,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
|
||||
it("should not allow creating a share for a collection in another team", async () => {
|
||||
const user = await buildUser();
|
||||
const otherCollection = await buildCollection();
|
||||
|
||||
const res = await server.post("/api/shares.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: otherCollection.id,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(403);
|
||||
});
|
||||
|
||||
it("should not allow creating a share with both a collectionId and documentId", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/shares.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: collection.id,
|
||||
documentId: document.id,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(400);
|
||||
});
|
||||
|
||||
it("should not allow creating a published share with both a collectionId and documentId", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
const document = await buildDocument({
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/shares.create", {
|
||||
body: {
|
||||
token: user.getJwtToken(),
|
||||
collectionId: collection.id,
|
||||
documentId: document.id,
|
||||
published: true,
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#shares.info", () => {
|
||||
|
||||
Reference in new issue
Block a user