初始化提交:go比特版本精简
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {
|
||||
parseProxyString,
|
||||
generateNexipString,
|
||||
} = require('../src/services/proxy_service');
|
||||
const { _private } = require('../src/services/proxy_recovery_service');
|
||||
|
||||
(async () => {
|
||||
const atFormat = parseProxyString('us.nexip.cc:3010@customer-us-sid-123456-ttl-60:secret');
|
||||
assert.deepStrictEqual(atFormat, {
|
||||
host: 'us.nexip.cc',
|
||||
port: 3010,
|
||||
username: 'customer-us-sid-123456-ttl-60',
|
||||
password: 'secret',
|
||||
});
|
||||
|
||||
const standardFormat = parseProxyString('us.nexip.cc:3010:customer-us:secret:with:colon');
|
||||
assert.deepStrictEqual(standardFormat, {
|
||||
host: 'us.nexip.cc',
|
||||
port: 3010,
|
||||
username: 'customer-us',
|
||||
password: 'secret:with:colon',
|
||||
});
|
||||
|
||||
const generated = generateNexipString({
|
||||
template: 'us.nexip.cc:3010@customer-us-sid-{sid}-ttl-60:secret',
|
||||
sidUseLetters: false,
|
||||
sidUseNumbers: true,
|
||||
sidLength: 6,
|
||||
});
|
||||
assert.match(generated, /^us\.nexip\.cc:3010:customer-us-sid-\d{6}-ttl-60:secret$/);
|
||||
assert.strictEqual(generateNexipString({ template: 'invalid-template' }), null);
|
||||
|
||||
const settings = {
|
||||
proxy_provider: 'nexip',
|
||||
proxy_template: 'us.nexip.cc:3010@customer-us-sid-{sid}-ttl-60:secret',
|
||||
sid_use_letters: '0',
|
||||
sid_use_numbers: '1',
|
||||
sid_length: '8',
|
||||
};
|
||||
const cfg = await _private.readProxyProviderConfig(async (key, fallback) => (
|
||||
Object.prototype.hasOwnProperty.call(settings, key) ? settings[key] : fallback
|
||||
));
|
||||
assert.strictEqual(cfg.provider, 'nexip');
|
||||
assert.strictEqual(cfg.template, settings.proxy_template);
|
||||
assert.strictEqual(_private.hasProxyProviderConfig(cfg), true);
|
||||
assert.strictEqual(_private.proxyTestAttemptsForProvider('nexip'), 10);
|
||||
assert.strictEqual(_private.proxyTestAttemptsForProvider('cliproxy'), 3);
|
||||
|
||||
const html = fs.readFileSync(path.join(__dirname, '..', 'public', 'index.html'), 'utf8');
|
||||
const appSource = fs.readFileSync(path.join(__dirname, '..', 'public', 'app.js'), 'utf8');
|
||||
const workerSource = fs.readFileSync(path.join(__dirname, '..', 'src', 'workers', 'task_runner.js'), 'utf8');
|
||||
assert.match(html, /<option value="nexip">Nexip<\/option>/);
|
||||
assert.match(html, /Nexip 代理模板/);
|
||||
assert.match(html, /每个账号最多测速 10 次/);
|
||||
assert.match(html, /复用已验证 SID/);
|
||||
assert.match(html, /nexip_sid_reuse_enabled/);
|
||||
assert.match(html, /nexip_sid_reuse_count/);
|
||||
assert.match(appSource, /nexip: 'Nexip'/);
|
||||
assert.match(appSource, /'nexip_sid_reuse_enabled', 'nexip_sid_reuse_count'/);
|
||||
assert.match(workerSource, /provider === 'nexip'/);
|
||||
assert.match(workerSource, /generateNexipString/);
|
||||
assert.match(workerSource, /provider === 'nexip' \? 10 : 3/);
|
||||
assert.match(workerSource, /\$\{attempt\}\/\$\{proxyTestAttempts\}次/);
|
||||
assert.ok(
|
||||
(workerSource.match(/const nexipReusePool = createProxyReusePool/g) || []).length >= 2,
|
||||
'换代理和导入初始化都应创建单次任务 SID 复用池',
|
||||
);
|
||||
assert.ok(
|
||||
(workerSource.match(/nexipReusePool\.acquire\(\)/g) || []).length >= 2,
|
||||
'换代理和导入初始化都应优先获取已验证 SID',
|
||||
);
|
||||
assert.ok(
|
||||
(workerSource.match(/nexipReusePool\.add\(/g) || []).length >= 2,
|
||||
'换代理和导入初始化都应将合格 SID 放入复用池',
|
||||
);
|
||||
assert.match(workerSource, /复用已验证 SID(第\$\{reusableProxy\.useNumber\}\/\$\{reusableProxy\.maxUses\}个账号)/);
|
||||
|
||||
console.log('nexip_proxy.test.js: PASS');
|
||||
})().catch(error => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in New Issue
Block a user