ngrok-wrapper 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.rubocop.yml +7 -1
- data/.ruby-version +1 -1
- data/.tool-versions +1 -1
- data/CHANGELOG.md +18 -1
- data/README.md +9 -5
- data/lib/ngrok/wrapper/version.rb +1 -1
- data/lib/ngrok/wrapper.rb +22 -10
- data/spec/ngrok/wrapper_spec.rb +286 -271
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af2e280f5efacf50a98453cbd8bbc26840b00fa74d31eff6346abc14fed1650f
|
4
|
+
data.tar.gz: 383a1dd7792b1dbff611f6f826ba24e9b904e41005622c8a7b68edbe45a82646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd6252001dbc722e9e087131e3eb8abc8561dce031d323a5a649b228233e6ebb7b39ceb04e9966c27701fd779aa6e3056c223331b1353175da1ac9715e0e28e5
|
7
|
+
data.tar.gz: 79e8891907659df3e858cad810b30e209139c1e9c1de0dee5834598ab2f4fd2e89a90aad17600bad8f8f084fd9273b8e89f97879a2660ce9787783ee013203ac
|
data/.github/workflows/ci.yml
CHANGED
@@ -25,7 +25,7 @@ jobs:
|
|
25
25
|
|
26
26
|
steps:
|
27
27
|
- name: Checkout
|
28
|
-
uses: actions/checkout@
|
28
|
+
uses: actions/checkout@v3
|
29
29
|
|
30
30
|
- name: Set up Ruby
|
31
31
|
uses: ruby/setup-ruby@v1
|
@@ -40,6 +40,6 @@ jobs:
|
|
40
40
|
run: bundle exec rspec
|
41
41
|
|
42
42
|
- name: Code Climate
|
43
|
-
uses: paambaati/codeclimate-action@v3.
|
43
|
+
uses: paambaati/codeclimate-action@v3.2.0
|
44
44
|
env:
|
45
45
|
CC_TEST_REPORTER_ID: d1116c05a48e27785cb11369bde3a5e7f9d9e5a114d294bcbefa19cd193b029c
|
data/.rubocop.yml
CHANGED
@@ -65,8 +65,14 @@ Metrics/BlockLength:
|
|
65
65
|
RSpec/MultipleExpectations:
|
66
66
|
Max: 13
|
67
67
|
|
68
|
-
RSpec/
|
68
|
+
RSpec/MultipleMemoizedHelpers:
|
69
|
+
Description: Checks if example groups contain too many `let` and `subject` calls.
|
70
|
+
Enabled: true
|
71
|
+
AllowSubject: true
|
69
72
|
Max: 7
|
70
73
|
|
74
|
+
RSpec/NestedGroups:
|
75
|
+
Max: 8
|
76
|
+
|
71
77
|
Style/StringLiterals:
|
72
78
|
ConsistentQuotesInMultiline: true
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6
|
1
|
+
2.7.6
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 2.6
|
1
|
+
ruby 2.7.6
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,25 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.3.0](https://github.com/texpert/ngrok-wrapper/tree/v0.3.0) (2022-11-19)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.2.0...v0.3.0)
|
6
|
+
|
7
|
+
Both Ngrok v2, and v3 are now supported.
|
8
|
+
|
9
|
+
Tested and working on Ubuntu Linux and macOS.
|
10
|
+
|
11
|
+
**Merged pull requests:**
|
12
|
+
|
13
|
+
- Added compatibility with Ngrok v3.x \(specs also enhanced to test both 2 and 3 versions\) [\#24](https://github.com/texpert/ngrok-wrapper/pull/24) ([texpert](https://github.com/texpert))
|
14
|
+
- Prepare for different ngrok versions params, still for version 2 [\#23](https://github.com/texpert/ngrok-wrapper/pull/23) ([texpert](https://github.com/texpert))
|
15
|
+
- Allow region subdomains - modify Rails config.hosts example to parse the host from NGROK\_URL [\#22](https://github.com/texpert/ngrok-wrapper/pull/22) ([texpert](https://github.com/texpert))
|
16
|
+
- Set main Ruby version to 2.7.6 [\#21](https://github.com/texpert/ngrok-wrapper/pull/21) ([texpert](https://github.com/texpert))
|
17
|
+
- Bump actions/checkout from 2 to 3 [\#19](https://github.com/texpert/ngrok-wrapper/pull/19) ([texpert](https://github.com/texpert))
|
18
|
+
|
3
19
|
## [v0.2.0](https://github.com/texpert/ngrok-wrapper/tree/v0.2.0) (2022-02-19)
|
4
20
|
|
21
|
+
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.1.0...v0.2.0)
|
22
|
+
|
5
23
|
### Making Ngrok process survive server stop on Linux
|
6
24
|
|
7
25
|
It was working OK on Mac OS on the 0.1.0 release, but not on Linux.
|
@@ -10,7 +28,6 @@ It came out that `Process.setsid` should be applied to the spawned process to es
|
|
10
28
|
and process group leader. This is completely detaching it from the parent process, so it won't be killed when the
|
11
29
|
parent will go down.
|
12
30
|
|
13
|
-
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.1.0...v0.2.0)
|
14
31
|
|
15
32
|
**Merged pull requests:**
|
16
33
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ngrok::Wrapper
|
2
2
|
|
3
|
-
Ngrok-wrapper gem is a ruby wrapper for ngrok v2.
|
3
|
+
Ngrok-wrapper gem is a ruby wrapper for ngrok v2.x or v3.x.
|
4
4
|
|
5
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/d978e217a8219326e325/maintainability)](https://codeclimate.com/github/texpert/ngrok-wrapper/maintainability)
|
6
6
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/d978e217a8219326e325/test_coverage)](https://codeclimate.com/github/texpert/ngrok-wrapper/test_coverage)
|
@@ -22,7 +22,9 @@ So, excuse me, [Anton Bogdanovich](https://github.com/bogdanovich), but I've dec
|
|
22
22
|
|
23
23
|
## Installation
|
24
24
|
|
25
|
-
|
25
|
+
**Pre-requisites:** You must have `ngrok` v2+ or v3+ installed available in your `PATH`.
|
26
|
+
|
27
|
+
**Upgrade Note:** Do not forget to run `ngrok config upgrade` after upgrading `ngrok` from v2.x to v3.x
|
26
28
|
|
27
29
|
Add this line to your application's Gemfile:
|
28
30
|
|
@@ -32,7 +34,7 @@ gem 'ngrok-wrapper'
|
|
32
34
|
|
33
35
|
And then execute:
|
34
36
|
|
35
|
-
$ bundle
|
37
|
+
$ bundle install
|
36
38
|
|
37
39
|
Or install it yourself as:
|
38
40
|
|
@@ -139,8 +141,10 @@ end
|
|
139
141
|
- And in `config/environments/development.rb`:
|
140
142
|
|
141
143
|
```ruby
|
142
|
-
|
143
|
-
config.
|
144
|
+
if NGROK_ENABLED
|
145
|
+
config.force_ssl = true
|
146
|
+
config.hosts << URI.parse(NGROK_URL).host # for Rails >= 6.0.0
|
147
|
+
end
|
144
148
|
|
145
149
|
config.action_mailer.default_url_options = {
|
146
150
|
host: NGROK_ENABLED ? NGROK_URL.delete_prefix('https://') : 'myapp.local',
|
data/lib/ngrok/wrapper.rb
CHANGED
@@ -4,7 +4,16 @@ require_relative 'wrapper/version'
|
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
6
|
module Ngrok
|
7
|
-
|
7
|
+
VERSION_PARAMS = {
|
8
|
+
'2' => {
|
9
|
+
flag_prefix: '-',
|
10
|
+
http_tunnel_flags: %i[config authtoken bind_tls host_header hostname inspect region subdomain].freeze
|
11
|
+
},
|
12
|
+
'3' => {
|
13
|
+
flag_prefix: '--',
|
14
|
+
http_tunnel_flags: %i[config authtoken scheme host_header hostname inspect region subdomain].freeze
|
15
|
+
}
|
16
|
+
}.freeze
|
8
17
|
|
9
18
|
class NotFound < StandardError; end
|
10
19
|
class FetchUrlError < StandardError; end
|
@@ -24,6 +33,9 @@ module Ngrok
|
|
24
33
|
|
25
34
|
def start(params = {})
|
26
35
|
ensure_binary
|
36
|
+
@current_version_params = VERSION_PARAMS[@major_version]
|
37
|
+
@flag_prefix = @current_version_params[:flag_prefix]
|
38
|
+
|
27
39
|
init(params)
|
28
40
|
|
29
41
|
persistent_ngrok = @params[:persistence] == true
|
@@ -84,7 +96,7 @@ module Ngrok
|
|
84
96
|
def raise_if_similar_ngroks(pid)
|
85
97
|
other_ngrok_on_port = ngrok_process_status_lines.find do |line|
|
86
98
|
# If found an Ngrok process with other pid, tunneling on the port, specified in Ngrok::Wrapper.start params
|
87
|
-
line.include?(
|
99
|
+
line.include?("ngrok http #{@flag_prefix}log") && !line.start_with?(pid || '') && line.end_with?(addr.to_s)
|
88
100
|
end
|
89
101
|
|
90
102
|
raise Ngrok::Error, "ERROR: Other ngrok instances tunneling to port #{addr} found" if other_ngrok_on_port
|
@@ -93,7 +105,7 @@ module Ngrok
|
|
93
105
|
|
94
106
|
tunnel_on_other_port = ngrok_process_status_lines.find do |line|
|
95
107
|
# If the line starts with this pid, but the port is other than specified in Ngrok::Wrapper.start params
|
96
|
-
line.include?(
|
108
|
+
line.include?("ngrok http #{@flag_prefix}log") && line.start_with?(pid) && !line.end_with?(addr.to_s)
|
97
109
|
end
|
98
110
|
|
99
111
|
return unless tunnel_on_other_port
|
@@ -125,7 +137,7 @@ module Ngrok
|
|
125
137
|
def ngrok_running?(pid)
|
126
138
|
ngrok_process_status_lines.find do |line|
|
127
139
|
# If found the Ngrok process with correct pid, tunneling on the port, specified in Ngrok::Wrapper.start params
|
128
|
-
line.include?(
|
140
|
+
line.include?("ngrok http #{@flag_prefix}log") && line.start_with?(pid) && line.end_with?(addr.to_s)
|
129
141
|
end
|
130
142
|
end
|
131
143
|
|
@@ -142,7 +154,7 @@ module Ngrok
|
|
142
154
|
sleep 0.5
|
143
155
|
|
144
156
|
@pid = ngrok_process_status_lines(refetch: true)
|
145
|
-
.find { |line| line.include?(
|
157
|
+
.find { |line| line.include?("ngrok http #{@flag_prefix}log") && line.end_with?(addr.to_s) }.split[0]
|
146
158
|
else
|
147
159
|
@pid = Process.spawn("exec ngrok http #{ngrok_exec_params}")
|
148
160
|
at_exit { Ngrok::Wrapper.stop }
|
@@ -152,11 +164,11 @@ module Ngrok
|
|
152
164
|
end
|
153
165
|
|
154
166
|
def ngrok_exec_params
|
155
|
-
exec_params = +
|
156
|
-
|
157
|
-
exec_params << "
|
167
|
+
exec_params = +"#{@flag_prefix}log=stdout #{@flag_prefix}log-level=debug "
|
168
|
+
@current_version_params[:http_tunnel_flags].each do |flag|
|
169
|
+
exec_params << "#{@flag_prefix}#{flag.to_s.tr('_', '-')}=#{@params[flag]} " if @params.key?(flag)
|
158
170
|
end
|
159
|
-
exec_params << "
|
171
|
+
exec_params << " #{@params[:addr]} > #{@params[:log].path}"
|
160
172
|
end
|
161
173
|
|
162
174
|
def fetch_urls
|
@@ -191,7 +203,7 @@ module Ngrok
|
|
191
203
|
end
|
192
204
|
|
193
205
|
def ensure_binary
|
194
|
-
`ngrok version
|
206
|
+
@major_version, * = `ngrok version`.chomp.delete_prefix('ngrok version ').split('.')
|
195
207
|
rescue Errno::ENOENT
|
196
208
|
raise Ngrok::NotFound, 'Ngrok binary not found'
|
197
209
|
end
|
data/spec/ngrok/wrapper_spec.rb
CHANGED
@@ -4,354 +4,369 @@ RSpec.describe 'Ngrok::Wrapper' do
|
|
4
4
|
let(:log) { File.read("#{RSPEC_ROOT}/fixtures/ngrok.sample.log") }
|
5
5
|
let(:fake_pid) { rand(99_999) }
|
6
6
|
|
7
|
-
|
8
|
-
allow(Ngrok::Wrapper).to receive(:ensure_binary)
|
9
|
-
allow(Ngrok::Wrapper).to receive(:raise_if_similar_ngroks)
|
10
|
-
allow(Process).to receive(:spawn).and_return(fake_pid)
|
11
|
-
allow(Process).to receive(:kill)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'has a version number' do
|
15
|
-
expect(Ngrok::Wrapper::VERSION).not_to be nil
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 'Before start' do
|
19
|
-
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
7
|
+
ngrok_versions = %w[2 3]
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
it 'is stopped' do
|
26
|
-
expect(Ngrok::Wrapper.stopped?).to be true
|
27
|
-
end
|
9
|
+
ngrok_versions.each do |ngrok_version|
|
10
|
+
describe "Ngrok v#{ngrok_version}" do
|
11
|
+
let(:flag_prefix) { Ngrok::VERSION_PARAMS[ngrok_version][:flag_prefix] }
|
12
|
+
let(:config_path) { "#{flag_prefix}config /Users/thunder/.ngrok2/ngrok.yml" }
|
28
13
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
14
|
+
before do
|
15
|
+
Ngrok::Wrapper.instance_variable_set(:@major_version, ngrok_version)
|
16
|
+
allow(Ngrok::Wrapper).to receive(:ensure_binary)
|
17
|
+
allow(Ngrok::Wrapper).to receive(:ngrok_process_status_lines)
|
18
|
+
allow(Ngrok::Wrapper).to receive(:raise_if_similar_ngroks)
|
19
|
+
allow(Process).to receive(:spawn).and_return(fake_pid)
|
20
|
+
allow(Process).to receive(:kill)
|
21
|
+
end
|
33
22
|
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
it 'has a version number' do
|
24
|
+
expect(Ngrok::Wrapper::VERSION).not_to be nil
|
25
|
+
end
|
37
26
|
|
38
|
-
|
39
|
-
|
27
|
+
describe 'Before start' do
|
28
|
+
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
40
29
|
|
41
|
-
|
30
|
+
it 'is not running' do
|
31
|
+
expect(Ngrok::Wrapper.running?).to be false
|
32
|
+
end
|
42
33
|
|
43
|
-
|
44
|
-
|
45
|
-
|
34
|
+
it 'is stopped' do
|
35
|
+
expect(Ngrok::Wrapper.stopped?).to be true
|
36
|
+
end
|
46
37
|
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
it 'has :stopped status' do
|
39
|
+
expect(Ngrok::Wrapper.status).to eq :stopped
|
40
|
+
end
|
41
|
+
end
|
50
42
|
|
51
|
-
|
52
|
-
|
53
|
-
|
43
|
+
describe 'After start' do
|
44
|
+
before do
|
45
|
+
allow_any_instance_of(Tempfile).to receive(:read).and_return(log)
|
54
46
|
|
55
|
-
|
56
|
-
|
57
|
-
end
|
47
|
+
Ngrok::Wrapper.start
|
48
|
+
end
|
58
49
|
|
59
|
-
|
60
|
-
expect(Ngrok::Wrapper.addr).to eq(3001)
|
61
|
-
end
|
50
|
+
after { Ngrok::Wrapper.stop }
|
62
51
|
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
it 'is running' do
|
53
|
+
expect(Ngrok::Wrapper.running?).to be true
|
54
|
+
end
|
66
55
|
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
it 'is not stopped' do
|
57
|
+
expect(Ngrok::Wrapper.stopped?).to be false
|
58
|
+
end
|
70
59
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
60
|
+
it 'has :running status' do
|
61
|
+
expect(Ngrok::Wrapper.status).to eq :running
|
62
|
+
end
|
75
63
|
|
76
|
-
|
77
|
-
|
64
|
+
it 'has correct port property' do
|
65
|
+
expect(Ngrok::Wrapper.port).to eq(3001)
|
66
|
+
end
|
78
67
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
expect(Ngrok::Wrapper.params[:log].path).to eq 'test.log'
|
83
|
-
Ngrok::Wrapper.stop
|
84
|
-
expect(Ngrok::Wrapper.stopped?).to eq true
|
85
|
-
end
|
86
|
-
end
|
68
|
+
it 'has correct addr property' do
|
69
|
+
expect(Ngrok::Wrapper.addr).to eq(3001)
|
70
|
+
end
|
87
71
|
|
88
|
-
|
89
|
-
|
90
|
-
|
72
|
+
it 'has valid ngrok_url' do
|
73
|
+
expect(Ngrok::Wrapper.ngrok_url).to be =~ %r{http://.*ngrok\.io$}
|
74
|
+
end
|
91
75
|
|
92
|
-
|
93
|
-
|
76
|
+
it 'has valid ngrok_url_https' do
|
77
|
+
expect(Ngrok::Wrapper.ngrok_url_https).to be =~ %r{https://.*ngrok\.io$}
|
78
|
+
end
|
94
79
|
|
95
|
-
|
80
|
+
it 'has correct pid property' do
|
81
|
+
expect(Ngrok::Wrapper.pid).to be > 0
|
82
|
+
end
|
96
83
|
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe 'when an invalid authtoken is specified in ngrok config file' do
|
100
|
-
let(:invalid_auth_log) { File.read("#{RSPEC_ROOT}/fixtures/ngrok.no_auth_token.log") }
|
101
84
|
|
102
|
-
|
103
|
-
allow_any_instance_of(
|
85
|
+
describe 'Custom log file' do
|
86
|
+
before { allow_any_instance_of(File).to receive(:read).and_return(log) }
|
104
87
|
|
105
|
-
|
106
|
-
Ngrok::Wrapper.start(
|
107
|
-
|
88
|
+
it 'uses custom log file' do
|
89
|
+
Ngrok::Wrapper.start(log: 'test.log')
|
90
|
+
expect(Ngrok::Wrapper.running?).to eq true
|
91
|
+
expect(Ngrok::Wrapper.params[:log].path).to eq 'test.log'
|
92
|
+
Ngrok::Wrapper.stop
|
93
|
+
expect(Ngrok::Wrapper.stopped?).to eq true
|
94
|
+
end
|
108
95
|
end
|
109
|
-
end
|
110
|
-
end
|
111
96
|
|
112
|
-
|
113
|
-
|
97
|
+
describe 'Invalid or missing authtoken' do
|
98
|
+
describe 'when no authtoken is specified in ngrok config file' do
|
99
|
+
let(:no_auth_log) { File.read("#{RSPEC_ROOT}/fixtures/ngrok.no_auth_token.log") }
|
114
100
|
|
115
|
-
|
116
|
-
|
117
|
-
Ngrok::Wrapper.start(port: port)
|
118
|
-
expect(Ngrok::Wrapper.addr).to eq port
|
119
|
-
Ngrok::Wrapper.stop
|
120
|
-
end
|
101
|
+
it 'raises Ngrok::Error exception' do
|
102
|
+
allow_any_instance_of(Tempfile).to receive(:read).and_return(no_auth_log)
|
121
103
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
expect(Ngrok::Wrapper.port).to eq 10_010
|
126
|
-
Ngrok::Wrapper.stop
|
127
|
-
end
|
104
|
+
expect { Ngrok::Wrapper.start }.to raise_error Ngrok::Error
|
105
|
+
end
|
106
|
+
end
|
128
107
|
|
129
|
-
|
130
|
-
|
131
|
-
Ngrok::Wrapper.start(addr: addr)
|
132
|
-
expect(Ngrok::Wrapper.addr).to eq addr
|
133
|
-
Ngrok::Wrapper.stop
|
134
|
-
end
|
135
|
-
end
|
108
|
+
describe 'when an invalid authtoken is specified in ngrok config file' do
|
109
|
+
let(:invalid_auth_log) { File.read("#{RSPEC_ROOT}/fixtures/ngrok.no_auth_token.log") }
|
136
110
|
|
137
|
-
|
138
|
-
|
111
|
+
it 'fails with incorrect authtoken' do
|
112
|
+
allow_any_instance_of(Tempfile).to receive(:read).and_return(invalid_auth_log)
|
139
113
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
114
|
+
expect do
|
115
|
+
Ngrok::Wrapper.start(authtoken: 'incorrect_token')
|
116
|
+
end.to raise_error Ngrok::Error
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
145
120
|
|
146
|
-
|
147
|
-
|
148
|
-
Ngrok::Wrapper.start(region: region)
|
149
|
-
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-region=#{region}")
|
150
|
-
Ngrok::Wrapper.stop
|
151
|
-
end
|
152
|
-
end
|
121
|
+
describe 'Custom addr' do
|
122
|
+
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
153
123
|
|
154
|
-
|
155
|
-
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
124
|
+
after { Ngrok::Wrapper.stop }
|
156
125
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
126
|
+
it 'maps port param to addr' do
|
127
|
+
port = 10_010
|
128
|
+
Ngrok::Wrapper.start(port: port)
|
129
|
+
expect(Ngrok::Wrapper.addr).to eq port
|
130
|
+
end
|
162
131
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
end
|
132
|
+
it 'returns just the port when the address contains a host' do
|
133
|
+
addr = '192.168.0.5:10010'
|
134
|
+
Ngrok::Wrapper.start(addr: addr)
|
135
|
+
expect(Ngrok::Wrapper.port).to eq 10_010
|
136
|
+
end
|
169
137
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
end
|
138
|
+
it 'supports remote addresses' do
|
139
|
+
addr = '192.168.0.5:10010'
|
140
|
+
Ngrok::Wrapper.start(addr: addr)
|
141
|
+
expect(Ngrok::Wrapper.addr).to eq addr
|
142
|
+
end
|
143
|
+
end
|
177
144
|
|
178
|
-
|
179
|
-
|
145
|
+
describe 'Custom region' do
|
146
|
+
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
180
147
|
|
181
|
-
|
182
|
-
expect(Ngrok::Wrapper).to receive(:fetch_urls)
|
183
|
-
Ngrok::Wrapper.start
|
184
|
-
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-host-header=')
|
185
|
-
end
|
148
|
+
after { Ngrok::Wrapper.stop }
|
186
149
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-host-header=#{host_header}")
|
192
|
-
end
|
193
|
-
end
|
150
|
+
it "doesn't include the -region parameter when it is not provided" do
|
151
|
+
Ngrok::Wrapper.start
|
152
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-region=')
|
153
|
+
end
|
194
154
|
|
195
|
-
|
196
|
-
|
155
|
+
it 'includes the -region parameter with the correct value when it is provided' do
|
156
|
+
region = 'eu'
|
157
|
+
Ngrok::Wrapper.start(region: region)
|
158
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-region=#{region}")
|
159
|
+
end
|
160
|
+
end
|
197
161
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
Ngrok::Wrapper.stop
|
202
|
-
end
|
162
|
+
describe 'Custom bind-tls' do
|
163
|
+
# It is 'bind_tls' for Ngrok v2, and 'scheme' for Ngrok v3
|
164
|
+
let(:bind_tls_flag) { Ngrok::VERSION_PARAMS[ngrok_version][:http_tunnel_flags][2] }
|
203
165
|
|
204
|
-
|
205
|
-
Ngrok::Wrapper.start(inspect: true)
|
206
|
-
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include('-inspect=true')
|
207
|
-
Ngrok::Wrapper.stop
|
166
|
+
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
208
167
|
|
209
|
-
|
210
|
-
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include('-inspect=false')
|
211
|
-
Ngrok::Wrapper.stop
|
212
|
-
end
|
213
|
-
end
|
168
|
+
after { Ngrok::Wrapper.stop }
|
214
169
|
|
215
|
-
|
216
|
-
|
170
|
+
it "doesn't include the -bind-tls parameter when it is not provided" do
|
171
|
+
Ngrok::Wrapper.start
|
172
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params))
|
173
|
+
.not_to include("#{flag_prefix}#{bind_tls_flag.to_s.tr('_', '-')}=")
|
174
|
+
end
|
217
175
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
end
|
176
|
+
it 'includes the -bind-tls parameter with the correct value when it is true' do
|
177
|
+
Ngrok::Wrapper.start(bind_tls_flag => true)
|
178
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params))
|
179
|
+
.to include("#{flag_prefix}#{bind_tls_flag.to_s.tr('_', '-')}=true")
|
180
|
+
end
|
224
181
|
|
225
|
-
|
226
|
-
|
227
|
-
|
182
|
+
it 'includes the -bind-tls parameter with the correct value when it is false' do
|
183
|
+
Ngrok::Wrapper.start(bind_tls_flag => false)
|
184
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params))
|
185
|
+
.to include("#{flag_prefix}#{bind_tls_flag.to_s.tr('_', '-')}=false")
|
186
|
+
end
|
187
|
+
end
|
228
188
|
|
229
|
-
|
230
|
-
|
231
|
-
expect(Ngrok::Wrapper).not_to receive(:raise_if_similar_ngroks)
|
232
|
-
expect(Ngrok::Wrapper).not_to receive(:ngrok_running?)
|
233
|
-
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
|
234
|
-
expect(File).to receive(:write)
|
189
|
+
describe 'Custom host header' do
|
190
|
+
after { Ngrok::Wrapper.stop }
|
235
191
|
|
236
|
-
|
237
|
-
|
192
|
+
it "doesn't include the -host-header parameter when it is not provided" do
|
193
|
+
expect(Ngrok::Wrapper).to receive(:fetch_urls)
|
194
|
+
Ngrok::Wrapper.start
|
195
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-host-header=')
|
238
196
|
end
|
239
197
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
198
|
+
it 'includes the -host-header parameter with the correct value when it is provided' do
|
199
|
+
expect(Ngrok::Wrapper).to receive(:fetch_urls)
|
200
|
+
host_header = 'foo.bar'
|
201
|
+
Ngrok::Wrapper.start(host_header: host_header)
|
202
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-host-header=#{host_header}")
|
203
|
+
end
|
204
|
+
end
|
246
205
|
|
247
|
-
|
248
|
-
|
249
|
-
allow(Ngrok::Wrapper).to receive(:raise_if_similar_ngroks).and_call_original
|
250
|
-
allow(Ngrok::Wrapper).to receive(:ngrok_process_status_lines).and_return(ngrok_ps_lines)
|
206
|
+
describe 'Custom parameters provided' do
|
207
|
+
before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
|
251
208
|
|
252
|
-
|
253
|
-
|
209
|
+
it "doesn't include the -inspect parameter when it is not provided" do
|
210
|
+
Ngrok::Wrapper.start
|
211
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-inspect=')
|
212
|
+
Ngrok::Wrapper.stop
|
213
|
+
end
|
254
214
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
215
|
+
it 'includes the -inspect parameter with the correct value when it is provided' do
|
216
|
+
Ngrok::Wrapper.start(inspect: true)
|
217
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include('-inspect=true')
|
218
|
+
Ngrok::Wrapper.stop
|
259
219
|
|
260
|
-
|
261
|
-
|
220
|
+
Ngrok::Wrapper.start(inspect: false)
|
221
|
+
expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include('-inspect=false')
|
222
|
+
Ngrok::Wrapper.stop
|
223
|
+
end
|
224
|
+
end
|
262
225
|
|
263
|
-
|
226
|
+
describe '#start' do
|
227
|
+
after { Ngrok::Wrapper.stop }
|
264
228
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
229
|
+
describe 'when persistence param is true' do
|
230
|
+
before do
|
231
|
+
allow(File).to receive(:write)
|
232
|
+
allow(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok).and_call_original
|
233
|
+
allow(Ngrok::Wrapper).to receive(:parse_persistence_file).and_return(state)
|
234
|
+
end
|
272
235
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
end
|
236
|
+
describe 'tries fetching params of an already running Ngrok and store Ngrok process data into a file' do
|
237
|
+
describe 'when fetching params returns nil' do
|
238
|
+
let(:state) { nil }
|
277
239
|
|
278
|
-
it '
|
279
|
-
expect(Ngrok::Wrapper).
|
240
|
+
it "doesn't check for similar ngroks running" do
|
241
|
+
expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
|
242
|
+
expect(Ngrok::Wrapper).not_to receive(:raise_if_similar_ngroks)
|
243
|
+
expect(Ngrok::Wrapper).not_to receive(:ngrok_running?)
|
244
|
+
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
|
245
|
+
expect(File).to receive(:write)
|
280
246
|
|
281
|
-
|
282
|
-
.to raise_error(Ngrok::Error, 'ERROR: Other ngrok instances tunneling to port 3001 found')
|
247
|
+
Ngrok::Wrapper.start(persistence: true)
|
283
248
|
end
|
284
249
|
end
|
285
250
|
|
286
|
-
describe 'when
|
251
|
+
describe 'when fetching params returns a legit hash' do
|
287
252
|
let(:ngrok_ps_lines) do
|
288
|
-
[
|
253
|
+
["795 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:3001"]
|
289
254
|
end
|
290
255
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
.to raise_error(Ngrok::Error, 'ERROR: Ngrok pid #795 tunneling on other port 3000')
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
describe 'when no Ngrok process with params from the persisted file or similar is running' do
|
300
|
-
let(:ngrok_ps_lines) do
|
301
|
-
['834 ?? S 0:04.81 ngrok http -log -config /Users/thunder/.ngrok2/ngrok.yml https://localhost:5001']
|
256
|
+
let(:state) do
|
257
|
+
{ 'pid' => '795',
|
258
|
+
'ngrok_url' => 'http://b1cd-109-185-141-9.ngrok.io',
|
259
|
+
'ngrok_url_https' => 'https://b1cd-109-185-141-9.ngrok.io' }
|
302
260
|
end
|
303
261
|
|
304
|
-
|
305
|
-
|
262
|
+
before { allow(Ngrok::Wrapper).to receive(:ngrok_process_status_lines).and_return(ngrok_ps_lines) }
|
263
|
+
|
264
|
+
describe 'checking if a similar Ngrok is running' do
|
265
|
+
before do
|
266
|
+
allow(Ngrok::Wrapper).to receive(:raise_if_similar_ngroks).and_call_original
|
267
|
+
|
268
|
+
expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
|
269
|
+
end
|
270
|
+
|
271
|
+
describe 'when Ngrok process with params from the persisted file is running' do
|
272
|
+
it 'set Ngrok::Wrapper pid and status attributes' do
|
273
|
+
expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
|
274
|
+
|
275
|
+
result = Ngrok::Wrapper.start(persistence: true)
|
276
|
+
|
277
|
+
expect(Ngrok::Wrapper.pid).to eql('795')
|
278
|
+
expect(Ngrok::Wrapper.status).to eql(:running)
|
279
|
+
expect(Ngrok::Wrapper.ngrok_url).to eql('http://b1cd-109-185-141-9.ngrok.io')
|
280
|
+
expect(Ngrok::Wrapper.ngrok_url_https).to eql('https://b1cd-109-185-141-9.ngrok.io')
|
281
|
+
expect(result).to eql('https://b1cd-109-185-141-9.ngrok.io')
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe 'when a similar Ngrok with other pid is already running' do
|
286
|
+
let(:ngrok_ps_lines) do
|
287
|
+
["71986 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:3001"]
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'raises exception' do
|
291
|
+
expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
|
292
|
+
|
293
|
+
expect { Ngrok::Wrapper.start(persistence: true) }
|
294
|
+
.to raise_error(Ngrok::Error, 'ERROR: Other ngrok instances tunneling to port 3001 found')
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
describe 'when Ngrok with the persisted pid is already running, but on a different port' do
|
299
|
+
let(:ngrok_ps_lines) do
|
300
|
+
["795 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:3000"]
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'raises exception' do
|
304
|
+
expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
|
305
|
+
|
306
|
+
expect { Ngrok::Wrapper.start(persistence: true) }
|
307
|
+
.to raise_error(Ngrok::Error, 'ERROR: Ngrok pid #795 tunneling on other port 3000')
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
describe 'when no Ngrok process with params from the persisted file or similar is running' do
|
312
|
+
let(:ngrok_ps_lines) do
|
313
|
+
["834 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:5001"]
|
314
|
+
end
|
315
|
+
|
316
|
+
let(:new_ngrok_ps_lines) do
|
317
|
+
["835 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:3001"]
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'sets Ngrok::Wrapper pid and status attributes' do
|
321
|
+
allow(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true).and_call_original
|
322
|
+
allow(Ngrok::Wrapper).to receive(:fork)
|
323
|
+
allow(Ngrok::Wrapper)
|
324
|
+
.to receive(:ngrok_process_status_lines).with(refetch: true).and_return(new_ngrok_ps_lines)
|
325
|
+
allow(Ngrok::Wrapper).to receive(:fetch_urls)
|
326
|
+
|
327
|
+
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
|
328
|
+
expect(Ngrok::Wrapper).to receive(:fork)
|
329
|
+
expect(Ngrok::Wrapper).to receive(:ngrok_process_status_lines).with(refetch: true)
|
330
|
+
allow(Ngrok::Wrapper).to receive(:fetch_urls)
|
331
|
+
|
332
|
+
Ngrok::Wrapper.start(persistence: true)
|
333
|
+
|
334
|
+
expect(Ngrok::Wrapper.pid).to eql('835')
|
335
|
+
expect(Ngrok::Wrapper.status).to eql(:running)
|
336
|
+
end
|
337
|
+
end
|
306
338
|
end
|
307
339
|
|
308
|
-
it '
|
309
|
-
|
310
|
-
|
311
|
-
allow(Ngrok::Wrapper)
|
312
|
-
.to receive(:ngrok_process_status_lines).with(refetch: true).and_return(new_ngrok_ps_lines)
|
313
|
-
allow(Ngrok::Wrapper).to receive(:fetch_urls)
|
314
|
-
|
315
|
-
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
|
316
|
-
expect(Ngrok::Wrapper).to receive(:fork)
|
317
|
-
expect(Ngrok::Wrapper).to receive(:ngrok_process_status_lines).with(refetch: true)
|
318
|
-
allow(Ngrok::Wrapper).to receive(:fetch_urls)
|
340
|
+
it 'tries fetching params of an already running Ngrok and store Ngrok process data into a file' do
|
341
|
+
expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
|
342
|
+
expect(File).to receive(:write)
|
319
343
|
|
320
344
|
Ngrok::Wrapper.start(persistence: true)
|
321
|
-
|
322
|
-
expect(Ngrok::Wrapper.pid).to eql('835')
|
323
|
-
expect(Ngrok::Wrapper.status).to eql(:running)
|
324
345
|
end
|
325
346
|
end
|
326
347
|
end
|
348
|
+
end
|
349
|
+
|
350
|
+
describe 'when persistence param is not true' do
|
351
|
+
after { Ngrok::Wrapper.stop }
|
327
352
|
|
328
|
-
it '
|
329
|
-
expect(Ngrok::Wrapper).
|
330
|
-
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok:
|
331
|
-
|
353
|
+
it "doesn't try to fetch params of an already running Ngrok" do
|
354
|
+
expect(Ngrok::Wrapper).not_to receive(:try_params_from_running_ngrok)
|
355
|
+
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: false)
|
356
|
+
expect_any_instance_of(File).not_to receive(:write)
|
332
357
|
|
333
|
-
Ngrok::Wrapper.start(persistence:
|
358
|
+
Ngrok::Wrapper.start(persistence: false)
|
334
359
|
end
|
335
360
|
end
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe 'when persistence param is not true' do
|
340
|
-
it "doesn't try to fetch params of an already running Ngrok" do
|
341
|
-
expect(Ngrok::Wrapper).not_to receive(:try_params_from_running_ngrok)
|
342
|
-
expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: false)
|
343
|
-
expect_any_instance_of(File).not_to receive(:write)
|
344
361
|
|
345
|
-
Ngrok::Wrapper
|
346
|
-
|
347
|
-
|
362
|
+
describe 'when Ngrok::Wrapper is already running' do
|
363
|
+
it "doesn't try to spawn a new Ngrok process" do
|
364
|
+
allow(Ngrok::Wrapper).to receive(:stopped?).and_return(false)
|
365
|
+
expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
|
348
366
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
|
353
|
-
|
354
|
-
Ngrok::Wrapper.start
|
367
|
+
Ngrok::Wrapper.start
|
368
|
+
end
|
369
|
+
end
|
355
370
|
end
|
356
371
|
end
|
357
372
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ngrok-wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Bogdanovich
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: github_changelog_generator
|
@@ -151,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
|
-
rubygems_version: 3.
|
154
|
+
rubygems_version: 3.3.10
|
155
155
|
signing_key:
|
156
156
|
specification_version: 4
|
157
157
|
summary: Ngrok-wrapper gem is a ruby wrapper for ngrok2
|