Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 15, 2025
1 parent af085f0 commit 42299f4
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/cliFilter.test.js', () => {
let app;
describe('test/app/extends/cliFilter.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-cliFilter-app',
plugin: 'security',
});
return app.ready();
});

after(() => app.close());

after(mm.restore);

describe('helper.cliFilter()', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/escapeShellArg.test.js', () => {
let app;
describe('test/app/extends/escapeShellArg.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-escapeShellArg-app',
plugin: 'security',
});
return app.ready();
});

after(() => app.close());

after(mm.restore);

describe('helper.escapeShellArg()', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/escapeShellCmd.test.js', () => {
let app;
describe('test/app/extends/escapeShellCmd.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-escapeShellCmd-app',
plugin: 'security',
});
return app.ready();
});

after(mm.restore);
after(() => app.close());

afterEach(mm.restore);

describe('helper.escapeShellCmd()', () => {
it('should convert chars in blacklists', () => {
Expand Down
23 changes: 13 additions & 10 deletions test/app/extends/helper.test.js → test/app/extends/helper.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
const { strict: assert } = require('node:assert');
const mm = require('egg-mock');
import { strict as assert } from 'node:assert';
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/helper.test.js', () => {
let app;
let app2;
let app3;
describe('test/app/extends/helper.test.ts', () => {
let app: MockApplication;
let app2: MockApplication;
let app3: MockApplication;
before(async () => {
app = mm.app({
baseDir: 'apps/helper-app',
plugin: 'security',
});
await app.ready();

app2 = mm.app({
baseDir: 'apps/helper-config-app',
plugin: 'security',
});
await app2.ready();

app3 = mm.app({
baseDir: 'apps/helper-link-app',
plugin: 'security',
});
await app3.ready();
});

after(mm.restore);
after(async () => {
await app.close();
await app2.close();
await app3.close();
});

afterEach(mm.restore);

describe('helper.escape()', () => {
it('should work', () => {
Expand Down
11 changes: 6 additions & 5 deletions test/app/extends/sjs.test.js → test/app/extends/sjs.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/sjs.test.js', () => {
let app;
describe('test/app/extends/sjs.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-sjs-app',
plugin: 'security',
});
return app.ready();
});

after(mm.restore);
after(() => app.close());

afterEach(mm.restore);

describe('helper.sjs()', () => {
it('should convert special chars on js context and not convert chart in whitelists', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/sjson.test.js', () => {
let app;
describe('test/app/extends/sjson.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-sjson-app',
plugin: 'security',
});
return app.ready();
});

after(mm.restore);
after(() => app.close());

afterEach(mm.restore);

describe('helper.sjson()', () => {
it('should not convert json string when json is safe', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const mm = require('egg-mock');
import { mm, MockApplication } from '@eggjs/mock';

describe('test/app/extends/spath.test.js', () => {
let app;
describe('test/app/extends/spath.test.ts', () => {
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/helper-spath-app',
plugin: 'security',
});
return app.ready();
});

after(() => app.close());

after(mm.restore);

describe('helper.spath()', () => {
Expand Down
15 changes: 9 additions & 6 deletions test/context.test.js → test/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
const { strict: assert } = require('node:assert');
const mm = require('egg-mock');
import { strict as assert } from 'node:assert';
import { mm, MockApplication } from '@eggjs/mock';

describe('test/context.test.js', () => {
describe('test/context.test.ts', () => {
afterEach(mm.restore);

describe('context.isSafeDomain', () => {
let app;
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/isSafeDomain-custom',
});
return app.ready();
});

after(() => app.close());

it('should return false when domains are not safe', async () => {
const res = await app.httpRequest()
.get('/unsafe')
.set('accept', 'text/html')
.expect(200);
assert(res.text === 'false');
assert.equal(res.text, 'false');
});

it('should return true when domains are safe', async () => {
const res = await app.httpRequest()
.get('/safe')
.set('accept', 'text/html')
.expect(200);
assert(res.text === 'true');
assert.equal(res.text, 'true');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
'use strict';
import { mm, MockApplication } from '@eggjs/mock';

const mm = require('egg-mock');

describe('test/csrf_cookieDomain.test.js', () => {
describe('test/csrf_cookieDomain.test.ts', () => {
afterEach(mm.restore);

describe('cookieDomain = function', () => {
let app;
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/ctoken',
Expand All @@ -26,7 +24,7 @@ describe('test/csrf_cookieDomain.test.js', () => {
});

describe('cookieDomain = string', () => {
let app;
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/csrf-string-cookiedomain',
Expand All @@ -46,7 +44,7 @@ describe('test/csrf_cookieDomain.test.js', () => {
});

describe('cookieOptions = object', () => {
let app;
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/csrf-cookieOptions',
Expand All @@ -66,7 +64,7 @@ describe('test/csrf_cookieDomain.test.js', () => {
});

describe('cookieOptions use signed', () => {
let app;
let app: MockApplication;
before(() => {
app = mm.app({
baseDir: 'apps/csrf-cookieOptions-signed',
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/apps/csrf-cookieOptions/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

module.exports = app => {
return class Home extends app.Controller {
* index() {
async index() {
this.ctx.body = 'hello csrfToken cookieOptions';
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

module.exports = app => {
return class Home extends app.Controller {
* index() {
async index() {
this.ctx.body = 'hello csrfToken';
}
};
Expand Down
4 changes: 1 addition & 3 deletions test/fixtures/apps/ctoken/app/controller/home.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

module.exports = app => {
return class Home extends app.Controller {
* index() {
async index() {
this.ctx.body = 'hello ctoken';
}
};
Expand Down

0 comments on commit 42299f4

Please sign in to comment.