miniproxy 0.4.0 → 0.5.0
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/lib/miniproxy.rb +4 -0
- data/lib/miniproxy/fake_ssl_server.rb +1 -3
- data/lib/miniproxy/proxy_server.rb +1 -3
- data/lib/miniproxy/remote.rb +17 -4
- data/lib/miniproxy/stub/request.rb +7 -2
- data/lib/miniproxy/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6875d6201b9252532b5cd9fac07495eff9ac447485aa9160c47af987d963066e
|
4
|
+
data.tar.gz: '09fcb65924875d32764ad9c8ce272b98ade611f1b77e6cfb3b33f2c67f219f97'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a5c51efa29c16d0aa224ccea3eb51ed69a333ce29e1d6f20e68955a766f820444d619950e0ff44972c7b7f991849ca7b93ab080d142892c7b072e4b735d2784
|
7
|
+
data.tar.gz: 97ffb024d267b00ea822bcf21cc7c92530fbe8e5435d895f898eae1f60e694f4c449e7959f5f518fe6db4a1adbb266591820adce4a0901ce58bac7eb4ba58cab
|
data/lib/miniproxy.rb
CHANGED
@@ -37,6 +37,10 @@ module MiniProxy
|
|
37
37
|
remote.stub_request(method: method, url: url, response: response)
|
38
38
|
end
|
39
39
|
|
40
|
+
def self.allow_request(method:, url:)
|
41
|
+
remote.allow_request(method: method, url: url)
|
42
|
+
end
|
43
|
+
|
40
44
|
private_class_method def self.remote
|
41
45
|
Timeout.timeout(DRB_SERVICE_TIMEOUT) do
|
42
46
|
begin
|
@@ -6,8 +6,6 @@ module MiniProxy
|
|
6
6
|
#
|
7
7
|
class FakeSSLServer < WEBrick::HTTPServer
|
8
8
|
def initialize(config = {}, default = WEBrick::Config::HTTP)
|
9
|
-
@allowed_hosts = ["127.0.0.1", "localhost", config[:MiniProxyHost]].compact
|
10
|
-
|
11
9
|
config = config.merge({
|
12
10
|
Logger: WEBrick::Log.new(nil, 0), # silence logging
|
13
11
|
AccessLog: [], # silence logging
|
@@ -21,7 +19,7 @@ module MiniProxy
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def service(req, res)
|
24
|
-
if
|
22
|
+
if self.config[:AllowedRequestCheck].call(req)
|
25
23
|
super(req, res)
|
26
24
|
else
|
27
25
|
self.config[:MockHandlerCallback].call(req, res)
|
@@ -7,8 +7,6 @@ module MiniProxy
|
|
7
7
|
attr_accessor :requests
|
8
8
|
|
9
9
|
def initialize(config = {}, default = WEBrick::Config::HTTP)
|
10
|
-
@allowed_hosts = ["127.0.0.1", "localhost", config[:MiniProxyHost]].compact
|
11
|
-
|
12
10
|
config = config.merge({
|
13
11
|
Logger: WEBrick::Log.new(nil, 0), # silence logging
|
14
12
|
AccessLog: [], # silence logging
|
@@ -36,7 +34,7 @@ module MiniProxy
|
|
36
34
|
end
|
37
35
|
|
38
36
|
def service(req, res)
|
39
|
-
if
|
37
|
+
if self.config[:AllowedRequestCheck].call(req)
|
40
38
|
super(req, res)
|
41
39
|
else
|
42
40
|
if req.request_method == "CONNECT"
|
data/lib/miniproxy/remote.rb
CHANGED
@@ -31,13 +31,13 @@ module MiniProxy
|
|
31
31
|
return @unix_socket_uri if drb_process_alive?
|
32
32
|
|
33
33
|
@pid = fork do
|
34
|
-
remote = Remote.new
|
34
|
+
remote = Remote.new(host)
|
35
35
|
|
36
36
|
Timeout.timeout(SERVER_START_TIMEOUT) do
|
37
37
|
begin
|
38
38
|
fake_server_port = SERVER_DYNAMIC_PORT_RANGE.sample
|
39
39
|
fake_server = FakeSSLServer.new(
|
40
|
-
|
40
|
+
AllowedRequestCheck: remote.method(:allowed_request?),
|
41
41
|
Port: fake_server_port,
|
42
42
|
MockHandlerCallback: remote.method(:handler),
|
43
43
|
)
|
@@ -49,7 +49,7 @@ module MiniProxy
|
|
49
49
|
begin
|
50
50
|
remote.port = ENV["MINI_PROXY_PORT"] || SERVER_DYNAMIC_PORT_RANGE.sample
|
51
51
|
proxy = MiniProxy::ProxyServer.new(
|
52
|
-
|
52
|
+
AllowedRequestCheck: remote.method(:allowed_request?),
|
53
53
|
Port: remote.port,
|
54
54
|
FakeServerPort: fake_server_port,
|
55
55
|
MockHandlerCallback: remote.method(:handler),
|
@@ -90,6 +90,16 @@ module MiniProxy
|
|
90
90
|
@stubs.push(request)
|
91
91
|
end
|
92
92
|
|
93
|
+
def allow_request(method:, url:)
|
94
|
+
@allowed_requests.push(MiniProxy::Stub::Request.new(method: method, url: url, response: nil))
|
95
|
+
end
|
96
|
+
|
97
|
+
def allowed_request?(req)
|
98
|
+
return true if ["127.0.0.1", "localhost", @host].include?(req.host)
|
99
|
+
|
100
|
+
@allowed_requests.any? { |allowed_request| allowed_request.match?(req) }
|
101
|
+
end
|
102
|
+
|
93
103
|
def port
|
94
104
|
@port
|
95
105
|
end
|
@@ -104,6 +114,7 @@ module MiniProxy
|
|
104
114
|
|
105
115
|
def clear
|
106
116
|
@stubs.clear
|
117
|
+
@allowed_requests.clear
|
107
118
|
end
|
108
119
|
|
109
120
|
def drain_messages
|
@@ -121,9 +132,11 @@ module MiniProxy
|
|
121
132
|
@messages.push msg
|
122
133
|
end
|
123
134
|
|
124
|
-
def initialize
|
135
|
+
def initialize(host)
|
136
|
+
@host = host
|
125
137
|
@stubs = []
|
126
138
|
@messages = []
|
139
|
+
@allowed_requests = []
|
127
140
|
end
|
128
141
|
end
|
129
142
|
end
|
@@ -16,8 +16,13 @@ module MiniProxy
|
|
16
16
|
|
17
17
|
# @param [WEBrick::HTTPRequest] http_request
|
18
18
|
def match?(http_request)
|
19
|
-
|
20
|
-
|
19
|
+
if http_request.request_method == "CONNECT"
|
20
|
+
host = http_request.unparsed_uri.split(":").first
|
21
|
+
@url.match?(host)
|
22
|
+
else
|
23
|
+
request_uri = http_request.host + http_request.path
|
24
|
+
http_request.request_method == @method && request_uri.match?(@url)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
data/lib/miniproxy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miniproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- The Conversation Dev Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -87,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
|
91
|
-
rubygems_version: 2.7.7
|
90
|
+
rubygems_version: 3.1.2
|
92
91
|
signing_key:
|
93
92
|
specification_version: 4
|
94
93
|
summary: Easily stub external requests for your browser tests.
|