mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-10-12 14:11:37 +08:00

- Used Peggy.js to replace the original parsers for Loon, QX and Surge. - Added support for vmess + ws, vmess + http, snell, socks 5 parsing. - Added various test cases for parsing.
145 lines
5.0 KiB
JavaScript
145 lines
5.0 KiB
JavaScript
import { expect } from 'chai';
|
|
import * as peggy from 'peggy';
|
|
import loon from '../../src/core/proxy-utils/grammars/loon';
|
|
import testcases from './testcases';
|
|
import { describe, it } from 'mocha';
|
|
|
|
const parser = peggy.generate(loon);
|
|
|
|
describe('Loon', function() {
|
|
describe('shadowsocks', function() {
|
|
it('test shadowsocks simple', function() {
|
|
const { input, expected } = testcases.SS.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
it('test shadowsocks obfs + tls', function() {
|
|
const { input, expected } = testcases.SS.OBFS_TLS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
it('test shadowsocks obfs + http', function() {
|
|
const { input, expected } = testcases.SS.OBFS_HTTP;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
});
|
|
|
|
describe('shadowsocksr', function() {
|
|
it('test shadowsocksr simple', function() {
|
|
const { input, expected } = testcases.SSR.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
});
|
|
|
|
describe('trojan', function() {
|
|
it('test trojan simple', function() {
|
|
const { input, expected } = testcases.TROJAN.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
|
|
it('test trojan + ws', function() {
|
|
const { input, expected } = testcases.TROJAN.WS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
|
|
it('test trojan + wss', function() {
|
|
const { input, expected } = testcases.TROJAN.WSS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
});
|
|
|
|
describe('vmess', function() {
|
|
it('test vmess simple', function() {
|
|
const { input, expected } = testcases.VMESS.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vmess + aead', function() {
|
|
const { input, expected } = testcases.VMESS.AEAD;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vmess + ws', function() {
|
|
const { input, expected } = testcases.VMESS.WS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vmess + wss', function() {
|
|
const { input, expected } = testcases.VMESS.WSS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vmess + http', function() {
|
|
const { input, expected } = testcases.VMESS.HTTP;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vmess + http + tls', function() {
|
|
const { input, expected } = testcases.VMESS.HTTP_TLS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
});
|
|
|
|
describe('vless', function() {
|
|
it('test vless simple', function() {
|
|
const { input, expected } = testcases.VLESS.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon)
|
|
});
|
|
|
|
it('test vless + ws', function() {
|
|
const { input, expected } = testcases.VLESS.WS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vless + wss', function() {
|
|
const { input, expected } = testcases.VLESS.WSS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vless + http', function() {
|
|
const { input, expected } = testcases.VLESS.HTTP;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
|
|
it('test vless + http + tls', function() {
|
|
const { input, expected } = testcases.VLESS.HTTP_TLS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected.Loon);
|
|
});
|
|
});
|
|
|
|
describe('http(s)', function() {
|
|
it('test http simple', function () {
|
|
const { input, expected } = testcases.HTTP.SIMPLE;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
|
|
it('test http with authentication', function () {
|
|
const { input, expected } = testcases.HTTP.AUTH;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
|
|
it('test https', function () {
|
|
const { input, expected } = testcases.HTTP.TLS;
|
|
const proxy = parser.parse(input.Loon);
|
|
expect(proxy).eql(expected);
|
|
});
|
|
});
|
|
}); |