forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): regex engine naming and test suit (DIYgod#10014)
* feat(core): regex engine config * fix(docs): config naming * filter-engine test naming
- Loading branch information
1 parent
e4478a3
commit dc64deb
Showing
7 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const supertest = require('supertest'); | ||
jest.mock('request-promise-native'); | ||
jest.setTimeout(50000); | ||
|
||
afterAll(() => { | ||
delete process.env.FILTER_REGEX_ENGINE; | ||
}); | ||
|
||
afterEach(() => { | ||
delete process.env.FILTER_REGEX_ENGINE; | ||
jest.resetModules(); | ||
}); | ||
|
||
describe('filter-engine', () => { | ||
it(`filter RE2 engine ReDoS attack`, async () => { | ||
const server = require('../../lib/index'); | ||
const request = supertest(server); | ||
|
||
const response = await request.get('/test/1?filter=abc(%3F%3Ddef)'); | ||
expect(response.status).toBe(404); | ||
expect(response.text).toMatch(/SyntaxError/); | ||
server.close(); | ||
}); | ||
|
||
it(`filter Regexp engine backward compatibility`, async () => { | ||
process.env.FILTER_REGEX_ENGINE = 'regexp'; | ||
|
||
const server = require('../../lib/index'); | ||
const request = supertest(server); | ||
|
||
const response = await request.get('/test/1?filter=abc(%3F%3Ddef)'); | ||
expect(response.status).toBe(200); | ||
server.close(); | ||
}); | ||
|
||
it(`filter Regexp engine test config`, async () => { | ||
process.env.FILTER_REGEX_ENGINE = 'somethingelse'; | ||
|
||
const server = require('../../lib/index'); | ||
const request = supertest(server); | ||
|
||
const response = await request.get('/test/1?filter=abc(%3F%3Ddef)'); | ||
expect(response.status).toBe(404); | ||
expect(response.text).toMatch(/somethingelse/); | ||
server.close(); | ||
}); | ||
}); |