f0e6d2dfb1
Harden gallery authentication and authorization, consolidate gallery workflows, and prevent token-bearing URLs from leaking through nginx request error logs.
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
// Supertest 6 binds an IPv6 wildcard listener but hardcodes an IPv4 URL.
|
|
// macOS can allocate that IPv6 port while a different IPv4 service owns it.
|
|
// Address the listener's actual family so a test cannot reach that service.
|
|
jest.mock('supertest/lib/test', () => {
|
|
const Test = jest.requireActual('supertest/lib/test');
|
|
const serverAddress = Test.prototype.serverAddress;
|
|
Test.prototype.serverAddress = function(app, path) {
|
|
const url = serverAddress.call(this, app, path);
|
|
return app.address()?.family === 'IPv6'
|
|
? url.replace('://127.0.0.1:', '://[::1]:')
|
|
: url;
|
|
};
|
|
return Test;
|
|
});
|
|
|
|
beforeAll(() => {
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.JWT_SECRET = 'test-secret';
|
|
if (!process.env.SKIP_S3_TESTS) {
|
|
process.env.SKIP_S3_TESTS = 'true';
|
|
}
|
|
if (!process.env.STORAGE_PATH) {
|
|
process.env.STORAGE_PATH = '/storage';
|
|
}
|
|
});
|
|
|
|
// Dispose resources loaded by this suite using the application's draining
|
|
// shutdown. Individual fixtures still own temporary files and other DB pools.
|
|
afterAll(async () => {
|
|
await require('./src/services/serviceShutdown').stopServices();
|
|
const loadedDb = require.cache[require.resolve('./src/database/db')];
|
|
if (typeof loadedDb?.exports.db?.destroy === 'function') await loadedDb.exports.db.destroy();
|
|
});
|