mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-02-10 18:05:07 +08:00
[test] directUrl
This commit is contained in:
@ -141,12 +141,13 @@ async function deletePath(ctx, strPath, opt_specialDir) {
|
||||
let storageCfg = getStorageCfg(ctx, opt_specialDir);
|
||||
return await storage.deletePath(storageCfg, getStoragePath(ctx, strPath, opt_specialDir));
|
||||
}
|
||||
async function getSignedUrl(ctx, baseUrl, strPath, urlType, optFilename, opt_creationDate, opt_specialDir) {
|
||||
async function getSignedUrl(ctx, baseUrl, strPath, urlType, optFilename, opt_creationDate, opt_specialDir, useDirectStorageUrls) {
|
||||
let storage = getStorage(opt_specialDir);
|
||||
let storageCfg = getStorageCfg(ctx, opt_specialDir);
|
||||
let storagePath = getStoragePath(ctx, strPath, opt_specialDir);
|
||||
const directUrlsEnabled = useDirectStorageUrls !== undefined ? useDirectStorageUrls : storageCfg.useDirectStorageUrls;
|
||||
|
||||
if (storageCfg.useDirectStorageUrls && storage.getDirectSignedUrl) {
|
||||
if (directUrlsEnabled && storage.getDirectSignedUrl) {
|
||||
return await storage.getDirectSignedUrl(ctx, storageCfg, baseUrl, storagePath, urlType, optFilename, opt_creationDate);
|
||||
} else {
|
||||
const storageSecretString = storageCfg.fs.secretString;
|
||||
|
||||
@ -35,6 +35,14 @@ jest.mock("fs/promises", () => ({
|
||||
...jest.requireActual('fs/promises'),
|
||||
cp: jest.fn().mockImplementation((from, to) => fs.writeFileSync(to, testFileData3))
|
||||
}));
|
||||
const mockNeedServeStatic = jest.fn().mockReturnValue(true);
|
||||
jest.mock('../../../Common/sources/storage/storage-base', () => {
|
||||
const originalModule = jest.requireActual('../../../Common/sources/storage/storage-base');
|
||||
return {
|
||||
...originalModule,
|
||||
needServeStatic: mockNeedServeStatic
|
||||
};
|
||||
});
|
||||
const { cp } = require('fs/promises');
|
||||
const http = require('http');
|
||||
const https = require('https');
|
||||
@ -371,3 +379,35 @@ describe('storage mix common and forgotten dir', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('storage direct URL testing', function () {
|
||||
test("getSignedUrl with direct URLs enabled", async () => {
|
||||
let buffer = Buffer.from(testFileData1);
|
||||
let res = await storage.putObject(ctx, testFile1, buffer, buffer.length, specialDirCache);
|
||||
expect(res).toEqual(undefined);
|
||||
|
||||
let url = await storage.getSignedUrl(ctx, baseUrl, testFile1, urlType, undefined, undefined, specialDirCache, true);
|
||||
let data = await request(url);
|
||||
expect(data).toEqual(testFileData1);
|
||||
|
||||
if (cfgCacheStorage.name !== 'storage-fs') {
|
||||
expect(url).toContain(cfgCacheStorage.endpoint);
|
||||
expect(url).toContain(cfgCacheStorage.bucketName);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("getSignedUrl with direct URLs disabled", async () => {
|
||||
let buffer = Buffer.from(testFileData1);
|
||||
let res = await storage.putObject(ctx, testFile1, buffer, buffer.length, specialDirCache);
|
||||
expect(res).toEqual(undefined);
|
||||
|
||||
let url = await storage.getSignedUrl(ctx, baseUrl, testFile1, urlType, undefined, undefined, specialDirCache, false);
|
||||
console.log("URL", url);
|
||||
let data = await request(url);
|
||||
expect(data).toEqual(testFileData1);
|
||||
|
||||
expect(url).toContain('md5');
|
||||
expect(url).toContain('expires');
|
||||
expect(url).toContain(cfgCacheStorage.storageFolderName);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user