From ec0d3a9a0fc1e64352b09d36688bf9f89a7f8262 Mon Sep 17 00:00:00 2001 From: Roy Li Date: Wed, 19 Feb 2020 20:49:54 +0800 Subject: [PATCH] feat: allow new unknown keys to gateway --- lib/types.ts | 3 ++- lib/utils/config.ts | 4 +++- test/fixture/gateway/surgio.conf.js | 1 + test/gateway/index.test.ts | 6 +++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/types.ts b/lib/types.ts index 67e2c6cb0..d732dab37 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -51,7 +51,8 @@ export interface CommandConfig { }; readonly gateway?: { readonly accessToken?: string; - auth?: boolean; // tslint:disable-line:readonly-keyword + readonly auth?: boolean; // tslint:disable-line:readonly-keyword + readonly cookieMaxAge?: number; }, readonly proxyTestUrl?: string; readonly proxyTestInterval?: number; diff --git a/lib/utils/config.ts b/lib/utils/config.ts index 4df0f2763..cb7224704 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -113,7 +113,9 @@ export const validateConfig = (userConfig: Partial): void => { gateway: Joi.object({ accessToken: Joi.string(), auth: Joi.boolean(), - }), + cookieMaxAge: Joi.number(), + }) + .unknown(), proxyTestUrl: Joi.string().uri({ scheme: [ /https?/, diff --git a/test/fixture/gateway/surgio.conf.js b/test/fixture/gateway/surgio.conf.js index a9fb7a169..79ea2cc8a 100644 --- a/test/fixture/gateway/surgio.conf.js +++ b/test/fixture/gateway/surgio.conf.js @@ -37,6 +37,7 @@ module.exports = { }, gateway: { accessToken: 'abcd', + auth: false, }, surgeConfig: { v2ray: 'native', diff --git a/test/gateway/index.test.ts b/test/gateway/index.test.ts index 82bd32c56..1a8d97c1e 100644 --- a/test/gateway/index.test.ts +++ b/test/gateway/index.test.ts @@ -2,6 +2,7 @@ import test from 'ava'; import path from 'path'; import request from 'supertest'; import { JSDOM } from 'jsdom'; +import sinon from 'sinon'; import * as gateway from '../../lib/gateway'; @@ -190,11 +191,12 @@ test('list artifact', async t => { }); test('auth', async t => { + const sandbox = sinon.createSandbox(); const fixture = path.join(__dirname, '../fixture/gateway'); const surgioServer = gateway.createSurgioServer(fixture); const app = gateway.createKoaApp(surgioServer); - app.surgioConfig.gateway.auth = true; + sandbox.stub(app.surgioConfig.gateway, 'auth').value(true); await request(app.callback()) .get('/list-artifact') @@ -206,6 +208,8 @@ test('auth', async t => { await request(app.callback()) .get('/list-artifact?access_token=abcd') .expect(200); + + sandbox.restore(); }); test('qx-script', async t => {