Skip to content

Commit

Permalink
feat: 在模板中输出 proxyTestUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 20, 2019
1 parent 345790e commit b95cd8b
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 147 deletions.
1 change: 1 addition & 0 deletions lib/command/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class GenerateCommand extends Command {
return '生成规则';
}

// istanbul ignore next
public errorHandler(err): void {
errorHandler.call(this, err);
}
Expand Down
1 change: 1 addition & 0 deletions lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export async function generate(
await Bluebird.map(providerList, providerMapper, { concurrency: NETWORK_CONCURRENCY });

const renderContext = {
proxyTestUrl: config.proxyTestUrl,
downloadUrl: getDownloadUrl(config.urlBase, artifactName, true, gatewayHasToken ? gatewayConfig.accessToken : undefined),
nodes: nodeList,
names: nodeNameList,
Expand Down
13 changes: 9 additions & 4 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ const cli = path.join(__dirname, '../bin/surgio.js');
const fixture = path.join(__dirname, './fixture');
const resolve = p => path.join(fixture, p);

test('cli works', async t => {
const { code } = await coffee.fork(cli, ['generate'], {
test.only('cli works', async t => {
await coffee.fork(cli, ['generate', '-h'], {
cwd: resolve('plain'),
execArgv: ['--require', require.resolve('./stub-axios.js')],
})
.expect('code', 0)
.end();

t.is(code, 0);
await coffee.fork(cli, ['generate'], {
cwd: resolve('plain'),
execArgv: ['--require', require.resolve('./stub-axios.js')],
})
.expect('code', 0)
.end();

const confString1 = fs.readFileSync(resolve('plain/dist/ss_json.conf'), {
encoding: 'utf8',
Expand Down
4 changes: 4 additions & 0 deletions test/fixture/plain/template/template-functions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
{{ getMellowNodes(nodeList) }}
----
{{ clashProxyConfig | yaml }}
----
{{ proxyTestUrl }}
----
{{ downloadUrl }}
290 changes: 147 additions & 143 deletions test/snapshots/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,149 +4,6 @@ The actual snapshot is saved in `cli.test.ts.snap`.

Generated by [AVA](https://ava.li).

## custom filter

> Snapshot 1
`🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
----␊
🇺🇸US 1, 🇺🇸US 2␊
----␊
🇺🇸US 1, 🇺🇸US 2␊
----␊
----␊
🇺🇸US 1␊
----␊
Proxy:␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
Proxy Group:␊
- type: select␊
name: global filter␊
proxies:␊
- 🇺🇸US 1␊
- type: select␊
name: provider filter␊
proxies:␊
- 🇺🇸US 1␊
- 🇺🇸US 2␊
- type: select␊
name: sort filter␊
proxies:␊
- 🇺🇸US 2␊
- 🇺🇸US 1␊
----␊
🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
----␊
🇺🇸US 2, 🇺🇸US 1␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
`

> Snapshot 2
`🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
🇭🇰 V01 HK 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
🇭🇰 V01 HK 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
🇺🇲 V03 US = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
----␊
Proxy:␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇭🇰 V01 HK 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇭🇰 V01 HK 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇲 V03 US␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
Proxy Group:␊
- type: select␊
name: all␊
proxies:␊
- 🇺🇸US 2␊
- 🇺🇸US 1␊
- 🇭🇰 V01 HK 1␊
- 🇭🇰 V01 HK 2␊
- 🇺🇲 V03 US␊
----␊
🇭🇰 V01 HK 1, 🇭🇰 V01 HK 2, 🇺🇸US 2, 🇺🇸US 1, 🇺🇲 V03 US␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇭🇰 V01 HK 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇭🇰 V01 HK 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇺🇲 V03 US␊
`

## cli works

> Snapshot 1
Expand Down Expand Up @@ -365,4 +222,151 @@ Generated by [AVA](https://ava.li).
- ss4␊
- 测试中文␊
----␊
http://www.google.com/generate_204␊
----␊
https://example.com/template-functions.conf?access_token=abcd␊
`

## custom filter

> Snapshot 1
`🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
----␊
🇺🇸US 1, 🇺🇸US 2␊
----␊
🇺🇸US 1, 🇺🇸US 2␊
----␊
----␊
🇺🇸US 1␊
----␊
Proxy:␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
Proxy Group:␊
- type: select␊
name: global filter␊
proxies:␊
- 🇺🇸US 1␊
- type: select␊
name: provider filter␊
proxies:␊
- 🇺🇸US 1␊
- 🇺🇸US 2␊
- type: select␊
name: sort filter␊
proxies:␊
- 🇺🇸US 2␊
- 🇺🇸US 1␊
----␊
🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
----␊
🇺🇸US 2, 🇺🇸US 1␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
`

> Snapshot 2
`🇺🇸US 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module␊
🇺🇸US 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, obfs=tls, obfs-host=gateway-carry.icloud.com␊
🇭🇰 V01 HK 1 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
🇭🇰 V01 HK 2 = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
🇺🇲 V03 US = custom, us.example.com, 443, chacha20-ietf-poly1305, password, https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true␊
----␊
Proxy:␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇸US 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: false␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇭🇰 V01 HK 1␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇭🇰 V01 HK 2␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
- type: ss␊
cipher: chacha20-ietf-poly1305␊
name: 🇺🇲 V03 US␊
password: password␊
port: "443"␊
server: us.example.com␊
udp: true␊
plugin: obfs␊
plugin-opts:␊
mode: tls␊
host: gateway-carry.icloud.com␊
Proxy Group:␊
- type: select␊
name: all␊
proxies:␊
- 🇺🇸US 2␊
- 🇺🇸US 1␊
- 🇭🇰 V01 HK 1␊
- 🇭🇰 V01 HK 2␊
- 🇺🇲 V03 US␊
----␊
🇭🇰 V01 HK 1, 🇭🇰 V01 HK 2, 🇺🇸US 2, 🇺🇸US 1, 🇺🇲 V03 US␊
----␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇭🇰 V01 HK 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇭🇰 V01 HK 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, tag=🇺🇸US 2␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, tag=🇺🇸US 1␊
shadowsocks=us.example.com:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com, udp-relay=true, fast-open=true, tag=🇺🇲 V03 US␊
`
Binary file modified test/snapshots/cli.test.ts.snap
Binary file not shown.

0 comments on commit b95cd8b

Please sign in to comment.