mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
[wopi] Add dummy handlers for stress test
This commit is contained in:
@ -100,7 +100,11 @@
|
||||
"modulusOld": "qnro3nUUjvZK1i7UqeOlXmCrVPiDtHlRgIPReAjt2nKL1GG3SBXO6N0aPbiM5rtK0XRPUoLmKu2rYvSJ/Kmkdp14a/3uiEl788VVn0hb/l9OuQtH3HBjmM0/LKRgJQuU3LgHI67uRVZYtSJ/n9fYdZqnLfveLsrgZpgRCoabrp+H5Uem9N+x0OJR3LpToVRZhzSkYQrxnERJmF3bhR5yF8Zn+3BoSiUpVOCAvJRAYl8cAIs3BwQcTEyXJjnt+wW5Q1VyKr+bXp/39+tnugQeTe1jjdPy6rOTftQwzjro81oZpOMazwwR1aeQuQWCrmHQZqyV3Rvo6X3xYlOQnlo1/w==",
|
||||
"exponentOld": "AQAB",
|
||||
"privateKeyOld": "MIIEowIBAAKCAQEAqnro3nUUjvZK1i7UqeOlXmCrVPiDtHlRgIPReAjt2nKL1GG3SBXO6N0aPbiM5rtK0XRPUoLmKu2rYvSJ/Kmkdp14a/3uiEl788VVn0hb/l9OuQtH3HBjmM0/LKRgJQuU3LgHI67uRVZYtSJ/n9fYdZqnLfveLsrgZpgRCoabrp+H5Uem9N+x0OJR3LpToVRZhzSkYQrxnERJmF3bhR5yF8Zn+3BoSiUpVOCAvJRAYl8cAIs3BwQcTEyXJjnt+wW5Q1VyKr+bXp/39+tnugQeTe1jjdPy6rOTftQwzjro81oZpOMazwwR1aeQuQWCrmHQZqyV3Rvo6X3xYlOQnlo1/wIDAQABAoIBAQCKtUSBs8tNYrGTQTlBHXrwpkDg+u7WSZt5sEcfnkxA39BLtlHU8gGO0E9Ihr8GAL+oWjUsEltJ9GTtN8CJ9lFdPVS8sTiCZR/YQOggmFRZTJyVzMrkXgF7Uwwiu3+KxLiTOZx9eRhfDBlTD8W9fXaegX2i2Xp2ohUhBHthEBLdaZTWFi5Sid/Y0dDzBeP6UIJorZ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||||
"enable": true,
|
||||
"sampleFilePath": ""
|
||||
}
|
||||
},
|
||||
"tenants": {
|
||||
"baseDir": "",
|
||||
|
||||
@ -60,6 +60,7 @@ const tenantManager = require('./../../Common/sources/tenantManager');
|
||||
const configStorage = config.get('storage');
|
||||
|
||||
const cfgWopiEnable = config.get('wopi.enable');
|
||||
const cfgWopiDummyEnable = config.get('wopi.dummy.enable');
|
||||
const cfgHtmlTemplate = config.get('wopi.htmlTemplate');
|
||||
const cfgTokenEnableBrowser = config.get('services.CoAuthoring.token.enable.browser');
|
||||
const cfgTokenEnableRequestInbox = config.get('services.CoAuthoring.token.enable.request.inbox');
|
||||
@ -293,6 +294,24 @@ docsCoServer.install(server, () => {
|
||||
res.sendStatus(404);
|
||||
});
|
||||
}
|
||||
function checkWopiDummyEnable(req, res, next) {
|
||||
//todo may be move code into wopiClient or wopiClient.discovery...
|
||||
let ctx = new operationContext.Context();
|
||||
ctx.initFromRequest(req);
|
||||
ctx.initTenantCache()
|
||||
.then(() => {
|
||||
const tenWopiEnable = ctx.getCfg('wopi.enable', cfgWopiEnable);
|
||||
const tenWopiDummyEnable = ctx.getCfg('wopi.dummy.enable', cfgWopiDummyEnable);
|
||||
if (tenWopiEnable && tenWopiDummyEnable) {
|
||||
next();
|
||||
} else {
|
||||
res.sendStatus(404);
|
||||
}
|
||||
}).catch((err) => {
|
||||
ctx.logger.error('checkWopiDummyEnable error: %s', err.stack);
|
||||
res.sendStatus(404);
|
||||
});
|
||||
}
|
||||
//todo dest
|
||||
let fileForms = multer({limits: {fieldSize: cfgDownloadMaxBytes}});
|
||||
app.get('/hosting/discovery', checkWopiEnable, utils.checkClientIp, wopiClient.discovery);
|
||||
@ -302,8 +321,12 @@ docsCoServer.install(server, () => {
|
||||
app.post('/hosting/wopi/:documentType/:mode', checkWopiEnable, urleEcodedParser, forms.none(), utils.lowercaseQueryString, wopiClient.getEditorHtml);
|
||||
app.post('/hosting/wopi/convert-and-edit/:ext/:targetext', checkWopiEnable, urleEcodedParser, forms.none(), utils.lowercaseQueryString, wopiClient.getConverterHtml);
|
||||
app.get('/hosting/wopi/convert-and-edit-handler', checkWopiEnable, utils.lowercaseQueryString, converterService.getConverterHtmlHandler);
|
||||
app.get('/wopi/files/:docid', apicache.middleware("5 minutes"), checkWopiDummyEnable, utils.lowercaseQueryString, wopiClient.dummyCheckFileInfo);
|
||||
app.post('/wopi/files/:docid', checkWopiDummyEnable, wopiClient.dummyOk);
|
||||
app.get('/wopi/files/:docid/contents', apicache.middleware("5 minutes"), checkWopiDummyEnable, wopiClient.dummyGetFile);
|
||||
app.post('/wopi/files/:docid/contents', checkWopiDummyEnable, wopiClient.dummyOk);
|
||||
|
||||
app.post('/dummyCallback', utils.checkClientIp, rawFileParser, function(req, res){
|
||||
app.post('/dummyCallback', utils.checkClientIp, apicache.middleware("5 minutes"), rawFileParser, function(req, res){
|
||||
let ctx = new operationContext.Context();
|
||||
ctx.initFromRequest(req);
|
||||
//yield ctx.initTenantCache();//no need
|
||||
|
||||
@ -33,6 +33,9 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const {stat} = require('node:fs/promises');
|
||||
const { pipeline } = require('node:stream/promises');
|
||||
const crypto = require('crypto');
|
||||
const {URL} = require('url');
|
||||
const co = require('co');
|
||||
@ -51,6 +54,7 @@ const sqlBase = require('./baseConnector');
|
||||
const taskResult = require('./taskresult');
|
||||
const canvasService = require('./canvasservice');
|
||||
const converterService = require('./converterservice');
|
||||
const mime = require('mime');
|
||||
|
||||
const cfgTokenOutboxAlgorithm = config.get('services.CoAuthoring.token.outbox.algorithm');
|
||||
const cfgTokenOutboxExpires = config.get('services.CoAuthoring.token.outbox.expires');
|
||||
@ -79,6 +83,7 @@ const cfgWopiModulusOld = config.get('wopi.modulusOld');
|
||||
const cfgWopiExponentOld = config.get('wopi.exponentOld');
|
||||
const cfgWopiPrivateKeyOld = config.get('wopi.privateKeyOld');
|
||||
const cfgWopiHost = config.get('wopi.host');
|
||||
const cfgWopiDummySampleFilePath = config.get('wopi.dummy.sampleFilePath');
|
||||
|
||||
let mimeTypesByExt = (function() {
|
||||
let mimeTypesByExt = {};
|
||||
@ -824,7 +829,75 @@ function getWopiParams(lockId, fileInfo, wopiSrc, access_token, access_token_ttl
|
||||
hostSessionId: null, userSessionId: null, mode: null
|
||||
};
|
||||
return {commonInfo: commonInfo, userAuth: userAuth, LastModifiedTime: null};
|
||||
};
|
||||
}
|
||||
|
||||
async function dummyCheckFileInfo(req, res) {
|
||||
if (true) {
|
||||
//static output for performance reason
|
||||
res.json({
|
||||
BaseFileName: "sample.docx",
|
||||
OwnerId: "userId",
|
||||
Size: 100,//no need to set actual size for test
|
||||
UserId: "userId",//test ignores
|
||||
UserFriendlyName: "user",
|
||||
Version: 0,
|
||||
UserCanWrite: true,
|
||||
SupportsGetLock: true,
|
||||
SupportsLocks: true,
|
||||
SupportsUpdate: true,
|
||||
});
|
||||
} else {
|
||||
let fileInfo;
|
||||
let ctx = new operationContext.Context();
|
||||
ctx.initFromRequest(req);
|
||||
try {
|
||||
await ctx.initTenantCache();
|
||||
const tenWopiDummySampleFilePath = ctx.getCfg('wopi.dummy.sampleFilePath', cfgWopiDummySampleFilePath);
|
||||
let access_token = req.query['access_token'];
|
||||
ctx.logger.debug('dummyCheckFileInfo access_token:%s', access_token);
|
||||
let sampleFileStat = await stat(tenWopiDummySampleFilePath);
|
||||
|
||||
fileInfo = JSON.parse(Buffer.from(access_token, 'base64').toString('ascii'));
|
||||
fileInfo.BaseFileName = path.basename(tenWopiDummySampleFilePath);
|
||||
fileInfo.Size = sampleFileStat.size;
|
||||
} catch (err) {
|
||||
ctx.logger.error('dummyCheckFileInfo error:%s', err.stack);
|
||||
} finally {
|
||||
if (fileInfo) {
|
||||
res.json(fileInfo);
|
||||
} else {
|
||||
res.sendStatus(400)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function dummyGetFile(req, res) {
|
||||
let ctx = new operationContext.Context();
|
||||
ctx.initFromRequest(req);
|
||||
try {
|
||||
await ctx.initTenantCache();
|
||||
|
||||
const tenWopiDummySampleFilePath = ctx.getCfg('wopi.dummy.sampleFilePath', cfgWopiDummySampleFilePath);
|
||||
let sampleFileStat = await stat(tenWopiDummySampleFilePath);
|
||||
res.setHeader('Content-Length', sampleFileStat.size);
|
||||
res.setHeader('Content-Type', mime.getType(tenWopiDummySampleFilePath));
|
||||
|
||||
await pipeline(
|
||||
fs.createReadStream(tenWopiDummySampleFilePath),
|
||||
res,
|
||||
);
|
||||
} catch (err) {
|
||||
ctx.logger.error('dummyGetFile error:%s', err.stack);
|
||||
} finally {
|
||||
if (!res.headersSent) {
|
||||
res.sendStatus(400);
|
||||
}
|
||||
}
|
||||
}
|
||||
function dummyOk(req, res) {
|
||||
res.sendStatus(200);
|
||||
}
|
||||
|
||||
exports.discovery = discovery;
|
||||
exports.collaboraCapabilities = collaboraCapabilities;
|
||||
@ -841,3 +914,6 @@ exports.generateProofOld = generateProofOld;
|
||||
exports.fillStandardHeaders = fillStandardHeaders;
|
||||
exports.getWopiUnlockMarker = getWopiUnlockMarker;
|
||||
exports.getWopiModifiedMarker = getWopiModifiedMarker;
|
||||
exports.dummyCheckFileInfo = dummyCheckFileInfo;
|
||||
exports.dummyGetFile = dummyGetFile;
|
||||
exports.dummyOk = dummyOk;
|
||||
|
||||
Reference in New Issue
Block a user