From 61b1a4ead70cbdffdaf87e2d903168ea7783276e Mon Sep 17 00:00:00 2001 From: Zhenkyle Date: Thu, 13 Jul 2017 08:54:52 +0800 Subject: [PATCH 1/5] Add script to bootstrap project using scripts to rule them all pattern --- .gitignore | 1 + .ruby-version | 1 + Rakefile | 3 ++- script/bootstrap | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ script/console | 15 +++++++++++ script/setup | 21 +++++++++++++++ script/test | 23 +++++++++++++++++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 .ruby-version create mode 100755 script/bootstrap create mode 100755 script/console create mode 100755 script/setup create mode 100755 script/test diff --git a/.gitignore b/.gitignore index 0cb6eeb..4ee6b64 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /pkg/ /spec/reports/ /tmp/ +/vendor diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..005119b --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.1 diff --git a/Rakefile b/Rakefile index 2ba284a..8005b1e 100644 --- a/Rakefile +++ b/Rakefile @@ -11,4 +11,5 @@ end YARD::Rake::YardocTask.new -task :default => [:spec, :features] +task :default => [:test] +task :test => [:spec, :features] diff --git a/script/bootstrap b/script/bootstrap new file mode 100755 index 0000000..7aff9a1 --- /dev/null +++ b/script/bootstrap @@ -0,0 +1,67 @@ +#!/bin/sh + +# script/bootstrap: Resolve all dependencies that the application requires to +# run. + +set -e + +cd "$(dirname "$0")/.." + +which rvm >/dev/null 2>&1 && { + echo "Sorry, $0 can not be used with rvm." + exit 1 +} + +if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ]; then + brew bundle check >/dev/null 2>&1 || { + echo "==> Installing Homebrew dependencies…" + brew bundle + } +elif [ "$(uname -s)" = "Linux" ] && [ -f "/etc/debian_version" ]; then + + # Install rbenv if needed + which rbenv >/dev/null 2>&1 || { + echo "==> Installing Dependencie -- rbenv" + sudo apt-get update && sudo apt-get install -y autoconf bison build-essential \ + libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev + git clone https://github.com/rbenv/rbenv.git ~/.rbenv + cd ~/.rbenv && src/configure && make -C src + grep 'export PATH="$HOME/.rbenv/bin:$PATH"' ~/.bashrc > /dev/null 2>&1 || { + echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc + } + grep 'eval "$(rbenv init -)"' ~/.bashrc > /dev/null 2>&1 || { + echo 'eval "$(rbenv init -)"' >> ~/.bashrc + } + export PATH="$HOME/.rbenv/bin:$PATH" + eval "$(rbenv init -)" + git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build + } + + # Install docker if needed + which docker >/dev/null 2>&1 || { + echo "==> Installing Dependencie -- docker" + sudo apt-get update && sudo apt-get install docker.io -y + sudo usermod -aG docker $USER + newgrp docker + } + +else + echo "Sorry, only support macOS & Debain system." + exit 1 +fi + +if [ -f ".ruby-version" ] && [ -z "$(rbenv version-name 2>/dev/null)" ]; then + echo "==> Installing Ruby…" + rbenv install --skip-existing + which bundle >/dev/null 2>&1 || { + gem install bundler + rbenv rehash + } +fi + +if [ -f "Gemfile" ]; then + echo "==> Installing gem dependencies…" + bundle check --path vendor/gems >/dev/null 2>&1 || { + bundle install --path vendor/gems --quiet --without production + } +fi diff --git a/script/console b/script/console new file mode 100755 index 0000000..4d39dcc --- /dev/null +++ b/script/console @@ -0,0 +1,15 @@ +#!/bin/sh + +# script/console: Launch a console for the application. Optionally allow an +# environment to be passed in to let the script handle the +# specific requirements for connecting to a console for that +# environment. + +set -e + +cd "$(dirname "$0")/.." + +# no argument provided, so just run the local console in the development +# environment. Ensure the application is setup first. +script/setup +bin/console \ No newline at end of file diff --git a/script/setup b/script/setup new file mode 100755 index 0000000..db68bea --- /dev/null +++ b/script/setup @@ -0,0 +1,21 @@ +#!/bin/sh + +# script/setup: Set up application for the first time after cloning, or set it +# back to the initial first unused state. + +set -e + +cd "$(dirname "$0")/.." + +script/bootstrap + + +if [ -z "docker images -q zhenkyle/docker-sslocal" ]; then + docker pull zhenkyle/docker-sslocal +fi + +if [ -z "docker images -q zhenkyle/shadowsocksr" ]; then + docker pull zhenkyle/shadowsocksr +fi + +echo "==> App is now ready to go!" \ No newline at end of file diff --git a/script/test b/script/test new file mode 100755 index 0000000..7585f1a --- /dev/null +++ b/script/test @@ -0,0 +1,23 @@ +#!/bin/sh + +# script/test: Run test suite for application. Optionally pass in a path to an +# individual test file to run a single test. + + +set -e + +cd "$(dirname "$0")/.." + +[ -z "$DEBUG" ] || set -x + +script/setup + +echo "==> Running tests…" + +if [ -n "$1" ]; then + # pass arguments to test call. This is useful for calling a single test. + echo "use: bin/rspec $1" + echo " or: bin/cucumber $1" +else + bin/rake test +fi \ No newline at end of file From 20f1386d4d15ffd8f73430a8135a93993a7f091b Mon Sep 17 00:00:00 2001 From: Zhenkyle Date: Fri, 14 Jul 2017 17:52:06 +0800 Subject: [PATCH 2/5] Change http://www.example.com to local http server --- features/local_functional.feature | 17 +++++++++++------ features/server_functional.feature | 17 +++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/features/local_functional.feature b/features/local_functional.feature index 7e827dc..3040960 100644 --- a/features/local_functional.feature +++ b/features/local_functional.feature @@ -7,21 +7,26 @@ Background: Given curl is installed Given the default aruba stop signal is "INT" Given I wait 1 seconds for a command to start up + Given a file named "index.html" with: + """ +

Example Domain

+ """ + And I run `ruby -run -e httpd . -p 5000` in background Scenario: shadowsocks origin version When I run `docker run --rm --net=host --entrypoint "ssserver" zhenkyle/docker-sslocal -k secret` in background And I run `sslocal-ruby -k secret -s 127.0.0.1` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with http_simple obfuscator When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o http_simple` in background And I run `sslocal-ruby -s 127.0.0.1 -k secret -o http_simple` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with tls_ticket obfuscator When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o tls1.2_ticket_auth_compatible` in background And I run `sslocal-ruby -s 127.0.0.1 -k secret -o tls1.2_ticket_auth_compatible` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" diff --git a/features/server_functional.feature b/features/server_functional.feature index 4857745..fd6d1eb 100644 --- a/features/server_functional.feature +++ b/features/server_functional.feature @@ -7,21 +7,26 @@ Background: Given curl is installed Given the default aruba stop signal is "INT" Given I wait 1 seconds for a command to start up + Given a file named "index.html" with: + """ +

Example Domain

+ """ + And I run `ruby -run -e httpd . -p 5000` in background Scenario: shadowsocks origin version When I run `ssserver-ruby -k secret` in background And I run `docker run --rm --net=host zhenkyle/docker-sslocal -k secret -s 127.0.0.1` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with http_simple obfuscator When I run `ssserver-ruby -k secret -o http_simple` in background And I run `docker run --rm --net=host zhenkyle/shadowsocksr sslocal -s 127.0.0.1 -k secret -o http_simple` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with tls_ticket obfuscator When I run `ssserver-ruby -k secret -o tls1.2_ticket_auth_compatible` in background And I run `docker run --rm --net=host zhenkyle/shadowsocksr sslocal -s 127.0.0.1 -k secret -o tls1.2_ticket_auth_compatible` in background - And I run `curl --socks5-hostname 127.0.0.1 http://www.example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://www.example.com/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" From 8505aa0b2ce4da07e7cdaf2ba9fbed0e93c62bd5 Mon Sep 17 00:00:00 2001 From: Zhenkyle Date: Sat, 15 Jul 2017 09:58:36 +0800 Subject: [PATCH 3/5] Change back to example.com : shadowsocks_server_python doesn't support open 127.0.0.1 host --- features/local_functional.feature | 23 ++++++++++++----------- features/server_functional.feature | 6 ++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/features/local_functional.feature b/features/local_functional.feature index 3040960..ad22f5a 100644 --- a/features/local_functional.feature +++ b/features/local_functional.feature @@ -7,26 +7,27 @@ Background: Given curl is installed Given the default aruba stop signal is "INT" Given I wait 1 seconds for a command to start up - Given a file named "index.html" with: - """ -

Example Domain

- """ - And I run `ruby -run -e httpd . -p 5000` in background Scenario: shadowsocks origin version + And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host --entrypoint "ssserver" zhenkyle/docker-sslocal -k secret` in background + And I wait 1 seconds for a command to start up And I run `sslocal-ruby -k secret -s 127.0.0.1` in background - And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" Scenario: shadowsocks origin version with http_simple obfuscator + And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o http_simple` in background + And I wait 1 seconds for a command to start up And I run `sslocal-ruby -s 127.0.0.1 -k secret -o http_simple` in background - And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" Scenario: shadowsocks origin version with tls_ticket obfuscator + And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o tls1.2_ticket_auth_compatible` in background + And I wait 1 seconds for a command to start up And I run `sslocal-ruby -s 127.0.0.1 -k secret -o tls1.2_ticket_auth_compatible` in background - And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" + And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` + Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" diff --git a/features/server_functional.feature b/features/server_functional.feature index fd6d1eb..4ea1c2f 100644 --- a/features/server_functional.feature +++ b/features/server_functional.feature @@ -15,18 +15,24 @@ Background: Scenario: shadowsocks origin version When I run `ssserver-ruby -k secret` in background + And I wait 15 seconds for the command to start up And I run `docker run --rm --net=host zhenkyle/docker-sslocal -k secret -s 127.0.0.1` in background + And I wait 1 seconds for a command to start up And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with http_simple obfuscator When I run `ssserver-ruby -k secret -o http_simple` in background + And I wait 15 seconds for the command to start up And I run `docker run --rm --net=host zhenkyle/shadowsocksr sslocal -s 127.0.0.1 -k secret -o http_simple` in background + And I wait 1 seconds for a command to start up And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" Scenario: shadowsocks origin version with tls_ticket obfuscator When I run `ssserver-ruby -k secret -o tls1.2_ticket_auth_compatible` in background + And I wait 15 seconds for the command to start up And I run `docker run --rm --net=host zhenkyle/shadowsocksr sslocal -s 127.0.0.1 -k secret -o tls1.2_ticket_auth_compatible` in background + And I wait 1 seconds for a command to start up And I run `curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/` Then the output from "curl --socks5-hostname 127.0.0.1 http://127.0.0.1:5000/" should contain "

Example Domain

" From 064e9156360391782850d18aef0fe52e7f047fa1 Mon Sep 17 00:00:00 2001 From: Zhen Kyle Date: Tue, 18 Jul 2017 10:32:11 +0800 Subject: [PATCH 4/5] Fix setup --- script/setup | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/setup b/script/setup index db68bea..fd33161 100755 --- a/script/setup +++ b/script/setup @@ -10,11 +10,11 @@ cd "$(dirname "$0")/.." script/bootstrap -if [ -z "docker images -q zhenkyle/docker-sslocal" ]; then +if [ -z `docker images -q zhenkyle/docker-sslocal` ]; then docker pull zhenkyle/docker-sslocal fi -if [ -z "docker images -q zhenkyle/shadowsocksr" ]; then +if [ -z `docker images -q zhenkyle/shadowsocksr` ]; then docker pull zhenkyle/shadowsocksr fi From 428008d546ce2b2e3627942d465e32ff3d8a67ec Mon Sep 17 00:00:00 2001 From: Zhen Kyle Date: Tue, 18 Jul 2017 11:08:30 +0800 Subject: [PATCH 5/5] Change all test to local --- features/local_functional.feature | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/features/local_functional.feature b/features/local_functional.feature index ad22f5a..228d6fc 100644 --- a/features/local_functional.feature +++ b/features/local_functional.feature @@ -7,27 +7,41 @@ Background: Given curl is installed Given the default aruba stop signal is "INT" Given I wait 1 seconds for a command to start up + Given a file named "index.html" with: + """ +

Example Domain

+ """ + And I run `ruby -run -e httpd . -p 5000` in background Scenario: shadowsocks origin version And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host --entrypoint "ssserver" zhenkyle/docker-sslocal -k secret` in background And I wait 1 seconds for a command to start up And I run `sslocal-ruby -k secret -s 127.0.0.1` in background - And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" + When I run the following script: + """bash + curl --socks5-hostname 127.0.0.1 http://$(ip route get 1 | awk '{print $NF;exit}'):5000/ + """ + Then the output should contain "

Example Domain

" Scenario: shadowsocks origin version with http_simple obfuscator And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o http_simple` in background And I wait 1 seconds for a command to start up And I run `sslocal-ruby -s 127.0.0.1 -k secret -o http_simple` in background - And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" + When I run the following script: + """bash + curl --socks5-hostname 127.0.0.1 http://$(ip route get 1 | awk '{print $NF;exit}'):5000/ + """ + Then the output should contain "

Example Domain

" Scenario: shadowsocks origin version with tls_ticket obfuscator And I wait 15 seconds for the command to start up When I run `docker run --rm --net=host zhenkyle/shadowsocksr ssserver -k secret -o tls1.2_ticket_auth_compatible` in background And I wait 1 seconds for a command to start up And I run `sslocal-ruby -s 127.0.0.1 -k secret -o tls1.2_ticket_auth_compatible` in background - And I run `curl --socks5-hostname 127.0.0.1 http://example.com/` - Then the output from "curl --socks5-hostname 127.0.0.1 http://example.com/" should contain "

Example Domain

" + When I run the following script: + """bash + curl --socks5-hostname 127.0.0.1 http://$(ip route get 1 | awk '{print $NF;exit}'):5000/ + """ + Then the output should contain "

Example Domain

"