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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73d4023376c99fae6a7c7c0e5461e1fb2fe91d83531bc77e35252e42e87a9795
4
- data.tar.gz: 61eecae9040ebbe584b02cacea0c0a41a84d928dd6ebe7964c20f4b391e155e4
3
+ metadata.gz: af2e280f5efacf50a98453cbd8bbc26840b00fa74d31eff6346abc14fed1650f
4
+ data.tar.gz: 383a1dd7792b1dbff611f6f826ba24e9b904e41005622c8a7b68edbe45a82646
5
5
  SHA512:
6
- metadata.gz: e20e1589b5b0e375acbbd59b0c6e7b472906a1f54534e6695492926fdad36b1aeec2a25fef568fb7527d9416c7a4cae78296473733ccb4166b8c6bbaec95ead4
7
- data.tar.gz: 237102d6642b6f58f5be5e9b35dfe9782863f93662df84c6a9864728df9103c67e4bf12badc87fa481e80b7156b636caab7ecd7058dfb44467e4420968dc191d
6
+ metadata.gz: dd6252001dbc722e9e087131e3eb8abc8561dce031d323a5a649b228233e6ebb7b39ceb04e9966c27701fd779aa6e3056c223331b1353175da1ac9715e0e28e5
7
+ data.tar.gz: 79e8891907659df3e858cad810b30e209139c1e9c1de0dee5834598ab2f4fd2e89a90aad17600bad8f8f084fd9273b8e89f97879a2660ce9787783ee013203ac
@@ -25,7 +25,7 @@ jobs:
25
25
 
26
26
  steps:
27
27
  - name: Checkout
28
- uses: actions/checkout@v2
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.0.0
43
+ uses: paambaati/codeclimate-action@v3.2.0
44
44
  env:
45
45
  CC_TEST_REPORTER_ID: d1116c05a48e27785cb11369bde3a5e7f9d9e5a114d294bcbefa19cd193b029c
@@ -38,7 +38,7 @@ jobs:
38
38
 
39
39
  steps:
40
40
  - name: Checkout repository
41
- uses: actions/checkout@v2
41
+ uses: actions/checkout@v3
42
42
 
43
43
  # Initializes the CodeQL tools for scanning.
44
44
  - name: Initialize CodeQL
data/.rubocop.yml CHANGED
@@ -65,8 +65,14 @@ Metrics/BlockLength:
65
65
  RSpec/MultipleExpectations:
66
66
  Max: 13
67
67
 
68
- RSpec/NestedGroups:
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.9
1
+ 2.7.6
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.6.9
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
- *Note:* You must have ngrok v2+ installed available in your `PATH`.
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
- config.force_ssl = true if NGROK_ENABLED
143
- config.hosts << '.ngrok.io' if NGROK_ENABLED # for Rails >= 6.0.0
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',
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ngrok
4
4
  class Wrapper
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
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
- OPTIONAL_PARAMS = %i[authtoken bind_tls host_header hostname inspect region subdomain].freeze
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?('ngrok http -log') && !line.start_with?(pid || '') && line.end_with?(addr.to_s)
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?('ngrok http -log') && line.start_with?(pid) && !line.end_with?(addr.to_s)
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?('ngrok http -log') && line.start_with?(pid) && line.end_with?(addr.to_s)
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?('ngrok http -log') && line.end_with?(addr.to_s) }.split[0]
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 = +'-log=stdout -log-level=debug '
156
- OPTIONAL_PARAMS.each do |opt|
157
- exec_params << "-#{opt.to_s.tr('_', '-')}=#{@params[opt]} " if @params.key?(opt)
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 << "-config #{@params[:config]} #{@params[:addr]} > #{@params[:log].path}"
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
@@ -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
- before do
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
- it 'is not running' do
22
- expect(Ngrok::Wrapper.running?).to be false
23
- end
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
- it 'has :stopped status' do
30
- expect(Ngrok::Wrapper.status).to eq :stopped
31
- end
32
- end
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
- describe 'After start' do
35
- before do
36
- allow_any_instance_of(Tempfile).to receive(:read).and_return(log)
23
+ it 'has a version number' do
24
+ expect(Ngrok::Wrapper::VERSION).not_to be nil
25
+ end
37
26
 
38
- Ngrok::Wrapper.start
39
- end
27
+ describe 'Before start' do
28
+ before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
40
29
 
41
- after { Ngrok::Wrapper.stop }
30
+ it 'is not running' do
31
+ expect(Ngrok::Wrapper.running?).to be false
32
+ end
42
33
 
43
- it 'is running' do
44
- expect(Ngrok::Wrapper.running?).to be true
45
- end
34
+ it 'is stopped' do
35
+ expect(Ngrok::Wrapper.stopped?).to be true
36
+ end
46
37
 
47
- it 'is not stopped' do
48
- expect(Ngrok::Wrapper.stopped?).to be false
49
- end
38
+ it 'has :stopped status' do
39
+ expect(Ngrok::Wrapper.status).to eq :stopped
40
+ end
41
+ end
50
42
 
51
- it 'has :running status' do
52
- expect(Ngrok::Wrapper.status).to eq :running
53
- end
43
+ describe 'After start' do
44
+ before do
45
+ allow_any_instance_of(Tempfile).to receive(:read).and_return(log)
54
46
 
55
- it 'has correct port property' do
56
- expect(Ngrok::Wrapper.port).to eq(3001)
57
- end
47
+ Ngrok::Wrapper.start
48
+ end
58
49
 
59
- it 'has correct addr property' do
60
- expect(Ngrok::Wrapper.addr).to eq(3001)
61
- end
50
+ after { Ngrok::Wrapper.stop }
62
51
 
63
- it 'has valid ngrok_url' do
64
- expect(Ngrok::Wrapper.ngrok_url).to be =~ %r{http://.*ngrok\.io$}
65
- end
52
+ it 'is running' do
53
+ expect(Ngrok::Wrapper.running?).to be true
54
+ end
66
55
 
67
- it 'has valid ngrok_url_https' do
68
- expect(Ngrok::Wrapper.ngrok_url_https).to be =~ %r{https://.*ngrok\.io$}
69
- end
56
+ it 'is not stopped' do
57
+ expect(Ngrok::Wrapper.stopped?).to be false
58
+ end
70
59
 
71
- it 'has correct pid property' do
72
- expect(Ngrok::Wrapper.pid).to be > 0
73
- end
74
- end
60
+ it 'has :running status' do
61
+ expect(Ngrok::Wrapper.status).to eq :running
62
+ end
75
63
 
76
- describe 'Custom log file' do
77
- before { allow_any_instance_of(File).to receive(:read).and_return(log) }
64
+ it 'has correct port property' do
65
+ expect(Ngrok::Wrapper.port).to eq(3001)
66
+ end
78
67
 
79
- it 'uses custom log file' do
80
- Ngrok::Wrapper.start(log: 'test.log')
81
- expect(Ngrok::Wrapper.running?).to eq true
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
- describe 'Invalid or missing authtoken' do
89
- describe 'when no authtoken is specified in ngrok config file' do
90
- let(:no_auth_log) { File.read("#{RSPEC_ROOT}/fixtures/ngrok.no_auth_token.log") }
72
+ it 'has valid ngrok_url' do
73
+ expect(Ngrok::Wrapper.ngrok_url).to be =~ %r{http://.*ngrok\.io$}
74
+ end
91
75
 
92
- it 'raises Ngrok::Error exception' do
93
- allow_any_instance_of(Tempfile).to receive(:read).and_return(no_auth_log)
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
- expect { Ngrok::Wrapper.start }.to raise_error Ngrok::Error
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
- it 'fails with incorrect authtoken' do
103
- allow_any_instance_of(Tempfile).to receive(:read).and_return(invalid_auth_log)
85
+ describe 'Custom log file' do
86
+ before { allow_any_instance_of(File).to receive(:read).and_return(log) }
104
87
 
105
- expect do
106
- Ngrok::Wrapper.start(authtoken: 'incorrect_token')
107
- end.to raise_error Ngrok::Error
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
- describe 'Custom addr' do
113
- before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
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
- it 'maps port param to addr' do
116
- port = 10_010
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
- it 'returns just the port when the address contains a host' do
123
- addr = '192.168.0.5:10010'
124
- Ngrok::Wrapper.start(addr: addr)
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
- it 'supports remote addresses' do
130
- addr = '192.168.0.5:10010'
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
- describe 'Custom region' do
138
- before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
111
+ it 'fails with incorrect authtoken' do
112
+ allow_any_instance_of(Tempfile).to receive(:read).and_return(invalid_auth_log)
139
113
 
140
- it "doesn't include the -region parameter when it is not provided" do
141
- Ngrok::Wrapper.start
142
- expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-region=')
143
- Ngrok::Wrapper.stop
144
- end
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
- it 'includes the -region parameter with the correct value when it is provided' do
147
- region = 'eu'
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
- describe 'Custom bind-tls' do
155
- before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
124
+ after { Ngrok::Wrapper.stop }
156
125
 
157
- it "doesn't include the -bind-tls parameter when it is not provided" do
158
- Ngrok::Wrapper.start
159
- expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-bind-tls=')
160
- Ngrok::Wrapper.stop
161
- end
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
- it 'includes the -bind-tls parameter with the correct value when it is true' do
164
- bind_tls = true
165
- Ngrok::Wrapper.start(bind_tls: bind_tls)
166
- expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-bind-tls=#{bind_tls}")
167
- Ngrok::Wrapper.stop
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
- it 'includes the -bind-tls parameter with the correct value when it is false' do
171
- bind_tls = false
172
- Ngrok::Wrapper.start(bind_tls: bind_tls)
173
- expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).to include("-bind-tls=#{bind_tls}")
174
- Ngrok::Wrapper.stop
175
- end
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
- describe 'Custom host header' do
179
- after { Ngrok::Wrapper.stop }
145
+ describe 'Custom region' do
146
+ before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
180
147
 
181
- it "doesn't include the -host-header parameter when it is not provided" do
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
- it 'includes the -host-header parameter with the correct value when it is provided' do
188
- expect(Ngrok::Wrapper).to receive(:fetch_urls)
189
- host_header = 'foo.bar'
190
- Ngrok::Wrapper.start(host_header: host_header)
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
- describe 'Custom parameters provided' do
196
- before { allow_any_instance_of(Tempfile).to receive(:read).and_return(log) }
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
- it "doesn't include the -inspect parameter when it is not provided" do
199
- Ngrok::Wrapper.start
200
- expect(Ngrok::Wrapper.__send__(:ngrok_exec_params)).not_to include('-inspect=')
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
- it 'includes the -inspect parameter with the correct value when it is provided' do
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
- Ngrok::Wrapper.start(inspect: false)
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
- describe '#start' do
216
- after { Ngrok::Wrapper.stop }
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
- describe 'when persistence param is true' do
219
- before do
220
- allow(File).to receive(:write)
221
- allow(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok).and_call_original
222
- allow(Ngrok::Wrapper).to receive(:parse_persistence_file).and_return(state)
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
- describe 'tries fetching params of an already running Ngrok and store Ngrok process data into a file' do
226
- describe 'when fetching params returns nil' do
227
- let(:state) { nil }
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
- it "doesn't check for similar ngroks running" do
230
- expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
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
- Ngrok::Wrapper.start(persistence: true)
237
- end
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
- describe 'when fetching params returns a legit hash' do
241
- let(:state) do
242
- { 'pid' => '795',
243
- 'ngrok_url' => 'http://b1cd-109-185-141-9.ngrok.io',
244
- 'ngrok_url_https' => 'https://b1cd-109-185-141-9.ngrok.io' }
245
- end
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
- describe 'checking if a similar Ngrok is running' do
248
- before do
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
- expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
253
- end
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
- describe 'when Ngrok process with params from the persisted file is running' do
256
- let(:ngrok_ps_lines) do
257
- ['795 ?? S 0:04.81 ngrok http -log -config /Users/thunder/.ngrok2/ngrok.yml https://localhost:3001']
258
- end
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
- it 'set Ngrok::Wrapper pid and status attributes' do
261
- expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
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
- result = Ngrok::Wrapper.start(persistence: true)
226
+ describe '#start' do
227
+ after { Ngrok::Wrapper.stop }
264
228
 
265
- expect(Ngrok::Wrapper.pid).to eql('795')
266
- expect(Ngrok::Wrapper.status).to eql(:running)
267
- expect(Ngrok::Wrapper.ngrok_url).to eql('http://b1cd-109-185-141-9.ngrok.io')
268
- expect(Ngrok::Wrapper.ngrok_url_https).to eql('https://b1cd-109-185-141-9.ngrok.io')
269
- expect(result).to eql('https://b1cd-109-185-141-9.ngrok.io')
270
- end
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
- describe 'when a similar Ngrok with other pid is already running' do
274
- let(:ngrok_ps_lines) do
275
- ['71986 ?? S 0:04.81 ngrok http -log -config /Users/thunder/.ngrok2/ngrok.yml https://localhost:3001']
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 'raises exception' do
279
- expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
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
- expect { Ngrok::Wrapper.start(persistence: true) }
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 Ngrok with the persisted pid is already running, but on a different port' do
251
+ describe 'when fetching params returns a legit hash' do
287
252
  let(:ngrok_ps_lines) do
288
- ['795 ?? S 0:04.81 ngrok http -log -config /Users/thunder/.ngrok2/ngrok.yml https://localhost:3000']
253
+ ["795 ?? S 0:04.81 ngrok http #{flag_prefix}log -config #{config_path} https://localhost:3001"]
289
254
  end
290
255
 
291
- it 'raises exception' do
292
- expect(Ngrok::Wrapper).not_to receive(:spawn_new_ngrok)
293
-
294
- expect { Ngrok::Wrapper.start(persistence: true) }
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
- let(:new_ngrok_ps_lines) do
305
- ['835 ?? S 0:04.81 ngrok http -log -config /Users/thunder/.ngrok2/ngrok.yml https://localhost:3001']
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 'sets Ngrok::Wrapper pid and status attributes' do
309
- allow(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true).and_call_original
310
- allow(Ngrok::Wrapper).to receive(:fork).and_call_original
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 'tries fetching params of an already running Ngrok and store Ngrok process data into a file' do
329
- expect(Ngrok::Wrapper).to receive(:try_params_from_running_ngrok)
330
- expect(Ngrok::Wrapper).to receive(:spawn_new_ngrok).with(persistent_ngrok: true)
331
- expect(File).to receive(:write)
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: true)
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.start(persistence: false)
346
- end
347
- end
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
- describe 'when Ngrok::Wrapper is already running' do
350
- it "doesn't try to spawn a new Ngrok process" do
351
- allow(Ngrok::Wrapper).to receive(:stopped?).and_return(false)
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.2.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-02-19 00:00:00.000000000 Z
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.0.3.1
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