mogotest 0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +7 -0
- data/Rakefile +17 -0
- data/bin/mogotest +69 -0
- data/lib/localtunnel/net_ssh_gateway_patch.rb +39 -0
- data/lib/localtunnel/tunnel.rb +62 -0
- data/lib/mogotest.rb +3 -0
- data/lib/mogotest/tunnel.rb +30 -0
- data/mogotest.gemspec +42 -0
- metadata +143 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('mogotest', '0.9') do |p|
|
6
|
+
p.description = "Test your local Web servers on Mogotest without poking a hole in your firewall."
|
7
|
+
p.url = "http://mogotest.com"
|
8
|
+
p.author = "Jeff Lindsay"
|
9
|
+
p.email = "kevin@mogotest.com [Please don't bother Jeff]"
|
10
|
+
p.has_rdoc = false
|
11
|
+
p.rdoc_pattern = //
|
12
|
+
p.rdoc_options = []
|
13
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
14
|
+
p.executable_pattern = ["bin/*"]
|
15
|
+
p.runtime_dependencies = ["json >=1.2.4", "net-ssh >=2.0.22", "net-ssh-gateway >=1.0.1", "rest-client >=1.6.1"]
|
16
|
+
p.development_dependencies = []
|
17
|
+
end
|
data/bin/mogotest
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (c) 2010 Jeff Lindsay
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person
|
5
|
+
# obtaining a copy of this software and associated documentation
|
6
|
+
# files (the "Software"), to deal in the Software without
|
7
|
+
# restriction, including without limitation the rights to use,
|
8
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the
|
10
|
+
# Software is furnished to do so, subject to the following
|
11
|
+
# conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be
|
14
|
+
# included in all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'optparse'
|
27
|
+
require 'mogotest'
|
28
|
+
|
29
|
+
api_host = "mogotest.com"
|
30
|
+
tunnel_host = "open.mogotunnel.com"
|
31
|
+
public_ssh_key = nil
|
32
|
+
|
33
|
+
options = OptionParser.new do |o|
|
34
|
+
o.banner = "Usage: mogotest [options] <mogotest_api_key> <hostname_to_test> <local_port>"
|
35
|
+
|
36
|
+
o.on("-k", "--key FILE", "upload a public key for authentication") do |k|
|
37
|
+
public_ssh_key = File.exist?(k.to_s) ? File.open(k).read : nil
|
38
|
+
end
|
39
|
+
|
40
|
+
o.on("--tunnel_host HOST", "connect to the named tunnel host (advanced debug mode)") do |t|
|
41
|
+
tunnel_host = t
|
42
|
+
end
|
43
|
+
|
44
|
+
o.on("--api_host HOST", "connect to the named API host for registration (advanced debug mode)") do |a|
|
45
|
+
api_host = a
|
46
|
+
end
|
47
|
+
|
48
|
+
o.on('-h', "--help", "show this help") { puts o; exit }
|
49
|
+
end
|
50
|
+
|
51
|
+
args = options.parse!
|
52
|
+
api_key = args[0]
|
53
|
+
test_host = args[1]
|
54
|
+
local_port = args[2]
|
55
|
+
unless api_key && test_host && local_port
|
56
|
+
puts options
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
x = LocalTunnel::Tunnel.new(tunnel_host, local_port, public_ssh_key)
|
61
|
+
response = x.register_tunnel
|
62
|
+
|
63
|
+
m = Mogotest::Tunnel.new(api_host, api_key, test_host, response['host'])
|
64
|
+
m.notify_mogotest_of_tunnel
|
65
|
+
|
66
|
+
x.start_tunnel(m)
|
67
|
+
|
68
|
+
# start_tunnel blocks until the user sends an interrupt. At that point, execution will resume here.
|
69
|
+
m.teardown_tunnel_in_mogotest
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'net/ssh/gateway'
|
4
|
+
|
5
|
+
# http://groups.google.com/group/capistrano/browse_thread/thread/455c0c8a6faa9cc8?pli=1
|
6
|
+
class Net::SSH::Gateway
|
7
|
+
# Opens a SSH tunnel from a port on a remote host to a given host and port
|
8
|
+
# on the local side
|
9
|
+
# (equivalent to openssh -R parameter)
|
10
|
+
def open_remote(port, host, remote_port, remote_host = "127.0.0.1")
|
11
|
+
ensure_open!
|
12
|
+
|
13
|
+
@session_mutex.synchronize do
|
14
|
+
@session.forward.remote(port, host, remote_port, remote_host)
|
15
|
+
end
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
begin
|
19
|
+
yield [remote_port, remote_host]
|
20
|
+
ensure
|
21
|
+
close_remote(remote_port, remote_host)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
return [remote_port, remote_host]
|
25
|
+
end
|
26
|
+
rescue Errno::EADDRINUSE
|
27
|
+
retry
|
28
|
+
end
|
29
|
+
|
30
|
+
# Cancels port-forwarding over an open port that was previously opened via
|
31
|
+
# #open_remote.
|
32
|
+
def close_remote(port, host = "127.0.0.1")
|
33
|
+
ensure_open!
|
34
|
+
|
35
|
+
@session_mutex.synchronize do
|
36
|
+
@session.forward.cancel_remote(port, host)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'net/ssh/gateway'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require 'localtunnel/net_ssh_gateway_patch'
|
9
|
+
|
10
|
+
module LocalTunnel; end
|
11
|
+
|
12
|
+
class LocalTunnel::Tunnel
|
13
|
+
|
14
|
+
attr_accessor :tunnel_host, :port, :key, :host
|
15
|
+
|
16
|
+
def initialize(tunnel_host, port, key)
|
17
|
+
@tunnel_host = tunnel_host
|
18
|
+
@port = port
|
19
|
+
@key = key
|
20
|
+
@host = ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_tunnel(key=@key)
|
24
|
+
url = URI.parse("http://#{tunnel_host}/")
|
25
|
+
if key
|
26
|
+
resp = JSON.parse(Net::HTTP.post_form(url, {"key" => key}).body)
|
27
|
+
else
|
28
|
+
resp = JSON.parse(Net::HTTP.get(url))
|
29
|
+
end
|
30
|
+
if resp.has_key? 'error'
|
31
|
+
puts " [Error] #{resp['error']}"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
@host = resp['host'].split(':').first
|
35
|
+
@tunnel = resp
|
36
|
+
return resp
|
37
|
+
rescue
|
38
|
+
puts " [Error] Unable to register tunnel. Perhaps service is down?"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_tunnel(mogotest)
|
43
|
+
port = @port
|
44
|
+
tunnel = @tunnel
|
45
|
+
gateway = Net::SSH::Gateway.new(@host, tunnel['user'])
|
46
|
+
gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh|
|
47
|
+
puts " You're good to go. Any tests you run against '#{mogotest.test_host}' on Mogotest will now access your local server on port #{port}."
|
48
|
+
begin
|
49
|
+
sleep 1 while true
|
50
|
+
rescue Interrupt
|
51
|
+
gateway.close_remote(rp, rh)
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
rescue Net::SSH::AuthenticationFailed
|
56
|
+
possible_key = Dir[File.expand_path('~/.ssh/*.pub')].first
|
57
|
+
puts " Failed to authenticate. If this is your first tunnel, you need to"
|
58
|
+
puts " upload a public key using the -k option. Try this:\n\n"
|
59
|
+
puts " mogotest -k #{possible_key ? possible_key : '~/path/to/key'} #{mogotest.api_key} #{mogotest.test_host} #{port}"
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
end
|
data/lib/mogotest.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
require 'localtunnel/tunnel'
|
4
|
+
|
5
|
+
module Mogotest; end
|
6
|
+
|
7
|
+
class Mogotest::Tunnel
|
8
|
+
attr_accessor :api_host, :api_key, :test_host, :tunnel_url
|
9
|
+
|
10
|
+
def initialize(api_host, api_key, test_host, tunnel_url)
|
11
|
+
@api_host = api_host
|
12
|
+
@api_key = api_key
|
13
|
+
@test_host = test_host
|
14
|
+
@tunnel_url = tunnel_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def notify_mogotest_of_tunnel
|
18
|
+
RestClient.post "https://#{api_host}/api/v1/ssh_tunnels", { :user_credentials => api_key, :hostname => test_host, :tunnel_url => tunnel_url }
|
19
|
+
rescue
|
20
|
+
puts " [Error] Unable to register tunnel location with Mogotest API. Perhaps your credentials are bad."
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown_tunnel_in_mogotest
|
25
|
+
RestClient.post "https://#{api_host}/api/v1/ssh_tunnels/destroy", { :user_credentials => api_key, :hostname => test_host }
|
26
|
+
rescue
|
27
|
+
puts " [Error] Unable to delete tunnel location from Mogotest API. Perhaps your credentials are bad."
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
data/mogotest.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{mogotest}
|
5
|
+
s.version = "0.9"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jeff Lindsay"]
|
9
|
+
s.date = %q{2011-05-05}
|
10
|
+
s.default_executable = %q{mogotest}
|
11
|
+
s.description = %q{Test your local Web servers on Mogotest without poking a hole in your firewall.}
|
12
|
+
s.email = %q{kevin@mogotest.com [Please don't bother Jeff]}
|
13
|
+
s.executables = ["mogotest"]
|
14
|
+
s.extra_rdoc_files = ["Rakefile", "lib/mogotest.rb", "lib/localtunnel/tunnel.rb", "lib/localtunnel/net_ssh_gateway_patch.rb", "lib/mogotest/tunnel.rb", "bin/mogotest", "mogotest.gemspec"]
|
15
|
+
s.files = ["Rakefile", "lib/mogotest.rb", "lib/localtunnel/tunnel.rb", "lib/localtunnel/net_ssh_gateway_patch.rb", "lib/mogotest/tunnel.rb", "bin/mogotest", "Manifest", "mogotest.gemspec"]
|
16
|
+
s.homepage = %q{http://mogotest.com}
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{mogotest}
|
19
|
+
s.rubygems_version = %q{1.5.3}
|
20
|
+
s.summary = %q{Test your local Web servers on Mogotest without poking a hole in your firewall.}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<json>, [">= 1.2.4"])
|
27
|
+
s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.22"])
|
28
|
+
s.add_runtime_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
|
29
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.6.1"])
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<json>, [">= 1.2.4"])
|
32
|
+
s.add_dependency(%q<net-ssh>, [">= 2.0.22"])
|
33
|
+
s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
|
34
|
+
s.add_dependency(%q<rest-client>, [">= 1.6.1"])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<json>, [">= 1.2.4"])
|
38
|
+
s.add_dependency(%q<net-ssh>, [">= 2.0.22"])
|
39
|
+
s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
|
40
|
+
s.add_dependency(%q<rest-client>, [">= 1.6.1"])
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mogotest
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
version: "0.9"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jeff Lindsay
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-05 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 23
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 2
|
32
|
+
- 4
|
33
|
+
version: 1.2.4
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: net-ssh
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 35
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
- 22
|
49
|
+
version: 2.0.22
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: net-ssh-gateway
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 21
|
61
|
+
segments:
|
62
|
+
- 1
|
63
|
+
- 0
|
64
|
+
- 1
|
65
|
+
version: 1.0.1
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rest-client
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 13
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 6
|
80
|
+
- 1
|
81
|
+
version: 1.6.1
|
82
|
+
type: :runtime
|
83
|
+
version_requirements: *id004
|
84
|
+
description: Test your local Web servers on Mogotest without poking a hole in your firewall.
|
85
|
+
email: kevin@mogotest.com [Please don't bother Jeff]
|
86
|
+
executables:
|
87
|
+
- mogotest
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- Rakefile
|
92
|
+
- lib/mogotest.rb
|
93
|
+
- lib/localtunnel/tunnel.rb
|
94
|
+
- lib/localtunnel/net_ssh_gateway_patch.rb
|
95
|
+
- lib/mogotest/tunnel.rb
|
96
|
+
- bin/mogotest
|
97
|
+
- mogotest.gemspec
|
98
|
+
files:
|
99
|
+
- Rakefile
|
100
|
+
- lib/mogotest.rb
|
101
|
+
- lib/localtunnel/tunnel.rb
|
102
|
+
- lib/localtunnel/net_ssh_gateway_patch.rb
|
103
|
+
- lib/mogotest/tunnel.rb
|
104
|
+
- bin/mogotest
|
105
|
+
- Manifest
|
106
|
+
- mogotest.gemspec
|
107
|
+
has_rdoc: true
|
108
|
+
homepage: http://mogotest.com
|
109
|
+
licenses: []
|
110
|
+
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 11
|
131
|
+
segments:
|
132
|
+
- 1
|
133
|
+
- 2
|
134
|
+
version: "1.2"
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project: mogotest
|
138
|
+
rubygems_version: 1.5.3
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: Test your local Web servers on Mogotest without poking a hole in your firewall.
|
142
|
+
test_files: []
|
143
|
+
|