* Memory usage test for authentication
()
| 425 | * Memory usage test for authentication |
| 426 | */ |
| 427 | function testAuthMemoryUsage () { |
| 428 | console.log("\n📊 Authentication Memory Usage"); |
| 429 | console.log("-".repeat(40)); |
| 430 | |
| 431 | const iterations = 10000; |
| 432 | |
| 433 | // Test basic auth memory usage |
| 434 | const basicAuthStart = process.memoryUsage(); |
| 435 | for (let i = 0; i < iterations; i++) { |
| 436 | const req = createMockRequest({ |
| 437 | headers: { |
| 438 | authorization: "Basic " + Buffer.from(`user${i}:password${i}`).toString("base64") |
| 439 | } |
| 440 | }); |
| 441 | // Simulate auth check |
| 442 | const auth = req.headers.authorization.slice(6); |
| 443 | Buffer.from(auth, "base64").toString(); |
| 444 | } |
| 445 | const basicAuthEnd = process.memoryUsage(); |
| 446 | |
| 447 | // Test bearer token memory usage |
| 448 | const bearerAuthStart = process.memoryUsage(); |
| 449 | for (let i = 0; i < iterations; i++) { |
| 450 | const req = createMockRequest({ |
| 451 | headers: { authorization: `Bearer token-${i}` } |
| 452 | }); |
| 453 | // Simulate token check |
| 454 | req.headers.authorization.slice(7); |
| 455 | } |
| 456 | const bearerAuthEnd = process.memoryUsage(); |
| 457 | |
| 458 | console.log(`Basic Auth (${iterations} iterations):`); |
| 459 | const basicDiff = basicAuthEnd.heapUsed - basicAuthStart.heapUsed; |
| 460 | console.log(` Heap Used: ${basicDiff >= 0 ? "+" : ""}${formatFilesize(basicDiff)}`); |
| 461 | |
| 462 | console.log(`Bearer Auth (${iterations} iterations):`); |
| 463 | const bearerDiff = bearerAuthEnd.heapUsed - bearerAuthStart.heapUsed; |
| 464 | console.log(` Heap Used: ${bearerDiff >= 0 ? "+" : ""}${formatFilesize(bearerDiff)}`); |
| 465 | console.log(" Note: Negative values indicate garbage collection occurred during test"); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Main execution function |
no test coverage detected