2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { beforeAll, beforeEach, describe, expect, it } from "vitest";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import supertest from "supertest";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import { initializeTranslations } from "../services/i18n.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import type { Application, Request, Response, NextFunction } from "express";
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-10 07:15:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import { safeExtractMessageAndStackFromError } from "../services/utils.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-28 16:41:41 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import buildApp from "../app.js";
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								let app: Application;
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								describe("Share API test", () => {
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let cannotSetHeadersCount = 0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    beforeAll(async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        initializeTranslations();
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-28 16:41:41 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        app = await buildApp();
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-10 07:15:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        app.use((err: unknown, req: Request, res: Response, next: NextFunction) => {
							 | 
						
					
						
							
								
									
										
										
										
											2025-04-02 23:00:22 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            const [ errMessage ] = safeExtractMessageAndStackFromError(err);
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-10 07:15:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            if (errMessage.includes("Cannot set headers after they are sent to the client")) {
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                cannotSetHeadersCount++;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            next();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    beforeEach(() => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        cannotSetHeadersCount = 0;
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    it("requests password for password-protected share", async () => {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        await supertest(app)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .get("/share/YjlPRj2E9fOV")
							 | 
						
					
						
							
								
									
										
										
										
											2025-03-15 18:18:17 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            .expect(401)
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            .expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:33:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(cannotSetHeadersCount).toBe(0);
							 | 
						
					
						
							
								
									
										
										
										
											2025-02-26 20:23:52 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								});
							 |