Skip to content

Commit

Permalink
feat: allow new unknown keys to gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Feb 19, 2020
1 parent efbe7ef commit ec0d3a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export const validateConfig = (userConfig: Partial<CommandConfig>): void => {
gateway: Joi.object({
accessToken: Joi.string(),
auth: Joi.boolean(),
}),
cookieMaxAge: Joi.number(),
})
.unknown(),
proxyTestUrl: Joi.string().uri({
scheme: [
/https?/,
Expand Down
1 change: 1 addition & 0 deletions test/fixture/gateway/surgio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
},
gateway: {
accessToken: 'abcd',
auth: false,
},
surgeConfig: {
v2ray: 'native',
Expand Down
6 changes: 5 additions & 1 deletion test/gateway/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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')
Expand All @@ -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 => {
Expand Down

0 comments on commit ec0d3a9

Please sign in to comment.