@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.
Files changed (164) hide show
  1. package/README.md +10 -10
  2. package/dist/acl/entries.js +20 -2
  3. package/dist/acl/entries.js.map +1 -1
  4. package/dist/asset-lifecycle.js +5 -1
  5. package/dist/asset-lifecycle.js.map +1 -1
  6. package/dist/bindings.d.ts +1 -0
  7. package/dist/bindings.js +36 -25
  8. package/dist/bindings.js.map +1 -1
  9. package/dist/db/models/mediaAssets.model.d.ts +3 -3
  10. package/dist/db/models/mediaDeclarations.model.d.ts +3 -3
  11. package/dist/db/models/mediaEvents.model.d.ts +3 -3
  12. package/dist/db/models/mediaFavorites.model.d.ts +3 -3
  13. package/dist/db/models/mediaFolders.model.d.ts +3 -3
  14. package/dist/db/models/mediaUploads.model.d.ts +3 -3
  15. package/dist/declared/assets.js +39 -25
  16. package/dist/declared/assets.js.map +1 -1
  17. package/dist/declared/folders.js +27 -14
  18. package/dist/declared/folders.js.map +1 -1
  19. package/dist/declared/records.d.ts +1 -0
  20. package/dist/declared/records.js +18 -1
  21. package/dist/declared/records.js.map +1 -1
  22. package/dist/fixed-id.d.ts +1 -0
  23. package/dist/fixed-id.js +16 -0
  24. package/dist/fixed-id.js.map +1 -0
  25. package/dist/library/folder-stats.d.ts +1 -1
  26. package/dist/library/folder-stats.js.map +1 -1
  27. package/dist/library/listing.d.ts +2 -0
  28. package/dist/library/listing.js +14 -4
  29. package/dist/library/listing.js.map +1 -1
  30. package/dist/routes/media/assets.d.ts +3 -2
  31. package/dist/routes/media/assets.js +15 -10
  32. package/dist/routes/media/assets.js.map +1 -1
  33. package/dist/routes/media/bulk.js +4 -4
  34. package/dist/routes/media/bulk.js.map +1 -1
  35. package/dist/routes/media/folders.js +4 -4
  36. package/dist/routes/media/folders.js.map +1 -1
  37. package/dist/routes/media/library.js +6 -12
  38. package/dist/routes/media/library.js.map +1 -1
  39. package/dist/routes/media/storage-keys.js +10 -1
  40. package/dist/routes/media/storage-keys.js.map +1 -1
  41. package/dist/test/helpers/assets.d.ts +2 -2
  42. package/dist/test/helpers/folders.d.ts +6 -6
  43. package/dist/test/helpers/permissions-world.d.ts +6 -6
  44. package/dist/test/integration/binding-folder-race.test.d.ts +1 -0
  45. package/dist/test/integration/binding-folder-race.test.js +66 -0
  46. package/dist/test/integration/binding-folder-race.test.js.map +1 -0
  47. package/dist/test/integration/declared-asset-race.test.d.ts +1 -0
  48. package/dist/test/integration/declared-asset-race.test.js +78 -0
  49. package/dist/test/integration/declared-asset-race.test.js.map +1 -0
  50. package/dist/test/integration/declared-folder-race.test.d.ts +1 -0
  51. package/dist/test/integration/declared-folder-race.test.js +43 -0
  52. package/dist/test/integration/declared-folder-race.test.js.map +1 -0
  53. package/dist/test/integration/media-activity-overview.test.js +27 -22
  54. package/dist/test/integration/media-activity-overview.test.js.map +1 -1
  55. package/dist/test/integration/media-api.test.js +9 -5
  56. package/dist/test/integration/media-api.test.js.map +1 -1
  57. package/dist/test/integration/media-bindings.test.js +16 -13
  58. package/dist/test/integration/media-bindings.test.js.map +1 -1
  59. package/dist/test/integration/media-cleanup.test.js +14 -5
  60. package/dist/test/integration/media-cleanup.test.js.map +1 -1
  61. package/dist/test/integration/media-declared-content.test.js +107 -91
  62. package/dist/test/integration/media-declared-content.test.js.map +1 -1
  63. package/dist/test/integration/media-delivery-editing.test.js +238 -215
  64. package/dist/test/integration/media-delivery-editing.test.js.map +1 -1
  65. package/dist/test/integration/media-explorer-writes.test.js +131 -112
  66. package/dist/test/integration/media-explorer-writes.test.js.map +1 -1
  67. package/dist/test/integration/media-guards.test.js +38 -37
  68. package/dist/test/integration/media-guards.test.js.map +1 -1
  69. package/dist/test/integration/media-library.test.js +244 -224
  70. package/dist/test/integration/media-library.test.js.map +1 -1
  71. package/dist/test/integration/media-linked-subfolders.test.js +173 -158
  72. package/dist/test/integration/media-linked-subfolders.test.js.map +1 -1
  73. package/dist/test/integration/media-permissions.test.js +31 -11
  74. package/dist/test/integration/media-permissions.test.js.map +1 -1
  75. package/dist/test/integration/media-search-query.test.js +8 -6
  76. package/dist/test/integration/media-search-query.test.js.map +1 -1
  77. package/dist/test/integration/media-search-views.test.js +12 -8
  78. package/dist/test/integration/media-search-views.test.js.map +1 -1
  79. package/dist/test/integration/media-upload-policy.test.js +228 -200
  80. package/dist/test/integration/media-upload-policy.test.js.map +1 -1
  81. package/dist/test/stack-modules.json +5 -5
  82. package/dist/test/unit/acl/entries.test.js +19 -0
  83. package/dist/test/unit/acl/entries.test.js.map +1 -1
  84. package/dist/test/unit/acl/resolver.test.js +9 -1
  85. package/dist/test/unit/acl/resolver.test.js.map +1 -1
  86. package/dist/test/unit/asset-lifecycle.test.d.ts +1 -0
  87. package/dist/test/unit/asset-lifecycle.test.js +18 -0
  88. package/dist/test/unit/asset-lifecycle.test.js.map +1 -0
  89. package/dist/test/unit/library/zip-names.test.js +6 -3
  90. package/dist/test/unit/library/zip-names.test.js.map +1 -1
  91. package/dist/test/unit/routes/storage-keys.test.d.ts +1 -0
  92. package/dist/test/unit/routes/storage-keys.test.js +18 -0
  93. package/dist/test/unit/routes/storage-keys.test.js.map +1 -0
  94. package/dist/test/unit/transform-ops.test.js +19 -0
  95. package/dist/test/unit/transform-ops.test.js.map +1 -1
  96. package/dist/transform-ops.js +25 -1
  97. package/dist/transform-ops.js.map +1 -1
  98. package/dist/validation/declared.schema.d.ts +6 -6
  99. package/dist/validation/library.schema.d.ts +4 -4
  100. package/dist/validation/media.schema.d.ts +5 -5
  101. package/dist/validation/media.schema.js +10 -6
  102. package/dist/validation/media.schema.js.map +1 -1
  103. package/frontend-vue/app/components/Explorer.vue +2 -0
  104. package/frontend-vue/app/components/FileProperties.vue +1 -1
  105. package/frontend-vue/app/components/ImageEditor.vue +5 -5
  106. package/frontend-vue/app/components/RecentFiles.vue +2 -2
  107. package/frontend-vue/app/components/UploadQueue.vue +4 -4
  108. package/frontend-vue/app/components/dialogs/DeleteFilesDialog.vue +1 -1
  109. package/frontend-vue/app/components/dialogs/ShortcutsDialog.vue +1 -1
  110. package/frontend-vue/app/components/dialogs/VisibilityDialog.vue +1 -1
  111. package/frontend-vue/app/components/explorer/ExplorerInspector.vue +1 -1
  112. package/frontend-vue/app/components/explorer/ExplorerSidebar.vue +2 -2
  113. package/frontend-vue/app/components/explorer/FolderStrip.vue +1 -1
  114. package/frontend-vue/app/components/explorer/GridView.vue +1 -1
  115. package/frontend-vue/app/components/shared/AltTextField.vue +2 -2
  116. package/frontend-vue/build/backend-boundary.ts +8 -3
  117. package/frontend-vue/eslint.config.mjs +0 -1
  118. package/frontend-vue/package.json +2 -2
  119. package/frontend-vue/pnpm-lock.yaml +45 -14
  120. package/frontend-vue/tests/backend-boundary.test.ts +6 -4
  121. package/frontend-vue/tests/fixtures/serverRender.ts +3 -3
  122. package/frontend-vue/tests/registration.test.ts +5 -0
  123. package/frontend-vue/tsconfig.json +1 -2
  124. package/package.json +17 -17
  125. package/src/acl/entries.ts +30 -7
  126. package/src/asset-lifecycle.ts +6 -2
  127. package/src/bindings.ts +41 -38
  128. package/src/declared/assets.ts +45 -28
  129. package/src/declared/folders.ts +30 -20
  130. package/src/declared/records.ts +31 -2
  131. package/src/fixed-id.ts +18 -0
  132. package/src/library/folder-stats.ts +1 -1
  133. package/src/library/listing.ts +24 -4
  134. package/src/routes/media/assets.ts +23 -11
  135. package/src/routes/media/bulk.ts +7 -5
  136. package/src/routes/media/folders.ts +9 -5
  137. package/src/routes/media/library.ts +10 -18
  138. package/src/routes/media/storage-keys.ts +14 -2
  139. package/src/test/integration/binding-folder-race.test.ts +82 -0
  140. package/src/test/integration/declared-asset-race.test.ts +115 -0
  141. package/src/test/integration/declared-folder-race.test.ts +50 -0
  142. package/src/test/integration/media-activity-overview.test.ts +40 -27
  143. package/src/test/integration/media-api.test.ts +9 -5
  144. package/src/test/integration/media-bindings.test.ts +17 -13
  145. package/src/test/integration/media-cleanup.test.ts +17 -5
  146. package/src/test/integration/media-declared-content.test.ts +129 -112
  147. package/src/test/integration/media-delivery-editing.test.ts +323 -299
  148. package/src/test/integration/media-explorer-writes.test.ts +161 -135
  149. package/src/test/integration/media-guards.test.ts +40 -38
  150. package/src/test/integration/media-library.test.ts +325 -296
  151. package/src/test/integration/media-linked-subfolders.test.ts +207 -186
  152. package/src/test/integration/media-permissions.test.ts +33 -14
  153. package/src/test/integration/media-search-query.test.ts +24 -8
  154. package/src/test/integration/media-search-views.test.ts +39 -32
  155. package/src/test/integration/media-upload-policy.test.ts +283 -254
  156. package/src/test/stack-modules.json +5 -5
  157. package/src/test/unit/acl/entries.test.ts +23 -0
  158. package/src/test/unit/acl/resolver.test.ts +9 -1
  159. package/src/test/unit/asset-lifecycle.test.ts +21 -0
  160. package/src/test/unit/library/zip-names.test.ts +9 -7
  161. package/src/test/unit/routes/storage-keys.test.ts +23 -0
  162. package/src/test/unit/transform-ops.test.ts +29 -1
  163. package/src/transform-ops.ts +32 -2
  164. 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
- describe("[integration] media upload policy — types, quota, real content and staging", () => {
77
- let client: AxiosInstance;
78
- let folderId: string;
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
- async function stage(
96
- filename: string,
97
- mimetype: string,
98
- body: Buffer,
99
- ): Promise<StagedUpload> {
100
- const presigned = await presign(
101
- folderId,
102
- filename,
103
- mimetype,
104
- body.byteLength,
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
- afterEach(() => {
137
- configureMediaModule(initialConfig);
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
- it("refuses HTML whatever its declared type, and types outside the allow-list", async () => {
141
- const attempts = [
142
- await presign(folderId, "page.html", "text/html"),
143
- await presign(folderId, "page.html", "text/plain"),
144
- await presign(folderId, "page.xhtml", "application/xhtml+xml"),
145
- await presign(folderId, "setup.exe", "application/x-msdownload"),
146
- ];
147
- for (const response of attempts) {
148
- expect(response.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
149
- expect(response.data.reason).to.equal("type_not_allowed");
150
- }
151
- expect(
152
- (await presign(folderId, "notes.txt", "text/plain")).status,
153
- ).to.equal(HTTP_OK);
154
- expect(
155
- (await presign(folderId, "logo.svg", "image/svg+xml")).status,
156
- ).to.equal(HTTP_OK);
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
- it("follows a configured allow-list but never re-enables HTML", async () => {
160
- configureMediaModule({
161
- ...initialConfig,
162
- allowedMimetypes: ["application/zip", "text/html"],
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
- try {
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(folderId, "a.zip", "application/zip")).status,
163
+ (await presign(linked!.id, "sheet.pdf", "application/pdf")).status,
167
164
  ).to.equal(HTTP_OK);
168
- expect((await presign(folderId, "a.png", "image/png")).status).to.equal(
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
- it("refuses a file the linked field does not accept", async () => {
180
- const linked = (await fetchFolderNodes(client)).find(
181
- (folder) => folder.binding === PDF_BINDING_ID,
182
- );
183
- expect(linked, "linked folder").to.not.equal(undefined);
184
- const image = await presign(linked!.id, "photo.png", "image/png");
185
- expect(image.status).to.equal(HTTP_UNSUPPORTED_MEDIA_TYPE);
186
- expect(image.data.reason).to.equal("field_type");
187
- expect(image.data.accepted).to.deep.equal(["application/pdf"]);
188
- expect(
189
- (await presign(linked!.id, "sheet.pdf", "application/pdf")).status,
190
- ).to.equal(HTTP_OK);
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
- it("refuses an upload past the storage quota", async () => {
194
- configureMediaModule({
195
- ...initialConfig,
196
- storageQuotaBytes: 1,
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
- it("checks the quota again at confirm, on the stored size", async () => {
208
- const staged = await stage("late.txt", "text/plain", Buffer.from("late"));
209
- configureMediaModule({ ...initialConfig, storageQuotaBytes: 1 });
210
- try {
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: "late.txt",
239
+ filename: "large.jpg",
215
240
  });
216
- expect(confirm.status).to.equal(HTTP_PAYLOAD_TOO_LARGE);
217
- expect(confirm.data.reason).to.equal("quota");
218
- expect(await FileExists(staged.resourceKey)).to.equal(false);
219
- } finally {
220
- configureMediaModule(initialConfig);
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
- it("refuses a fake image at confirm, whatever the case of its type, and deletes its staged file", async () => {
225
- for (const mimetype of ["image/png", "Image/PNG"]) {
226
- const staged = await stage(
227
- "fake.png",
228
- mimetype,
229
- Buffer.from("this is not a png"),
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(confirm.status, mimetype).to.equal(HTTP_UNPROCESSABLE_ENTITY);
237
- expect(confirm.data.reason, mimetype).to.equal("invalid_image");
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
- it("confirms a text file declared with the name of an Object.prototype member", async () => {
265
- configureMediaModule({ ...initialConfig, allowedMimetypes: ["*"] });
266
- try {
267
- for (const mimetype of ["constructor", "__proto__"]) {
268
- const filename = `${mimetype.replaceAll("_", "")}.txt`;
269
- const staged = await stage(
270
- filename,
271
- mimetype,
272
- Buffer.from("plain text"),
273
- );
274
- const confirm = await client.post("/api/media/upload/confirm", {
275
- folderId,
276
- resourceKey: staged.resourceKey,
277
- filename,
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
- it("deletes the staged file when the folder disappeared before confirm", async () => {
287
- const doomed = await client.post("/api/media/folders", {
288
- name: "Doomed upload target",
289
- });
290
- const body = Buffer.from("bytes");
291
- const doomedId = readBody(doomed, createdBody).id;
292
- const presigned = readBody(
293
- await presign(doomedId, "x.txt", "text/plain", body.byteLength),
294
- presignBody,
295
- );
296
- await axios.put(presigned.uploadUrl, body, {
297
- headers: presigned.headers,
298
- transformRequest: [(data: Buffer) => data],
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
- await client.delete(`/api/media/folders/${doomedId}`);
301
- const confirm = await client.post("/api/media/upload/confirm", {
302
- folderId: doomedId,
303
- resourceKey: presigned.resourceKey,
304
- filename: "x.txt",
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
- it("deletes a staged file on abort", async () => {
311
- const staged = await stage(
312
- "cancelled.txt",
313
- "text/plain",
314
- Buffer.from("cancel me"),
315
- );
316
- const abort = await client.post("/api/media/upload/abort", {
317
- folderId,
318
- resourceKey: staged.resourceKey,
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(abort.status).to.equal(HTTP_OK);
321
- expect(await FileExists(staged.resourceKey)).to.equal(false);
379
+ expect(folder.status).to.equal(HTTP_OK);
380
+ folderId = readBody(folder, createdBody).id;
322
381
  });
323
382
 
324
- it("purges staged uploads abandoned for more than a day", async () => {
325
- const staged = await stage(
326
- "abandoned.txt",
327
- "text/plain",
328
- Buffer.from("left behind"),
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
- it("suggests free names for duplicates, ignoring case", async () => {
340
- await uploadPixelPng(client, folderId);
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
- it("stores the displayed size of an EXIF-rotated photo", async () => {
354
- const body = await sharp({
355
- create: { width: 20, height: 10, channels: 3, background: "blue" },
356
- })
357
- .jpeg()
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.6.2",
3
- "@antelopejs/auth-jwt": "1.1.0",
4
- "@antelopejs/api": "1.7.0",
5
- "@antelopejs/file-storage-local": "0.2.0",
6
- "@antelopejs/nodemailer": "0.0.6"
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", () => {