From 4166a8cb7d3af586d779a29813f55e6d8190004c Mon Sep 17 00:00:00 2001 From: jysperm Date: Sat, 15 Nov 2014 00:24:22 +0800 Subject: [PATCH] some test of shadowsocks --- README.md | 6 +- core/pluggable.coffee | 7 ++- core/test/router/account.test.coffee | 1 - plugin/shadowsocks/shadowsocks.coffee | 12 ++-- .../shadowsocks/test/shadowsocks.test.coffee | 55 +++++++++++++++++++ plugin/supervisor/template/program.conf | 2 + sample/core.config.coffee | 3 - sample/shadowsocks.config.coffee | 5 +- 8 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 plugin/shadowsocks/test/shadowsocks.test.coffee diff --git a/README.md b/README.md index 2d4c540..040a032 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # RootPanel -RootPanel 是一个 PaaS 开发框架,提供了用户系统、计费和订单系统、工单系统,允许通过开发插件的方式来支持各种网络服务的管理和销售,默认实现了一些插件来支持例如虚拟主机,ShadowSocks, 用户也可以简单地自行编写插件来拓展 RootPanel 的功能。 +RootPanel 是一个 PaaS 开发框架,提供了用户系统、计费和订单系统、工单系统,允许通过开发插件的方式来支持各种网络服务的管理和销售,默认实现了一些插件来支持例如虚拟主机,ShadowSocks 等常见服务,用户也可以简单地自行编写插件来拓展 RootPanel 的功能。 RootPanel 具有良好的设计,高度的可定制性,支持多语言和多时区,以及非常高的单元测试覆盖率。 ## 安装 -稳定版本 [![Build Status](https://travis-ci.org/jysperm/RootPanel.svg?branch=stable)](https://travis-ci.org/jysperm/RootPanel): +稳定版本 [![Build Status](https://travis-ci.org/jysperm/RootPanel.svg?branch=stable)](https://travis-ci.org/jysperm/RootPanel) git clone -b stable https://github.com/jysperm/RootPanel.git -开发版本 [![Build Status](https://travis-ci.org/jysperm/RootPanel.svg?branch=master)](https://travis-ci.org/jysperm/RootPanel): +开发版本 [![Build Status](https://travis-ci.org/jysperm/RootPanel.svg?branch=master)](https://travis-ci.org/jysperm/RootPanel) git clone https://github.com/jysperm/RootPanel.git diff --git a/core/pluggable.coffee b/core/pluggable.coffee index 40ccce2..4993de2 100644 --- a/core/pluggable.coffee +++ b/core/pluggable.coffee @@ -177,9 +177,12 @@ exports.Plugin = class Plugin fs.readFile template_path, (err, template_file) -> callback _.template(template_file.toString()) view_data - @writeConfigFile: (filename, content, callback) -> + @writeConfigFile: (filename, content, options, callback) -> + unless callback + [options, callback] = [{}, options] + tmp.file - mode: 0o750 + mode: options.mode ? 0o750 , (err, filepath, fd) -> logger.error err if err diff --git a/core/test/router/account.test.coffee b/core/test/router/account.test.coffee index 80bb2e5..3920a2d 100644 --- a/core/test/router/account.test.coffee +++ b/core/test/router/account.test.coffee @@ -9,7 +9,6 @@ describe 'router/account', -> password = null before -> - require '../../../app' {utils} = app agent = supertest.agent app.express diff --git a/plugin/shadowsocks/shadowsocks.coffee b/plugin/shadowsocks/shadowsocks.coffee index 09a7a97..b15b7cc 100644 --- a/plugin/shadowsocks/shadowsocks.coffee +++ b/plugin/shadowsocks/shadowsocks.coffee @@ -4,6 +4,8 @@ supervisor = require '../supervisor/supervisor' +ShadowsocksPlugin = require './index' + BILLING_BUCKET = config.plugins.shadowsocks.billing_bucket exports.initSupervisor = (callback) -> @@ -11,19 +13,21 @@ exports.initSupervisor = (callback) -> async.each config.plugins.shadowsocks.available_ciphers, (method, callback) -> program_name = "shadowsocks-#{method}" - if program_name in _.keys program_status + if program_name in _.pluck program_status, 'name' return callback() shadowsocks_config_file = "/etc/shadowsocks/#{method}.json" configure = exports.generateConfigure [], method: method - fs.writeFile shadowsocks_config_file, configure, -> + ShadowsocksPlugin.writeConfigFile shadowsocks_config_file, configure, {mode: 0o755}, -> supervisor.writeConfig {username: 'nobody'}, + program_name: program_name command: "ssserver -c #{shadowsocks_config_file}" name: program_name autostart: true autorestart: true + stdout_logfile: false , -> supervisor.updateProgram {}, {program_name: program_name}, -> callback() @@ -45,7 +49,7 @@ exports.generateConfigure = (users, options = {}) -> return JSON.stringify configure -exports.generatePort = (port) -> +exports.generatePort = (callback) -> port = 10000 + Math.floor Math.random() * 10000 Account.findOne @@ -197,7 +201,7 @@ exports.updateConfigure = (account, callback) -> config = JSON.parse content config.port_password[port] = password - fs.writeFile shadowsocks_config_file, JSON.stringify(config), -> + ShadowsocksPlugin.writeConfigFile shadowsocks_config_file, JSON.stringify(config), {mode: 0o755}, -> callback() (callback) -> diff --git a/plugin/shadowsocks/test/shadowsocks.test.coffee b/plugin/shadowsocks/test/shadowsocks.test.coffee new file mode 100644 index 0000000..ab4f3be --- /dev/null +++ b/plugin/shadowsocks/test/shadowsocks.test.coffee @@ -0,0 +1,55 @@ +describe 'plugin/shadowsocks', -> + agent = null + utils = null + config = null + Account = null + + csrf_token = null + account_id = null + + before -> + {utils, config} = app + {Account} = app.models + agent = supertest.agent app.express + + config.plans.shadowsocks = + t_name: 'shadowsocks' + t_description: 'shadowsocks' + + services: ['shadowsocks'] + + describe 'router', -> + it 'POST register', (done) -> + agent.get '/account/session_info' + .end (err, res) -> + csrf_token = res.body.csrf_token + + agent.post '/account/register' + .send + csrf_token: csrf_token + username: "test#{utils.randomString(20).toLowerCase()}" + email: "#{utils.randomString 20}@gmail.com" + password: utils.randomString 20 + .end (err, res) -> + account_id = res.body.id + created_objects.accounts.push ObjectId account_id + + Account.findByIdAndUpdate account_id, + $set: + 'billing.balance': 10 + , -> + done err + + it 'POST join_plan', (done) -> + agent.post '/billing/join_plan' + .send + csrf_token: csrf_token + plan: 'shadowsocks' + .expect 200 + .end done + + it 'POST reset_password' + + it 'POST switch_method' + + it 'POST leave_plan' diff --git a/plugin/supervisor/template/program.conf b/plugin/supervisor/template/program.conf index 1ad5487..e400d1b 100644 --- a/plugin/supervisor/template/program.conf +++ b/plugin/supervisor/template/program.conf @@ -4,7 +4,9 @@ autostart = <%= program.autostart.toString() %> autorestart = <%= program.autorestart %> user = <%= account.username %> redirect_stderr = true +<% if (program.stdout_logfile !== false) { %> stdout_logfile = /home/<%= account.username %>/supervisor-<%= program.name %>.log +<% } %> <% if(program.directory) { %> directory = <%= program.directory %> <% } %> diff --git a/sample/core.config.coffee b/sample/core.config.coffee index 2f0ad16..2152695 100644 --- a/sample/core.config.coffee +++ b/sample/core.config.coffee @@ -43,9 +43,6 @@ module.exports = t_name: 'plans.test.name' t_description: 'plans.test.description' - billing_by_usage: - auto_leave: 7 * 24 * 3600 * 1000 - services: [] resources: {} diff --git a/sample/shadowsocks.config.coffee b/sample/shadowsocks.config.coffee index e10064e..503138f 100644 --- a/sample/shadowsocks.config.coffee +++ b/sample/shadowsocks.config.coffee @@ -28,13 +28,10 @@ module.exports = billing_cycle: 10 * 60 * 1000 plans: - all: + shadowsocks: t_name: 'plugins.rpvhost.plans.shadowsocks.name' t_description: 'plugins.rpvhost.plans.shadowsocks.description' - billing_by_usage: - auto_leave: 14 * 24 * 3600 * 1000 - services: ['shadowsocks'] mongodb: