Skip to content

Commit

Permalink
Bugfix 2022 11 01 (#2628)
Browse files Browse the repository at this point in the history
* fix: 修复【Mongo 注入获取 token】的问题

* chore: up version

* chore: 关闭 Pre-request Script 和 Pre-response Script

v1.11.0 之后 如下脚本功能关闭,如需打开,请联系管理员添加. 在 db, mail 同级配置 scriptEnable: true, 并重启服务 即可

Co-authored-by: ariesly <ariesly@arieslymac13.local>
  • Loading branch information
ariesly15 and ariesly committed Nov 1, 2022
1 parent ed6771a commit 59bade3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
10 changes: 8 additions & 2 deletions common/postmanLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,13 @@ async function crossRequest(defaultOptions, preScript, afterScript, commonContex
axios: axios
});

if (preScript) {
let scriptEnable = false;
try {
const yapi = require('../server/yapi');

This comment has been minimized.

Copy link
@GpingFeng

GpingFeng Nov 11, 2022

这个是 common 中的逻辑【客户端和服务端都会用到的】,但是这里引用的又是 server 的逻辑,在编译的时候,会报编译错误:

✖ [18:28:42] 14 errors in compiling process.
[error] in ./~/graceful-fs/graceful-fs.js
Module not found: Error: Cannot resolve module 'fs' in /Users/guangpingfeng/Documents/shopee/projects/yapi/node_modules/graceful-fs
 @ ./~/graceful-fs/graceful-fs.js 1:9-22

[error] in ./~/graceful-fs/fs.js
Module not found: Error: Cannot resolve module 'fs' in /Users/guangpingfeng/Documents/shopee/projects/yapi/node_modules/graceful-fs
 @ ./~/graceful-fs/fs.js 3:9-22

[error] in ./~/nodemailer/lib/mailer/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/guangpingfeng/Documents/shopee/projects/yapi/node_modules/nodemailer/lib/mailer
 @ ./~/nodemailer/lib/mailer/index.js 13:12-26

This comment has been minimized.

Copy link
@tangpo

tangpo Dec 6, 2022

这个错误是不是还没解决

This comment has been minimized.

Copy link
@Ed1s0nZ

Ed1s0nZ Jan 12, 2023

解决了没

This comment has been minimized.

Copy link
@icycore

icycore Feb 10, 2023

可参照此方案调整。 #2666

scriptEnable = yapi.WEBCONFIG.scriptEnable === true;
} catch (err) {}

if (preScript && scriptEnable) {
context = await sandbox(context, preScript);
defaultOptions.url = options.url = URL.format({
protocol: urlObj.protocol,
Expand Down Expand Up @@ -340,7 +346,7 @@ async function crossRequest(defaultOptions, preScript, afterScript, commonContex
});
}

if (afterScript) {
if (afterScript && scriptEnable) {
context.responseData = data.res.body;
context.responseHeader = data.res.header;
context.responseStatus = data.res.status;
Expand Down
42 changes: 17 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "yapi-vendor",
"version": "1.10.2",
"version": "1.11.0",
"description": "YAPI",
"main": "server/app.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions server/controllers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class baseController {
let token = params.token;

// 如果前缀是 /api/open,执行 parse token 逻辑
if (token && (openApiRouter.indexOf(ctx.path) > -1 || ctx.path.indexOf('/api/open/') === 0 )) {
if (token && typeof token === 'string' && (openApiRouter.indexOf(ctx.path) > -1 || ctx.path.indexOf('/api/open/') === 0 )) {

let tokens = parseToken(token)

const oldTokenUid = '999999'
Expand All @@ -83,7 +83,7 @@ class baseController {
// }
// return (this.$tokenAuth = true);
// }

let checkId = await this.getProjectIdByToken(token);
if(!checkId){
ctx.body = yapi.commons.resReturn(null, 42014, 'token 无效');
Expand All @@ -105,7 +105,7 @@ class baseController {
let userInst = yapi.getInst(userModel); //创建user实体
result = await userInst.findById(tokenUid);
}

this.$user = result;
this.$auth = true;
}
Expand Down
2 changes: 1 addition & 1 deletion server/middleware/mockServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ module.exports = async (ctx, next) => {
if (project.is_mock_open && project.project_mock_script) {
// 项目层面的mock脚本解析
let script = project.project_mock_script;
yapi.commons.handleMockScript(script, context);
await yapi.commons.handleMockScript(script, context);
}

await yapi.emitHook('mock_after', context);
Expand Down

0 comments on commit 59bade3

Please sign in to comment.