ngrok-wrapper 0.2.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +5 -8
- data/.github/workflows/codeql-analysis.yml +1 -1
- data/.gitignore +1 -0
- data/.rubocop.yml +9 -2
- data/.tool-versions +1 -1
- data/CHANGELOG.md +41 -1
- data/Gemfile +7 -0
- data/README.md +20 -14
- data/disabled.yml +3 -0
- data/lib/ngrok/wrapper/version.rb +1 -1
- data/lib/ngrok/wrapper.rb +24 -12
- data/ngrok-wrapper.gemspec +1 -9
- data/spec/ngrok/wrapper_spec.rb +286 -271
- data/tea.yaml +6 -0
- metadata +7 -96
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 87e9c41fe2c57a9412ff8d75fb5950cc24623778c3b1d5e9a3969fe4c07899e4
|
|
4
|
+
data.tar.gz: cddba38da8b0e540b52534fbd591233a5941b2dcdaf130075215f29a4eb87437
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1195f3f59babf99244efbb65ba5c1a2ff6e39cd990dcf5472db1bd8eadd1b326161a93a1dafc0fed02e0d544400902ed01ace3bf52bcbedd2bcf4eae1a6eab6a
|
|
7
|
+
data.tar.gz: 66f62592b48a9537d6eeea87661c5a93b076ab03ed4097e726deb3cfa7245e9ef25382e241dccab50e00c31000c3d391da05b7858364440f99437f4a0a7a4ed4
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -13,19 +13,16 @@ jobs:
|
|
|
13
13
|
fail-fast: false
|
|
14
14
|
matrix:
|
|
15
15
|
include:
|
|
16
|
-
- ruby: 2.6
|
|
17
|
-
|
|
18
|
-
- ruby: 2.7
|
|
19
|
-
|
|
20
|
-
- ruby: 3.0
|
|
21
|
-
|
|
22
16
|
- ruby: 3.1
|
|
17
|
+
- ruby: 3.2
|
|
18
|
+
- ruby: 3.3
|
|
19
|
+
- ruby: head
|
|
23
20
|
|
|
24
21
|
name: ruby ${{ matrix.ruby }}
|
|
25
22
|
|
|
26
23
|
steps:
|
|
27
24
|
- name: Checkout
|
|
28
|
-
uses: actions/checkout@
|
|
25
|
+
uses: actions/checkout@v4
|
|
29
26
|
|
|
30
27
|
- name: Set up Ruby
|
|
31
28
|
uses: ruby/setup-ruby@v1
|
|
@@ -40,6 +37,6 @@ jobs:
|
|
|
40
37
|
run: bundle exec rspec
|
|
41
38
|
|
|
42
39
|
- name: Code Climate
|
|
43
|
-
uses: paambaati/codeclimate-action@
|
|
40
|
+
uses: paambaati/codeclimate-action@v9
|
|
44
41
|
env:
|
|
45
42
|
CC_TEST_REPORTER_ID: d1116c05a48e27785cb11369bde3a5e7f9d9e5a114d294bcbefa19cd193b029c
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require:
|
|
5
5
|
- rubocop-performance
|
|
6
|
+
- rubocop-rake
|
|
6
7
|
- rubocop-rspec
|
|
7
8
|
|
|
8
9
|
inherit_from:
|
|
@@ -24,7 +25,7 @@ AllCops:
|
|
|
24
25
|
# Additional cops that do not reference a style guide rule may be enabled by
|
|
25
26
|
# default. Change behavior by overriding StyleGuideCopsOnly, or by giving
|
|
26
27
|
# the --only-guide-cops option.
|
|
27
|
-
TargetRubyVersion:
|
|
28
|
+
TargetRubyVersion: 3.1
|
|
28
29
|
|
|
29
30
|
Layout/LineLength:
|
|
30
31
|
Max: 120
|
|
@@ -65,8 +66,14 @@ Metrics/BlockLength:
|
|
|
65
66
|
RSpec/MultipleExpectations:
|
|
66
67
|
Max: 13
|
|
67
68
|
|
|
68
|
-
RSpec/
|
|
69
|
+
RSpec/MultipleMemoizedHelpers:
|
|
70
|
+
Description: Checks if example groups contain too many `let` and `subject` calls.
|
|
71
|
+
Enabled: true
|
|
72
|
+
AllowSubject: true
|
|
69
73
|
Max: 7
|
|
70
74
|
|
|
75
|
+
RSpec/NestedGroups:
|
|
76
|
+
Max: 8
|
|
77
|
+
|
|
71
78
|
Style/StringLiterals:
|
|
72
79
|
ConsistentQuotesInMultiline: true
|
data/.tool-versions
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby
|
|
1
|
+
ruby 3.3.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.3.1](https://github.com/texpert/ngrok-wrapper/tree/v0.3.1) (2024-08-25)
|
|
4
|
+
|
|
5
|
+
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.3.0...v0.3.1)
|
|
6
|
+
|
|
7
|
+
### Maintenance release
|
|
8
|
+
|
|
9
|
+
Ruby, Rubocop, and CI upgrades
|
|
10
|
+
|
|
11
|
+
**Closed issues:**
|
|
12
|
+
|
|
13
|
+
- Config error with Ngrok v3.3.3 [\#31](https://github.com/texpert/ngrok-wrapper/issues/31)
|
|
14
|
+
- The ngrok agent \(v3\) only accepts long name flags prefixed with -- and will error if a single hyphen is used [\#20](https://github.com/texpert/ngrok-wrapper/issues/20)
|
|
15
|
+
|
|
16
|
+
**Merged pull requests:**
|
|
17
|
+
|
|
18
|
+
- Upgrade paambaati/codeclimate-action to version 9 [\#34](https://github.com/texpert/ngrok-wrapper/pull/34) ([texpert](https://github.com/texpert))
|
|
19
|
+
- Upgrade actions/checkout to version 4 [\#33](https://github.com/texpert/ngrok-wrapper/pull/33) ([texpert](https://github.com/texpert))
|
|
20
|
+
- Restrict Ruby minimal version to 3.1 [\#32](https://github.com/texpert/ngrok-wrapper/pull/32) ([texpert](https://github.com/texpert))
|
|
21
|
+
- Bump actions/checkout to 3.5.0 [\#30](https://github.com/texpert/ngrok-wrapper/pull/30) ([texpert](https://github.com/texpert))
|
|
22
|
+
- Bump actions/checkout to 3.3.0 [\#29](https://github.com/texpert/ngrok-wrapper/pull/29) ([texpert](https://github.com/texpert))
|
|
23
|
+
- Bump main Ruby version to 2.7.7 [\#28](https://github.com/texpert/ngrok-wrapper/pull/28) ([texpert](https://github.com/texpert))
|
|
24
|
+
- Fix Code Climate issues [\#27](https://github.com/texpert/ngrok-wrapper/pull/27) ([texpert](https://github.com/texpert))
|
|
25
|
+
|
|
26
|
+
## [v0.3.0](https://github.com/texpert/ngrok-wrapper/tree/v0.3.0) (2022-11-19)
|
|
27
|
+
|
|
28
|
+
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.2.0...v0.3.0)
|
|
29
|
+
|
|
30
|
+
### Both Ngrok v2, and v3 are now supported.
|
|
31
|
+
|
|
32
|
+
Tested and working on Ubuntu Linux and macOS.
|
|
33
|
+
|
|
34
|
+
**Merged pull requests:**
|
|
35
|
+
|
|
36
|
+
- 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))
|
|
37
|
+
- Prepare for different ngrok versions params, still for version 2 [\#23](https://github.com/texpert/ngrok-wrapper/pull/23) ([texpert](https://github.com/texpert))
|
|
38
|
+
- 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))
|
|
39
|
+
- Set main Ruby version to 2.7.6 [\#21](https://github.com/texpert/ngrok-wrapper/pull/21) ([texpert](https://github.com/texpert))
|
|
40
|
+
- Bump actions/checkout from 2 to 3 [\#19](https://github.com/texpert/ngrok-wrapper/pull/19) ([texpert](https://github.com/texpert))
|
|
41
|
+
|
|
3
42
|
## [v0.2.0](https://github.com/texpert/ngrok-wrapper/tree/v0.2.0) (2022-02-19)
|
|
4
43
|
|
|
44
|
+
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.1.0...v0.2.0)
|
|
45
|
+
|
|
5
46
|
### Making Ngrok process survive server stop on Linux
|
|
6
47
|
|
|
7
48
|
It was working OK on Mac OS on the 0.1.0 release, but not on Linux.
|
|
@@ -10,7 +51,6 @@ It came out that `Process.setsid` should be applied to the spawned process to es
|
|
|
10
51
|
and process group leader. This is completely detaching it from the parent process, so it won't be killed when the
|
|
11
52
|
parent will go down.
|
|
12
53
|
|
|
13
|
-
[Full Changelog](https://github.com/texpert/ngrok-wrapper/compare/v0.1.0...v0.2.0)
|
|
14
54
|
|
|
15
55
|
**Merged pull requests:**
|
|
16
56
|
|
data/Gemfile
CHANGED
|
@@ -5,4 +5,11 @@ source 'https://rubygems.org'
|
|
|
5
5
|
# Specify your gem's dependencies in ngrok-wrapper.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
+
gem 'github_changelog_generator', git: 'https://github.com/github-changelog-generator/github-changelog-generator'
|
|
9
|
+
gem 'rake'
|
|
10
|
+
gem 'rspec'
|
|
11
|
+
gem 'rubocop'
|
|
12
|
+
gem 'rubocop-performance'
|
|
13
|
+
gem 'rubocop-rake'
|
|
14
|
+
gem 'rubocop-rspec'
|
|
8
15
|
gem 'simplecov', require: false, group: :test
|
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
|
[](https://codeclimate.com/github/texpert/ngrok-wrapper/maintainability)
|
|
6
6
|
[](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
|
|
|
@@ -48,32 +50,32 @@ Ngrok::Wrapper.start
|
|
|
48
50
|
|
|
49
51
|
# ngrok local_port
|
|
50
52
|
Ngrok::Wrapper.port
|
|
51
|
-
=> 3001
|
|
53
|
+
# => 3001
|
|
52
54
|
|
|
53
55
|
# ngrok external url
|
|
54
56
|
Ngrok::Wrapper.ngrok_url
|
|
55
|
-
=> "http://aaa0e65.ngrok.io"
|
|
57
|
+
# => "http://aaa0e65.ngrok.io"
|
|
56
58
|
|
|
57
59
|
Ngrok::Wrapper.ngrok_url_https
|
|
58
|
-
=> "https://aaa0e65.ngrok.io"
|
|
60
|
+
# => "https://aaa0e65.ngrok.io"
|
|
59
61
|
|
|
60
62
|
Ngrok::Wrapper.running?
|
|
61
|
-
=> true
|
|
63
|
+
# => true
|
|
62
64
|
|
|
63
65
|
Ngrok::Wrapper.stopped?
|
|
64
|
-
=> false
|
|
66
|
+
# => false
|
|
65
67
|
|
|
66
68
|
# ngrok process id
|
|
67
69
|
Ngrok::Wrapper.pid
|
|
68
|
-
=> 27384
|
|
70
|
+
# => 27384
|
|
69
71
|
|
|
70
72
|
# ngrok log file descriptor
|
|
71
73
|
Ngrok::Wrapper.log
|
|
72
|
-
=> #<File:/tmp/ngrok20141022-27376-cmmiq4>
|
|
74
|
+
# => #<File:/tmp/ngrok20141022-27376-cmmiq4>
|
|
73
75
|
|
|
74
76
|
# kill ngrok
|
|
75
77
|
Ngrok::Wrapper.stop
|
|
76
|
-
=> :stopped
|
|
78
|
+
# => :stopped
|
|
77
79
|
|
|
78
80
|
```
|
|
79
81
|
|
|
@@ -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',
|
|
@@ -196,6 +200,7 @@ git pull
|
|
|
196
200
|
|
|
197
201
|
github_changelog_generator -u texpert -p ngrok-wrapper --future-release v0.1.0
|
|
198
202
|
```
|
|
203
|
+
Adjust the new gem version number in the `lib/ngrok/wrapper/version.rb` file.
|
|
199
204
|
|
|
200
205
|
Then add the changes to `git`, commit and push the `Preparing the new release` commit directly into the `main` branch:
|
|
201
206
|
|
|
@@ -217,7 +222,8 @@ gem owner ngrok-wrapper -a branzeanu.aurel@gmail.com
|
|
|
217
222
|
|
|
218
223
|
### Building a new gem version
|
|
219
224
|
|
|
220
|
-
|
|
225
|
+
Check if the new gem version number in the `lib/ngrok/wrapper/version.rb` file has been specified.
|
|
226
|
+
It is used when building the gem by the following command:
|
|
221
227
|
|
|
222
228
|
```
|
|
223
229
|
gem build ngrok-wrapper.gemspec
|
data/disabled.yml
CHANGED
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,13 +33,16 @@ 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
|
|
30
42
|
# Attempt to read the attributes of an existing process instead of starting a new process.
|
|
31
43
|
try_params_from_running_ngrok if persistent_ngrok
|
|
32
44
|
|
|
33
|
-
spawn_new_ngrok(persistent_ngrok:
|
|
45
|
+
spawn_new_ngrok(persistent_ngrok:) if stopped?
|
|
34
46
|
|
|
35
47
|
@status = :running
|
|
36
48
|
if persistent_ngrok
|
|
@@ -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
|
|
@@ -104,7 +116,7 @@ module Ngrok
|
|
|
104
116
|
def ngrok_process_status_lines(refetch: false)
|
|
105
117
|
return @ngrok_process_status_lines if defined?(@ngrok_process_status_lines) && !refetch
|
|
106
118
|
|
|
107
|
-
@ngrok_process_status_lines =
|
|
119
|
+
@ngrok_process_status_lines = `ps ax | grep "ngrok http"`.split("\n").map(&:strip)
|
|
108
120
|
end
|
|
109
121
|
|
|
110
122
|
def try_params_from_running_ngrok
|
|
@@ -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/ngrok-wrapper.gemspec
CHANGED
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.summary = 'Ngrok-wrapper gem is a ruby wrapper for ngrok2'
|
|
15
15
|
spec.description = 'Ngrok-wrapper gem is a ruby wrapper for ngrok2'
|
|
16
16
|
spec.homepage = 'https://github.com/texpert/ngrok-wrapper'
|
|
17
|
-
spec.required_ruby_version = '>=
|
|
17
|
+
spec.required_ruby_version = '>= 3.1.0'
|
|
18
18
|
spec.license = 'MIT'
|
|
19
19
|
|
|
20
20
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
@@ -25,13 +25,5 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
# Specify which files should be added to the gem when it is released.
|
|
26
26
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
27
27
|
spec.files = `git ls-files -z`.split("\x0")
|
|
28
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
29
28
|
spec.require_paths = ['lib']
|
|
30
|
-
|
|
31
|
-
spec.add_development_dependency 'github_changelog_generator'
|
|
32
|
-
spec.add_development_dependency 'rake'
|
|
33
|
-
spec.add_development_dependency 'rspec'
|
|
34
|
-
spec.add_development_dependency 'rubocop'
|
|
35
|
-
spec.add_development_dependency 'rubocop-performance'
|
|
36
|
-
spec.add_development_dependency 'rubocop-rspec'
|
|
37
29
|
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 be_truthy
|
|
91
|
+
expect(Ngrok::Wrapper.params[:log].path).to eq 'test.log'
|
|
92
|
+
Ngrok::Wrapper.stop
|
|
93
|
+
expect(Ngrok::Wrapper.stopped?).to be_truthy
|
|
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:)
|
|
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:)
|
|
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:)
|
|
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:)
|
|
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:)
|
|
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
|
data/tea.yaml
ADDED
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.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Bogdanovich
|
|
@@ -9,92 +9,8 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
13
|
-
dependencies:
|
|
14
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
-
name: github_changelog_generator
|
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
requirements:
|
|
18
|
-
- - ">="
|
|
19
|
-
- !ruby/object:Gem::Version
|
|
20
|
-
version: '0'
|
|
21
|
-
type: :development
|
|
22
|
-
prerelease: false
|
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
-
requirements:
|
|
25
|
-
- - ">="
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
version: '0'
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: rake
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0'
|
|
35
|
-
type: :development
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0'
|
|
42
|
-
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: rspec
|
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
|
45
|
-
requirements:
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0'
|
|
49
|
-
type: :development
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - ">="
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: '0'
|
|
56
|
-
- !ruby/object:Gem::Dependency
|
|
57
|
-
name: rubocop
|
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
|
59
|
-
requirements:
|
|
60
|
-
- - ">="
|
|
61
|
-
- !ruby/object:Gem::Version
|
|
62
|
-
version: '0'
|
|
63
|
-
type: :development
|
|
64
|
-
prerelease: false
|
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
-
requirements:
|
|
67
|
-
- - ">="
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version: '0'
|
|
70
|
-
- !ruby/object:Gem::Dependency
|
|
71
|
-
name: rubocop-performance
|
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
|
73
|
-
requirements:
|
|
74
|
-
- - ">="
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
version: '0'
|
|
77
|
-
type: :development
|
|
78
|
-
prerelease: false
|
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
-
requirements:
|
|
81
|
-
- - ">="
|
|
82
|
-
- !ruby/object:Gem::Version
|
|
83
|
-
version: '0'
|
|
84
|
-
- !ruby/object:Gem::Dependency
|
|
85
|
-
name: rubocop-rspec
|
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
|
87
|
-
requirements:
|
|
88
|
-
- - ">="
|
|
89
|
-
- !ruby/object:Gem::Version
|
|
90
|
-
version: '0'
|
|
91
|
-
type: :development
|
|
92
|
-
prerelease: false
|
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
-
requirements:
|
|
95
|
-
- - ">="
|
|
96
|
-
- !ruby/object:Gem::Version
|
|
97
|
-
version: '0'
|
|
12
|
+
date: 2024-08-25 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
98
14
|
description: Ngrok-wrapper gem is a ruby wrapper for ngrok2
|
|
99
15
|
email:
|
|
100
16
|
- 27bogdanovich@gmail.com
|
|
@@ -109,7 +25,6 @@ files:
|
|
|
109
25
|
- ".gitignore"
|
|
110
26
|
- ".rspec"
|
|
111
27
|
- ".rubocop.yml"
|
|
112
|
-
- ".ruby-version"
|
|
113
28
|
- ".simplecov"
|
|
114
29
|
- ".tool-versions"
|
|
115
30
|
- CHANGELOG.md
|
|
@@ -128,6 +43,7 @@ files:
|
|
|
128
43
|
- spec/fixtures/ngrok_invalid_auth_token.log
|
|
129
44
|
- spec/ngrok/wrapper_spec.rb
|
|
130
45
|
- spec/spec_helper.rb
|
|
46
|
+
- tea.yaml
|
|
131
47
|
homepage: https://github.com/texpert/ngrok-wrapper
|
|
132
48
|
licenses:
|
|
133
49
|
- MIT
|
|
@@ -144,20 +60,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
144
60
|
requirements:
|
|
145
61
|
- - ">="
|
|
146
62
|
- !ruby/object:Gem::Version
|
|
147
|
-
version:
|
|
63
|
+
version: 3.1.0
|
|
148
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
65
|
requirements:
|
|
150
66
|
- - ">="
|
|
151
67
|
- !ruby/object:Gem::Version
|
|
152
68
|
version: '0'
|
|
153
69
|
requirements: []
|
|
154
|
-
rubygems_version: 3.
|
|
70
|
+
rubygems_version: 3.5.11
|
|
155
71
|
signing_key:
|
|
156
72
|
specification_version: 4
|
|
157
73
|
summary: Ngrok-wrapper gem is a ruby wrapper for ngrok2
|
|
158
|
-
test_files:
|
|
159
|
-
- spec/fixtures/ngrok.no_auth_token.log
|
|
160
|
-
- spec/fixtures/ngrok.sample.log
|
|
161
|
-
- spec/fixtures/ngrok_invalid_auth_token.log
|
|
162
|
-
- spec/ngrok/wrapper_spec.rb
|
|
163
|
-
- spec/spec_helper.rb
|
|
74
|
+
test_files: []
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.6.9
|