@antelopejs/dms-media 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -10
- package/dist/acl/entries.js +20 -2
- package/dist/acl/entries.js.map +1 -1
- package/dist/asset-lifecycle.js +5 -1
- package/dist/asset-lifecycle.js.map +1 -1
- package/dist/bindings.d.ts +1 -0
- package/dist/bindings.js +36 -25
- package/dist/bindings.js.map +1 -1
- package/dist/db/models/mediaAssets.model.d.ts +3 -3
- package/dist/db/models/mediaDeclarations.model.d.ts +3 -3
- package/dist/db/models/mediaEvents.model.d.ts +3 -3
- package/dist/db/models/mediaFavorites.model.d.ts +3 -3
- package/dist/db/models/mediaFolders.model.d.ts +3 -3
- package/dist/db/models/mediaUploads.model.d.ts +3 -3
- package/dist/declared/assets.js +39 -25
- package/dist/declared/assets.js.map +1 -1
- package/dist/declared/folders.js +27 -14
- package/dist/declared/folders.js.map +1 -1
- package/dist/declared/records.d.ts +1 -0
- package/dist/declared/records.js +18 -1
- package/dist/declared/records.js.map +1 -1
- package/dist/fixed-id.d.ts +1 -0
- package/dist/fixed-id.js +16 -0
- package/dist/fixed-id.js.map +1 -0
- package/dist/library/folder-stats.d.ts +1 -1
- package/dist/library/folder-stats.js.map +1 -1
- package/dist/library/listing.d.ts +2 -0
- package/dist/library/listing.js +14 -4
- package/dist/library/listing.js.map +1 -1
- package/dist/routes/media/assets.d.ts +3 -2
- package/dist/routes/media/assets.js +15 -10
- package/dist/routes/media/assets.js.map +1 -1
- package/dist/routes/media/bulk.js +4 -4
- package/dist/routes/media/bulk.js.map +1 -1
- package/dist/routes/media/folders.js +4 -4
- package/dist/routes/media/folders.js.map +1 -1
- package/dist/routes/media/library.js +6 -12
- package/dist/routes/media/library.js.map +1 -1
- package/dist/routes/media/storage-keys.js +10 -1
- package/dist/routes/media/storage-keys.js.map +1 -1
- package/dist/test/helpers/assets.d.ts +2 -2
- package/dist/test/helpers/folders.d.ts +6 -6
- package/dist/test/helpers/permissions-world.d.ts +6 -6
- package/dist/test/integration/binding-folder-race.test.d.ts +1 -0
- package/dist/test/integration/binding-folder-race.test.js +66 -0
- package/dist/test/integration/binding-folder-race.test.js.map +1 -0
- package/dist/test/integration/declared-asset-race.test.d.ts +1 -0
- package/dist/test/integration/declared-asset-race.test.js +78 -0
- package/dist/test/integration/declared-asset-race.test.js.map +1 -0
- package/dist/test/integration/declared-folder-race.test.d.ts +1 -0
- package/dist/test/integration/declared-folder-race.test.js +43 -0
- package/dist/test/integration/declared-folder-race.test.js.map +1 -0
- package/dist/test/integration/media-activity-overview.test.js +27 -22
- package/dist/test/integration/media-activity-overview.test.js.map +1 -1
- package/dist/test/integration/media-api.test.js +9 -5
- package/dist/test/integration/media-api.test.js.map +1 -1
- package/dist/test/integration/media-bindings.test.js +16 -13
- package/dist/test/integration/media-bindings.test.js.map +1 -1
- package/dist/test/integration/media-cleanup.test.js +14 -5
- package/dist/test/integration/media-cleanup.test.js.map +1 -1
- package/dist/test/integration/media-declared-content.test.js +107 -91
- package/dist/test/integration/media-declared-content.test.js.map +1 -1
- package/dist/test/integration/media-delivery-editing.test.js +238 -215
- package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
- package/dist/test/integration/media-explorer-writes.test.js +131 -112
- package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
- package/dist/test/integration/media-guards.test.js +38 -37
- package/dist/test/integration/media-guards.test.js.map +1 -1
- package/dist/test/integration/media-library.test.js +244 -224
- package/dist/test/integration/media-library.test.js.map +1 -1
- package/dist/test/integration/media-linked-subfolders.test.js +173 -158
- package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
- package/dist/test/integration/media-permissions.test.js +31 -11
- package/dist/test/integration/media-permissions.test.js.map +1 -1
- package/dist/test/integration/media-search-query.test.js +8 -6
- package/dist/test/integration/media-search-query.test.js.map +1 -1
- package/dist/test/integration/media-search-views.test.js +12 -8
- package/dist/test/integration/media-search-views.test.js.map +1 -1
- package/dist/test/integration/media-upload-policy.test.js +228 -200
- package/dist/test/integration/media-upload-policy.test.js.map +1 -1
- package/dist/test/stack-modules.json +5 -5
- package/dist/test/unit/acl/entries.test.js +19 -0
- package/dist/test/unit/acl/entries.test.js.map +1 -1
- package/dist/test/unit/acl/resolver.test.js +9 -1
- package/dist/test/unit/acl/resolver.test.js.map +1 -1
- package/dist/test/unit/asset-lifecycle.test.d.ts +1 -0
- package/dist/test/unit/asset-lifecycle.test.js +18 -0
- package/dist/test/unit/asset-lifecycle.test.js.map +1 -0
- package/dist/test/unit/library/zip-names.test.js +6 -3
- package/dist/test/unit/library/zip-names.test.js.map +1 -1
- package/dist/test/unit/routes/storage-keys.test.d.ts +1 -0
- package/dist/test/unit/routes/storage-keys.test.js +18 -0
- package/dist/test/unit/routes/storage-keys.test.js.map +1 -0
- package/dist/test/unit/transform-ops.test.js +19 -0
- package/dist/test/unit/transform-ops.test.js.map +1 -1
- package/dist/transform-ops.js +25 -1
- package/dist/transform-ops.js.map +1 -1
- package/dist/validation/declared.schema.d.ts +6 -6
- package/dist/validation/library.schema.d.ts +4 -4
- package/dist/validation/media.schema.d.ts +5 -5
- package/dist/validation/media.schema.js +10 -6
- package/dist/validation/media.schema.js.map +1 -1
- package/frontend-vue/app/components/Explorer.vue +2 -0
- package/frontend-vue/app/components/FileProperties.vue +1 -1
- package/frontend-vue/app/components/ImageEditor.vue +5 -5
- package/frontend-vue/app/components/RecentFiles.vue +2 -2
- package/frontend-vue/app/components/UploadQueue.vue +4 -4
- package/frontend-vue/app/components/dialogs/DeleteFilesDialog.vue +1 -1
- package/frontend-vue/app/components/dialogs/ShortcutsDialog.vue +1 -1
- package/frontend-vue/app/components/dialogs/VisibilityDialog.vue +1 -1
- package/frontend-vue/app/components/explorer/ExplorerInspector.vue +1 -1
- package/frontend-vue/app/components/explorer/ExplorerSidebar.vue +2 -2
- package/frontend-vue/app/components/explorer/FolderStrip.vue +1 -1
- package/frontend-vue/app/components/explorer/GridView.vue +1 -1
- package/frontend-vue/app/components/shared/AltTextField.vue +2 -2
- package/frontend-vue/build/backend-boundary.ts +8 -3
- package/frontend-vue/eslint.config.mjs +0 -1
- package/frontend-vue/package.json +2 -2
- package/frontend-vue/pnpm-lock.yaml +45 -14
- package/frontend-vue/tests/backend-boundary.test.ts +6 -4
- package/frontend-vue/tests/fixtures/serverRender.ts +3 -3
- package/frontend-vue/tests/registration.test.ts +5 -0
- package/frontend-vue/tsconfig.json +1 -2
- package/package.json +17 -17
- package/src/acl/entries.ts +30 -7
- package/src/asset-lifecycle.ts +6 -2
- package/src/bindings.ts +41 -38
- package/src/declared/assets.ts +45 -28
- package/src/declared/folders.ts +30 -20
- package/src/declared/records.ts +31 -2
- package/src/fixed-id.ts +18 -0
- package/src/library/folder-stats.ts +1 -1
- package/src/library/listing.ts +24 -4
- package/src/routes/media/assets.ts +23 -11
- package/src/routes/media/bulk.ts +7 -5
- package/src/routes/media/folders.ts +9 -5
- package/src/routes/media/library.ts +10 -18
- package/src/routes/media/storage-keys.ts +14 -2
- package/src/test/integration/binding-folder-race.test.ts +82 -0
- package/src/test/integration/declared-asset-race.test.ts +115 -0
- package/src/test/integration/declared-folder-race.test.ts +50 -0
- package/src/test/integration/media-activity-overview.test.ts +40 -27
- package/src/test/integration/media-api.test.ts +9 -5
- package/src/test/integration/media-bindings.test.ts +17 -13
- package/src/test/integration/media-cleanup.test.ts +17 -5
- package/src/test/integration/media-declared-content.test.ts +129 -112
- package/src/test/integration/media-delivery-editing.test.ts +323 -299
- package/src/test/integration/media-explorer-writes.test.ts +161 -135
- package/src/test/integration/media-guards.test.ts +40 -38
- package/src/test/integration/media-library.test.ts +325 -296
- package/src/test/integration/media-linked-subfolders.test.ts +207 -186
- package/src/test/integration/media-permissions.test.ts +33 -14
- package/src/test/integration/media-search-query.test.ts +24 -8
- package/src/test/integration/media-search-views.test.ts +39 -32
- package/src/test/integration/media-upload-policy.test.ts +283 -254
- package/src/test/stack-modules.json +5 -5
- package/src/test/unit/acl/entries.test.ts +23 -0
- package/src/test/unit/acl/resolver.test.ts +9 -1
- package/src/test/unit/asset-lifecycle.test.ts +21 -0
- package/src/test/unit/library/zip-names.test.ts +9 -7
- package/src/test/unit/routes/storage-keys.test.ts +23 -0
- package/src/test/unit/transform-ops.test.ts +29 -1
- package/src/transform-ops.ts +32 -2
- package/src/validation/media.schema.ts +14 -15
|
@@ -73,298 +73,327 @@ async function removeLinkedFolders(): Promise<void> {
|
|
|
73
73
|
if (children.length === 0) await folderModel.delete(contentRoot._id);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
let initialConfig: DmsMediaConfig;
|
|
80
|
-
|
|
81
|
-
async function presign(
|
|
82
|
-
target: string,
|
|
83
|
-
filename: string,
|
|
84
|
-
mimetype: string,
|
|
85
|
-
size = 4,
|
|
86
|
-
) {
|
|
87
|
-
return client.post("/api/media/upload/presign", {
|
|
88
|
-
folderId: target,
|
|
89
|
-
filename,
|
|
90
|
-
size,
|
|
91
|
-
mimetype,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
76
|
+
let client: AxiosInstance;
|
|
77
|
+
let folderId: string;
|
|
78
|
+
let initialConfig: DmsMediaConfig;
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
expect(presigned.status, "presign").to.equal(HTTP_OK);
|
|
107
|
-
const target = readBody(presigned, presignBody);
|
|
108
|
-
const put = await putPresigned(target, body);
|
|
109
|
-
expect(put.status, "storage PUT").to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
|
|
110
|
-
return { resourceKey: target.resourceKey };
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
before(async function () {
|
|
114
|
-
this.timeout(40_000);
|
|
115
|
-
initialConfig = snapshotConfig();
|
|
116
|
-
RegisterAssetBinding({
|
|
117
|
-
id: PDF_BINDING_ID,
|
|
118
|
-
folderName: PDF_FOLDER_NAME,
|
|
119
|
-
field: { mimetypes: ["application/pdf"] },
|
|
120
|
-
});
|
|
121
|
-
client = authorizedClient((await ensureOwnerSession()).accessToken);
|
|
122
|
-
const folder = await client.post("/api/media/folders", {
|
|
123
|
-
name: "Upload policy",
|
|
124
|
-
});
|
|
125
|
-
expect(folder.status).to.equal(HTTP_OK);
|
|
126
|
-
folderId = readBody(folder, createdBody).id;
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
after(async () => {
|
|
130
|
-
await client.delete(`/api/media/folders/${folderId}`);
|
|
131
|
-
UnregisterAssetBinding(PDF_BINDING_ID);
|
|
132
|
-
await removeLinkedFolders();
|
|
133
|
-
configureMediaModule(initialConfig);
|
|
80
|
+
async function presign(
|
|
81
|
+
target: string,
|
|
82
|
+
filename: string,
|
|
83
|
+
mimetype: string,
|
|
84
|
+
size = 4,
|
|
85
|
+
) {
|
|
86
|
+
return client.post("/api/media/upload/presign", {
|
|
87
|
+
folderId: target,
|
|
88
|
+
filename,
|
|
89
|
+
size,
|
|
90
|
+
mimetype,
|
|
134
91
|
});
|
|
92
|
+
}
|
|
135
93
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
94
|
+
async function stage(
|
|
95
|
+
filename: string,
|
|
96
|
+
mimetype: string,
|
|
97
|
+
body: Buffer,
|
|
98
|
+
): Promise<StagedUpload> {
|
|
99
|
+
const presigned = await presign(
|
|
100
|
+
folderId,
|
|
101
|
+
filename,
|
|
102
|
+
mimetype,
|
|
103
|
+
body.byteLength,
|
|
104
|
+
);
|
|
105
|
+
expect(presigned.status, "presign").to.equal(HTTP_OK);
|
|
106
|
+
const target = readBody(presigned, presignBody);
|
|
107
|
+
const put = await putPresigned(target, body);
|
|
108
|
+
expect(put.status, "storage PUT").to.be.lessThan(HTTP_REDIRECT_BOUNDARY);
|
|
109
|
+
return { resourceKey: target.resourceKey };
|
|
110
|
+
}
|
|
139
111
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
(
|
|
156
|
-
|
|
157
|
-
|
|
112
|
+
function describeTypeRules(): void {
|
|
113
|
+
describe("accepted types", () => {
|
|
114
|
+
it("refuses HTML whatever its declared type, and types outside the allow-list", async () => {
|
|
115
|
+
const attempts = [
|
|
116
|
+
await presign(folderId, "page.html", "text/html"),
|
|
117
|
+
await presign(folderId, "page.html", "text/plain"),
|
|
118
|
+
await presign(folderId, "page.xhtml", "application/xhtml+xml"),
|
|
119
|
+
await presign(folderId, "setup.exe", "application/x-msdownload"),
|
|
120
|
+
];
|
|
121
|
+
for (const response of attempts) {
|
|
122
|
+
expect(response.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
|
|
123
|
+
expect(response.data.reason).to.equal("type_not_allowed");
|
|
124
|
+
}
|
|
125
|
+
expect(
|
|
126
|
+
(await presign(folderId, "notes.txt", "text/plain")).status,
|
|
127
|
+
).to.equal(HTTP_OK);
|
|
128
|
+
expect(
|
|
129
|
+
(await presign(folderId, "logo.svg", "image/svg+xml")).status,
|
|
130
|
+
).to.equal(HTTP_OK);
|
|
131
|
+
});
|
|
158
132
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
133
|
+
it("follows a configured allow-list but never re-enables HTML", async () => {
|
|
134
|
+
configureMediaModule({
|
|
135
|
+
...initialConfig,
|
|
136
|
+
allowedMimetypes: ["application/zip", "text/html"],
|
|
137
|
+
});
|
|
138
|
+
try {
|
|
139
|
+
expect(
|
|
140
|
+
(await presign(folderId, "a.zip", "application/zip")).status,
|
|
141
|
+
).to.equal(HTTP_OK);
|
|
142
|
+
expect((await presign(folderId, "a.png", "image/png")).status).to.equal(
|
|
143
|
+
HTTP_UNSUPPORTED_MEDIA_TYPE,
|
|
144
|
+
);
|
|
145
|
+
expect(
|
|
146
|
+
(await presign(folderId, "a.html", "text/html")).status,
|
|
147
|
+
).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
|
|
148
|
+
} finally {
|
|
149
|
+
configureMediaModule(initialConfig);
|
|
150
|
+
}
|
|
163
151
|
});
|
|
164
|
-
|
|
152
|
+
|
|
153
|
+
it("refuses a file the linked field does not accept", async () => {
|
|
154
|
+
const linked = (await fetchFolderNodes(client)).find(
|
|
155
|
+
(folder) => folder.binding === PDF_BINDING_ID,
|
|
156
|
+
);
|
|
157
|
+
expect(linked, "linked folder").to.not.equal(undefined);
|
|
158
|
+
const image = await presign(linked!.id, "photo.png", "image/png");
|
|
159
|
+
expect(image.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
|
|
160
|
+
expect(image.data.reason).to.equal("field_type");
|
|
161
|
+
expect(image.data.accepted).to.deep.equal(["application/pdf"]);
|
|
165
162
|
expect(
|
|
166
|
-
(await presign(
|
|
163
|
+
(await presign(linked!.id, "sheet.pdf", "application/pdf")).status,
|
|
167
164
|
).to.equal(HTTP_OK);
|
|
168
|
-
|
|
169
|
-
HTTP_UNSUPPORTED_MEDIA_TYPE,
|
|
170
|
-
);
|
|
171
|
-
expect((await presign(folderId, "a.html", "text/html")).status).to.equal(
|
|
172
|
-
HTTP_UNSUPPORTED_MEDIA_TYPE,
|
|
173
|
-
);
|
|
174
|
-
} finally {
|
|
175
|
-
configureMediaModule(initialConfig);
|
|
176
|
-
}
|
|
165
|
+
});
|
|
177
166
|
});
|
|
167
|
+
}
|
|
178
168
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
169
|
+
function describeQuota(): void {
|
|
170
|
+
describe("storage quota", () => {
|
|
171
|
+
it("refuses an upload past the storage quota", async () => {
|
|
172
|
+
configureMediaModule({
|
|
173
|
+
...initialConfig,
|
|
174
|
+
storageQuotaBytes: 1,
|
|
175
|
+
});
|
|
176
|
+
try {
|
|
177
|
+
const response = await presign(folderId, "notes.txt", "text/plain", 10);
|
|
178
|
+
expect(response.status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
|
|
179
|
+
expect(response.data.reason).to.equal("quota");
|
|
180
|
+
} finally {
|
|
181
|
+
configureMediaModule(initialConfig);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
192
184
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
...initialConfig,
|
|
196
|
-
|
|
185
|
+
it("checks the quota again at confirm, on the stored size", async () => {
|
|
186
|
+
const staged = await stage("late.txt", "text/plain", Buffer.from("late"));
|
|
187
|
+
configureMediaModule({ ...initialConfig, storageQuotaBytes: 1 });
|
|
188
|
+
try {
|
|
189
|
+
const confirm = await client.post("/api/media/upload/confirm", {
|
|
190
|
+
folderId,
|
|
191
|
+
resourceKey: staged.resourceKey,
|
|
192
|
+
filename: "late.txt",
|
|
193
|
+
});
|
|
194
|
+
expect(confirm.status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
|
|
195
|
+
expect(confirm.data.reason).to.equal("quota");
|
|
196
|
+
expect(await FileExists(staged.resourceKey)).to.equal(false);
|
|
197
|
+
} finally {
|
|
198
|
+
configureMediaModule(initialConfig);
|
|
199
|
+
}
|
|
197
200
|
});
|
|
198
|
-
try {
|
|
199
|
-
const response = await presign(folderId, "notes.txt", "text/plain", 10);
|
|
200
|
-
expect(response.status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
|
|
201
|
-
expect(response.data.reason).to.equal("quota");
|
|
202
|
-
} finally {
|
|
203
|
-
configureMediaModule(initialConfig);
|
|
204
|
-
}
|
|
205
201
|
});
|
|
202
|
+
}
|
|
206
203
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
function describeContentChecks(): void {
|
|
205
|
+
describe("real content", () => {
|
|
206
|
+
it("refuses a fake image at confirm, whatever the case of its type, and deletes its staged file", async () => {
|
|
207
|
+
for (const mimetype of ["image/png", "Image/PNG"]) {
|
|
208
|
+
const staged = await stage(
|
|
209
|
+
"fake.png",
|
|
210
|
+
mimetype,
|
|
211
|
+
Buffer.from("this is not a png"),
|
|
212
|
+
);
|
|
213
|
+
const confirm = await client.post("/api/media/upload/confirm", {
|
|
214
|
+
folderId,
|
|
215
|
+
resourceKey: staged.resourceKey,
|
|
216
|
+
filename: "fake.png",
|
|
217
|
+
});
|
|
218
|
+
expect(confirm.status, mimetype).to.equal(HTTP_UNPROCESSABLE_ENTITY);
|
|
219
|
+
expect(confirm.data.reason, mimetype).to.equal("invalid_image");
|
|
220
|
+
expect(await FileExists(staged.resourceKey), mimetype).to.equal(false);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("stores an image too large to probe, without its size", async function () {
|
|
225
|
+
this.timeout(60_000);
|
|
226
|
+
const jpeg = await sharp({
|
|
227
|
+
create: { width: 8, height: 6, channels: 3, background: "#808080" },
|
|
228
|
+
})
|
|
229
|
+
.jpeg()
|
|
230
|
+
.toBuffer();
|
|
231
|
+
const large = Buffer.concat([
|
|
232
|
+
jpeg,
|
|
233
|
+
Buffer.alloc(LARGER_THAN_PROBE_BYTES),
|
|
234
|
+
]);
|
|
235
|
+
const staged = await stage("large.jpg", "image/jpeg", large);
|
|
211
236
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
212
237
|
folderId,
|
|
213
238
|
resourceKey: staged.resourceKey,
|
|
214
|
-
filename: "
|
|
239
|
+
filename: "large.jpg",
|
|
215
240
|
});
|
|
216
|
-
expect(confirm.status).to.equal(
|
|
217
|
-
|
|
218
|
-
expect(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
241
|
+
expect(confirm.status, JSON.stringify(confirm.data)).to.equal(HTTP_OK);
|
|
242
|
+
const { asset } = readBody(confirm, confirmedBody);
|
|
243
|
+
expect(asset.mimetype).to.equal("image/jpeg");
|
|
244
|
+
expect(asset.size).to.equal(large.byteLength);
|
|
245
|
+
expect(asset.width ?? undefined).to.equal(undefined);
|
|
246
|
+
expect(asset.height ?? undefined).to.equal(undefined);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("confirms a text file declared with the name of an Object.prototype member", async () => {
|
|
250
|
+
configureMediaModule({ ...initialConfig, allowedMimetypes: ["*"] });
|
|
251
|
+
try {
|
|
252
|
+
for (const mimetype of ["constructor", "__proto__"]) {
|
|
253
|
+
const filename = `${mimetype.replaceAll("_", "")}.txt`;
|
|
254
|
+
const staged = await stage(
|
|
255
|
+
filename,
|
|
256
|
+
mimetype,
|
|
257
|
+
Buffer.from("plain text"),
|
|
258
|
+
);
|
|
259
|
+
const confirm = await client.post("/api/media/upload/confirm", {
|
|
260
|
+
folderId,
|
|
261
|
+
resourceKey: staged.resourceKey,
|
|
262
|
+
filename,
|
|
263
|
+
});
|
|
264
|
+
expect(confirm.status, mimetype).to.equal(HTTP_OK);
|
|
265
|
+
}
|
|
266
|
+
} finally {
|
|
267
|
+
configureMediaModule(initialConfig);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
222
270
|
});
|
|
271
|
+
}
|
|
223
272
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
273
|
+
function describeStaging(): void {
|
|
274
|
+
describe("staged files", () => {
|
|
275
|
+
it("deletes the staged file when the folder disappeared before confirm", async () => {
|
|
276
|
+
const doomed = await client.post("/api/media/folders", {
|
|
277
|
+
name: "Doomed upload target",
|
|
278
|
+
});
|
|
279
|
+
const body = Buffer.from("bytes");
|
|
280
|
+
const doomedId = readBody(doomed, createdBody).id;
|
|
281
|
+
const presigned = readBody(
|
|
282
|
+
await presign(doomedId, "x.txt", "text/plain", body.byteLength),
|
|
283
|
+
presignBody,
|
|
230
284
|
);
|
|
285
|
+
await axios.put(presigned.uploadUrl, body, {
|
|
286
|
+
headers: presigned.headers,
|
|
287
|
+
transformRequest: [(data: Buffer) => data],
|
|
288
|
+
});
|
|
289
|
+
await client.delete(`/api/media/folders/${doomedId}`);
|
|
231
290
|
const confirm = await client.post("/api/media/upload/confirm", {
|
|
291
|
+
folderId: doomedId,
|
|
292
|
+
resourceKey: presigned.resourceKey,
|
|
293
|
+
filename: "x.txt",
|
|
294
|
+
});
|
|
295
|
+
expect(confirm.status).to.be.greaterThanOrEqual(400);
|
|
296
|
+
expect(await FileExists(presigned.resourceKey)).to.equal(false);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("deletes a staged file on abort", async () => {
|
|
300
|
+
const staged = await stage(
|
|
301
|
+
"cancelled.txt",
|
|
302
|
+
"text/plain",
|
|
303
|
+
Buffer.from("cancel me"),
|
|
304
|
+
);
|
|
305
|
+
const abort = await client.post("/api/media/upload/abort", {
|
|
232
306
|
folderId,
|
|
233
307
|
resourceKey: staged.resourceKey,
|
|
234
|
-
filename: "fake.png",
|
|
235
308
|
});
|
|
236
|
-
expect(
|
|
237
|
-
expect(
|
|
238
|
-
expect(await FileExists(staged.resourceKey), mimetype).to.equal(false);
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
it("stores an image too large to probe, without its size", async function () {
|
|
243
|
-
this.timeout(60_000);
|
|
244
|
-
const jpeg = await sharp({
|
|
245
|
-
create: { width: 8, height: 6, channels: 3, background: "#808080" },
|
|
246
|
-
})
|
|
247
|
-
.jpeg()
|
|
248
|
-
.toBuffer();
|
|
249
|
-
const large = Buffer.concat([jpeg, Buffer.alloc(LARGER_THAN_PROBE_BYTES)]);
|
|
250
|
-
const staged = await stage("large.jpg", "image/jpeg", large);
|
|
251
|
-
const confirm = await client.post("/api/media/upload/confirm", {
|
|
252
|
-
folderId,
|
|
253
|
-
resourceKey: staged.resourceKey,
|
|
254
|
-
filename: "large.jpg",
|
|
309
|
+
expect(abort.status).to.equal(HTTP_OK);
|
|
310
|
+
expect(await FileExists(staged.resourceKey)).to.equal(false);
|
|
255
311
|
});
|
|
256
|
-
expect(confirm.status, JSON.stringify(confirm.data)).to.equal(HTTP_OK);
|
|
257
|
-
const { asset } = readBody(confirm, confirmedBody);
|
|
258
|
-
expect(asset.mimetype).to.equal("image/jpeg");
|
|
259
|
-
expect(asset.size).to.equal(large.byteLength);
|
|
260
|
-
expect(asset.width ?? undefined).to.equal(undefined);
|
|
261
|
-
expect(asset.height ?? undefined).to.equal(undefined);
|
|
262
|
-
});
|
|
263
312
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
279
|
-
expect(confirm.status, mimetype).to.equal(HTTP_OK);
|
|
280
|
-
}
|
|
281
|
-
} finally {
|
|
282
|
-
configureMediaModule(initialConfig);
|
|
283
|
-
}
|
|
313
|
+
it("purges staged uploads abandoned for more than a day", async () => {
|
|
314
|
+
const staged = await stage(
|
|
315
|
+
"abandoned.txt",
|
|
316
|
+
"text/plain",
|
|
317
|
+
Buffer.from("left behind"),
|
|
318
|
+
);
|
|
319
|
+
expect(await runPurgeStaging(new Date())).to.equal(0);
|
|
320
|
+
expect(await FileExists(staged.resourceKey)).to.equal(true);
|
|
321
|
+
const purged = await runPurgeStaging(
|
|
322
|
+
new Date(Date.now() + PURGE_HORIZON_MS),
|
|
323
|
+
);
|
|
324
|
+
expect(purged).to.be.greaterThanOrEqual(1);
|
|
325
|
+
expect(await FileExists(staged.resourceKey)).to.equal(false);
|
|
326
|
+
});
|
|
284
327
|
});
|
|
328
|
+
}
|
|
285
329
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
330
|
+
function describeStoredMetadata(): void {
|
|
331
|
+
describe("stored names and sizes", () => {
|
|
332
|
+
it("suggests free names for duplicates, ignoring case", async () => {
|
|
333
|
+
await uploadPixelPng(client, folderId);
|
|
334
|
+
const response = await client.post("/api/media/upload/names", {
|
|
335
|
+
folderId,
|
|
336
|
+
filenames: ["pixel.png", "PIXEL.png", "other.png"],
|
|
337
|
+
});
|
|
338
|
+
expect(response.status).to.equal(HTTP_OK);
|
|
339
|
+
expect(response.data.names).to.deep.equal([
|
|
340
|
+
"pixel (2).png",
|
|
341
|
+
"PIXEL (3).png",
|
|
342
|
+
null,
|
|
343
|
+
]);
|
|
299
344
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
345
|
+
|
|
346
|
+
it("stores the displayed size of an EXIF-rotated photo", async () => {
|
|
347
|
+
const body = await sharp({
|
|
348
|
+
create: { width: 20, height: 10, channels: 3, background: "blue" },
|
|
349
|
+
})
|
|
350
|
+
.jpeg()
|
|
351
|
+
.withMetadata({ orientation: EXIF_ROTATED_RIGHT })
|
|
352
|
+
.toBuffer();
|
|
353
|
+
const asset = await uploadAsset(
|
|
354
|
+
client,
|
|
355
|
+
folderId,
|
|
356
|
+
"portrait.jpg",
|
|
357
|
+
"image/jpeg",
|
|
358
|
+
body,
|
|
359
|
+
);
|
|
360
|
+
expect(asset.width).to.equal(10);
|
|
361
|
+
expect(asset.height).to.equal(20);
|
|
305
362
|
});
|
|
306
|
-
expect(confirm.status).to.be.greaterThanOrEqual(400);
|
|
307
|
-
expect(await FileExists(presigned.resourceKey)).to.equal(false);
|
|
308
363
|
});
|
|
364
|
+
}
|
|
309
365
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
366
|
+
describe("[integration] media upload policy — types, quota, real content and staging", () => {
|
|
367
|
+
before(async function () {
|
|
368
|
+
this.timeout(40_000);
|
|
369
|
+
initialConfig = snapshotConfig();
|
|
370
|
+
RegisterAssetBinding({
|
|
371
|
+
id: PDF_BINDING_ID,
|
|
372
|
+
folderName: PDF_FOLDER_NAME,
|
|
373
|
+
field: { mimetypes: ["application/pdf"] },
|
|
374
|
+
});
|
|
375
|
+
client = authorizedClient((await ensureOwnerSession()).accessToken);
|
|
376
|
+
const folder = await client.post("/api/media/folders", {
|
|
377
|
+
name: "Upload policy",
|
|
319
378
|
});
|
|
320
|
-
expect(
|
|
321
|
-
|
|
379
|
+
expect(folder.status).to.equal(HTTP_OK);
|
|
380
|
+
folderId = readBody(folder, createdBody).id;
|
|
322
381
|
});
|
|
323
382
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
);
|
|
330
|
-
expect(await runPurgeStaging(new Date())).to.equal(0);
|
|
331
|
-
expect(await FileExists(staged.resourceKey)).to.equal(true);
|
|
332
|
-
const purged = await runPurgeStaging(
|
|
333
|
-
new Date(Date.now() + PURGE_HORIZON_MS),
|
|
334
|
-
);
|
|
335
|
-
expect(purged).to.be.greaterThanOrEqual(1);
|
|
336
|
-
expect(await FileExists(staged.resourceKey)).to.equal(false);
|
|
383
|
+
after(async () => {
|
|
384
|
+
await client.delete(`/api/media/folders/${folderId}`);
|
|
385
|
+
UnregisterAssetBinding(PDF_BINDING_ID);
|
|
386
|
+
await removeLinkedFolders();
|
|
387
|
+
configureMediaModule(initialConfig);
|
|
337
388
|
});
|
|
338
389
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const response = await client.post("/api/media/upload/names", {
|
|
342
|
-
folderId,
|
|
343
|
-
filenames: ["pixel.png", "PIXEL.png", "other.png"],
|
|
344
|
-
});
|
|
345
|
-
expect(response.status).to.equal(HTTP_OK);
|
|
346
|
-
expect(response.data.names).to.deep.equal([
|
|
347
|
-
"pixel (2).png",
|
|
348
|
-
"PIXEL (3).png",
|
|
349
|
-
null,
|
|
350
|
-
]);
|
|
390
|
+
afterEach(() => {
|
|
391
|
+
configureMediaModule(initialConfig);
|
|
351
392
|
});
|
|
352
393
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
.withMetadata({ orientation: EXIF_ROTATED_RIGHT })
|
|
359
|
-
.toBuffer();
|
|
360
|
-
const asset = await uploadAsset(
|
|
361
|
-
client,
|
|
362
|
-
folderId,
|
|
363
|
-
"portrait.jpg",
|
|
364
|
-
"image/jpeg",
|
|
365
|
-
body,
|
|
366
|
-
);
|
|
367
|
-
expect(asset.width).to.equal(10);
|
|
368
|
-
expect(asset.height).to.equal(20);
|
|
369
|
-
});
|
|
394
|
+
describeTypeRules();
|
|
395
|
+
describeQuota();
|
|
396
|
+
describeContentChecks();
|
|
397
|
+
describeStaging();
|
|
398
|
+
describeStoredMetadata();
|
|
370
399
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"@antelopejs/mongodb": "1.
|
|
3
|
-
"@antelopejs/auth-jwt": "1.1.
|
|
4
|
-
"@antelopejs/api": "1.7.
|
|
5
|
-
"@antelopejs/file-storage-local": "0.2.
|
|
6
|
-
"@antelopejs/nodemailer": "0.0.
|
|
2
|
+
"@antelopejs/mongodb": "1.8.1",
|
|
3
|
+
"@antelopejs/auth-jwt": "1.1.2",
|
|
4
|
+
"@antelopejs/api": "1.7.4",
|
|
5
|
+
"@antelopejs/file-storage-local": "0.2.1",
|
|
6
|
+
"@antelopejs/nodemailer": "0.0.12"
|
|
7
7
|
}
|
|
@@ -38,6 +38,29 @@ describe("[unit] acl/entries — parseFolderAcl", () => {
|
|
|
38
38
|
it("fails closed on JSON that is not an array", () => {
|
|
39
39
|
expect(parseFolderAcl(folderWithAcl('{"subject":"x"}'))).to.deep.equal([]);
|
|
40
40
|
});
|
|
41
|
+
|
|
42
|
+
it("fails closed on an array holding something other than ACL entries", () => {
|
|
43
|
+
for (const stored of [
|
|
44
|
+
[{ subject: { kind: "group", id: "editors" }, rights: ["read"] }],
|
|
45
|
+
[{ subject: { kind: "role", id: 7 }, rights: ["read"] }],
|
|
46
|
+
[{ subject: { kind: "role", id: "editors" }, rights: ["own"] }],
|
|
47
|
+
["editors"],
|
|
48
|
+
]) {
|
|
49
|
+
expect(
|
|
50
|
+
parseFolderAcl(folderWithAcl(JSON.stringify(stored))),
|
|
51
|
+
).to.deep.equal([]);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("reads back an entry with no rights as the module writes it", () => {
|
|
56
|
+
const entry: AclEntry = {
|
|
57
|
+
subject: { kind: "permission", id: "p" },
|
|
58
|
+
rights: [],
|
|
59
|
+
};
|
|
60
|
+
expect(parseFolderAcl(folderWithAcl(serializeAcl([entry])))).to.deep.equal([
|
|
61
|
+
entry,
|
|
62
|
+
]);
|
|
63
|
+
});
|
|
41
64
|
});
|
|
42
65
|
|
|
43
66
|
describe("[unit] acl/entries — serializeAcl", () => {
|