mirror of
https://github.com/outline/outline.git
synced 2026-12-03 01:59:03 +03:00
fix: Keep attachments private when S3 ACLs are disabled (#13867)
This commit is contained in:
1 parent
014dd04606
commit
fcb5f7934d
3 files changed
+68
-2
No files matched your search
@@ -1,6 +1,39 @@
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import env from "@server/env";
|
||||
import AttachmentHelper from "./AttachmentHelper";
|
||||
|
||||
describe("AttachmentHelper", () => {
|
||||
describe("presetToAcl", () => {
|
||||
it("uses a private attachment ACL when S3 object ACLs are disabled", () => {
|
||||
const original = env.AWS_S3_ACL;
|
||||
env.AWS_S3_ACL = "";
|
||||
|
||||
try {
|
||||
expect(
|
||||
AttachmentHelper.presetToAcl(AttachmentPreset.DocumentAttachment)
|
||||
).toBe("private");
|
||||
expect(AttachmentHelper.presetToAcl(AttachmentPreset.Avatar)).toBe(
|
||||
"public-read"
|
||||
);
|
||||
} finally {
|
||||
env.AWS_S3_ACL = original;
|
||||
}
|
||||
});
|
||||
|
||||
it("uses a configured attachment ACL", () => {
|
||||
const original = env.AWS_S3_ACL;
|
||||
env.AWS_S3_ACL = "public-read";
|
||||
|
||||
try {
|
||||
expect(
|
||||
AttachmentHelper.presetToAcl(AttachmentPreset.DocumentAttachment)
|
||||
).toBe("public-read");
|
||||
} finally {
|
||||
env.AWS_S3_ACL = original;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("getKey", () => {
|
||||
it("should return the correct key for a private attachment", () => {
|
||||
const key = AttachmentHelper.getKey({
|
||||
|
||||
@@ -70,14 +70,14 @@ export default class AttachmentHelper {
|
||||
* Get the ACL to use for a given attachment preset
|
||||
*
|
||||
* @param preset The preset to use
|
||||
* @returns A valid S3 ACL
|
||||
* @returns A valid attachment ACL
|
||||
*/
|
||||
static presetToAcl(preset: AttachmentPreset) {
|
||||
switch (preset) {
|
||||
case AttachmentPreset.Avatar:
|
||||
return "public-read";
|
||||
default:
|
||||
return env.AWS_S3_ACL;
|
||||
return env.AWS_S3_ACL || "private";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -167,6 +167,39 @@ describe("#attachments.create", () => {
|
||||
expect(res.status).toEqual(200);
|
||||
});
|
||||
|
||||
it("should create a private document attachment when S3 object ACLs are disabled", async () => {
|
||||
const original = env.AWS_S3_ACL;
|
||||
env.AWS_S3_ACL = "";
|
||||
|
||||
try {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/attachments.create", user, {
|
||||
body: {
|
||||
name: "test.png",
|
||||
contentType: "image/png",
|
||||
size: 1000,
|
||||
documentId: document.id,
|
||||
preset: AttachmentPreset.DocumentAttachment,
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
const body = await res.json();
|
||||
const attachment = await Attachment.findByPk(body.data.attachment.id, {
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
expect(attachment.acl).toBe("private");
|
||||
expect(body.data.form).toBeDefined();
|
||||
} finally {
|
||||
env.AWS_S3_ACL = original;
|
||||
}
|
||||
});
|
||||
|
||||
it("should return PUT data when AWS_S3_UPLOAD_METHOD is put", async () => {
|
||||
const original = env.AWS_S3_UPLOAD_METHOD;
|
||||
env.AWS_S3_UPLOAD_METHOD = "put";
|
||||
|
||||
Reference in new issue
Block a user