proxy_rb 0.10.4 → 0.10.5
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/History.md +6 -0
- data/README.md +4 -0
- data/cucumber.yml +2 -2
- data/lib/proxy_rb/announcer.rb +1 -0
- data/lib/proxy_rb/api/http_proxy.rb +5 -1
- data/lib/proxy_rb/cucumber/hooks.rb +4 -14
- data/lib/proxy_rb/cucumber/steps.rb +3 -1
- data/lib/proxy_rb/http_proxy.rb +8 -0
- data/lib/proxy_rb/main.rb +10 -0
- data/lib/proxy_rb/matchers/be_forbidden.rb +22 -3
- data/lib/proxy_rb/matchers/be_successful.rb +23 -3
- data/lib/proxy_rb/matchers/have_mime_type.rb +28 -0
- data/lib/proxy_rb/proxy_url.rb +2 -0
- data/lib/proxy_rb/rspec.rb +3 -14
- data/lib/proxy_rb/setup.rb +1 -0
- data/lib/proxy_rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6abcc8dc4e92962539f30a1449feae10f6c8940
|
4
|
+
data.tar.gz: 184e4d8e2206de5d44e86eee437fece58df3f02a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9096dd8f7b0373e477354e4cfaa22621a2775fe247dba45650b06b8a8e80bed93bb2da0965f7854b90af086851ce2af8fa6d83969ff503f2f6e0b07ff8209e3b
|
7
|
+
data.tar.gz: a4b629292fcaa35f0bbf0942ab5f42729e41b669a141b720b2e0bd10eb1e351dd46ef12ac3c1bdb299fd415d200f0599d34d56d1cd35585c6369204dbf520661
|
data/History.md
CHANGED
@@ -4,6 +4,12 @@ Empty
|
|
4
4
|
|
5
5
|
# RELEASED
|
6
6
|
|
7
|
+
## [v0.10.5](https://github.com/fedux-org/proxy_rb/compare/v0.10.5...v0.10.5)
|
8
|
+
|
9
|
+
* Fix for overwriting proxies
|
10
|
+
* Better error messages for matchers
|
11
|
+
* Added new announcer for http status code
|
12
|
+
|
7
13
|
## [v0.10.4](https://github.com/fedux-org/proxy_rb/compare/v0.10.3...v0.10.4)
|
8
14
|
|
9
15
|
* Don't overwrite proxies set by multiple tags
|
data/README.md
CHANGED
@@ -8,6 +8,10 @@
|
|
8
8
|
|
9
9
|
`proxy_rb` makes it easier for you to test your proxy infrastructre.
|
10
10
|
|
11
|
+
**Be careful: This documentation is always up to date and might contain
|
12
|
+
information that is not suitable for the version you are using. All features
|
13
|
+
flagged with "experimental" might change without any further notice.**
|
14
|
+
|
11
15
|
## Installation
|
12
16
|
|
13
17
|
Add this line to your application's Gemfile:
|
data/cucumber.yml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
wip: -t @wip:3 -t ~@broken-external -t ~@future -t ~@broken
|
2
|
+
default: -t ~@wip -t ~@broken-external -t ~@future -t ~@broken
|
data/lib/proxy_rb/announcer.rb
CHANGED
@@ -80,6 +80,7 @@ module ProxyRb
|
|
80
80
|
output_format :resource_user, proc { |v| format('Resource User: %s', v) }
|
81
81
|
output_format :resource, proc { |v| format('Resource: %s', v) }
|
82
82
|
output_format :http_response_headers, proc { |v| format("<<-HTTP_RESPONSE_HEADERS\n%s\nHTTP_RESPONSE_HEADERS", SimpleTable.new(v)) }
|
83
|
+
output_format :status_code, proc { |v| format('HTTP Status Code: %s', v) }
|
83
84
|
end
|
84
85
|
|
85
86
|
def output_format(channel, string = '%s', &block)
|
@@ -40,6 +40,10 @@ module ProxyRb
|
|
40
40
|
module HttpProxy
|
41
41
|
include ::Capybara::DSL
|
42
42
|
|
43
|
+
# !@attribute resource
|
44
|
+
# The resource which should be visited/downloaded
|
45
|
+
attr_reader :resource
|
46
|
+
|
43
47
|
# The proxy based on subject
|
44
48
|
def proxy
|
45
49
|
@proxy ||= ProxyRb::HttpProxy.new(ProxyRb::ProxyUrlParser.new(subject))
|
@@ -50,7 +54,7 @@ module ProxyRb
|
|
50
54
|
# @param [String] url
|
51
55
|
# rubocop:disable Metrics/AbcSize
|
52
56
|
def visit(url, p = proxy)
|
53
|
-
resource = Resource.new(url)
|
57
|
+
@resource = Resource.new(url)
|
54
58
|
|
55
59
|
proxy_rb.event_bus.notify Events::ResourceSet.new(resource.url.to_s)
|
56
60
|
proxy_rb.event_bus.notify Events::ResourceUserSet.new(resource.credentials.to_s) unless resource.credentials.empty?
|
@@ -1,28 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'proxy_rb/main'
|
3
|
+
|
2
4
|
Before do
|
3
5
|
setup_proxy_rb
|
4
6
|
end
|
5
7
|
|
6
|
-
|
7
|
-
proxy
|
8
|
-
proxy_user
|
9
|
-
resource
|
10
|
-
resource_user
|
11
|
-
http_response_headers
|
12
|
-
).each do |announcer|
|
8
|
+
ProxyRb::ANNOUNCERS.each do |announcer|
|
13
9
|
Before "@announce-#{announcer.to_s.tr('_', '-')}" do
|
14
10
|
proxy_rb.announcer.activate(announcer)
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
18
14
|
Before '@announce' do
|
19
|
-
|
20
|
-
proxy
|
21
|
-
proxy_user
|
22
|
-
resource
|
23
|
-
resource_user
|
24
|
-
http_response_headers
|
25
|
-
).each do |announcer|
|
15
|
+
ProxyRb::ANNOUNCERS.each do |announcer|
|
26
16
|
proxy_rb.announcer.activate(announcer)
|
27
17
|
end
|
28
18
|
end
|
@@ -16,7 +16,7 @@ Given(/^I use the user "([^"]*)"(?: with password "([^"]*)")?$/) do |user_name,
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Given(/^I use the following proxies:$/) do |table|
|
19
|
-
|
19
|
+
new_proxies = table.hashes.map do |r|
|
20
20
|
p = ProxyRb::HttpProxy.new(ProxyRb::ProxyUrlParser.new(r[:proxy]))
|
21
21
|
|
22
22
|
# Hide password by using <PASSWORD> => retrieve it using fetcher
|
@@ -37,6 +37,8 @@ Given(/^I use the following proxies:$/) do |table|
|
|
37
37
|
|
38
38
|
p
|
39
39
|
end
|
40
|
+
|
41
|
+
proxies.concat new_proxies
|
40
42
|
end
|
41
43
|
|
42
44
|
Then(/the following requests are( not)? allowed to pass the proxy:/) do |forbidden, table|
|
data/lib/proxy_rb/http_proxy.rb
CHANGED
data/lib/proxy_rb/main.rb
CHANGED
@@ -6,6 +6,15 @@ module ProxyRb
|
|
6
6
|
@debug_mode = false
|
7
7
|
@logger = Logger.new($stderr)
|
8
8
|
|
9
|
+
ANNOUNCERS = %i(
|
10
|
+
proxy
|
11
|
+
proxy_user
|
12
|
+
resource
|
13
|
+
resource_user
|
14
|
+
http_response_headers
|
15
|
+
status_code
|
16
|
+
)
|
17
|
+
|
9
18
|
class << self
|
10
19
|
protected
|
11
20
|
|
@@ -15,6 +24,7 @@ module ProxyRb
|
|
15
24
|
|
16
25
|
attr_reader :logger
|
17
26
|
|
27
|
+
# What kind of information can be announce while debugging
|
18
28
|
def debug_mode_enabled?
|
19
29
|
debug_mode == true
|
20
30
|
end
|
@@ -2,17 +2,36 @@
|
|
2
2
|
RSpec::Matchers.define :be_forbidden do
|
3
3
|
match do |actual|
|
4
4
|
next true if proxy_rb.config.strict == false && (actual.status_code.nil? || actual.status_code == 0)
|
5
|
-
require 'pry'
|
6
5
|
sleep 0.5 # handle network latency
|
7
6
|
|
8
7
|
values_match?(403, actual.status_code)
|
9
8
|
end
|
10
9
|
|
11
10
|
failure_message do |actual|
|
12
|
-
|
11
|
+
msg = []
|
12
|
+
|
13
|
+
msg << %(expected that response of "#{resource}" has status code 403, but has #{actual.status_code}.)
|
14
|
+
|
15
|
+
if proxy.nil? || proxy.empty?
|
16
|
+
msg << %(No proxy was used.)
|
17
|
+
else
|
18
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
19
|
+
end
|
20
|
+
|
21
|
+
msg.join ' '
|
13
22
|
end
|
14
23
|
|
15
24
|
failure_message_when_negated do
|
16
|
-
|
25
|
+
msg = []
|
26
|
+
|
27
|
+
msg << %(expected that response of "#{resource}" does not have status code 403.)
|
28
|
+
|
29
|
+
if proxy.nil? || proxy.empty?
|
30
|
+
msg << %(No proxy was used.)
|
31
|
+
else
|
32
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
33
|
+
end
|
34
|
+
|
35
|
+
msg.join ' '
|
17
36
|
end
|
18
37
|
end
|
@@ -2,16 +2,36 @@
|
|
2
2
|
RSpec::Matchers.define :be_successful do
|
3
3
|
match do |actual|
|
4
4
|
next true if proxy_rb.config.strict == false && (actual.status_code.nil? || actual.status_code == 0)
|
5
|
+
sleep 0.5 # handle network latency
|
5
6
|
|
6
|
-
sleep 0.5
|
7
7
|
actual.status_code.to_s.start_with?('2', '3')
|
8
8
|
end
|
9
9
|
|
10
10
|
failure_message do |actual|
|
11
|
-
|
11
|
+
msg = []
|
12
|
+
|
13
|
+
msg << %(expected that response of "#{resource}" has status code 2xx, but has #{actual.status_code}.)
|
14
|
+
|
15
|
+
if proxy.nil? || proxy.empty?
|
16
|
+
msg << %(No proxy was used.)
|
17
|
+
else
|
18
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
19
|
+
end
|
20
|
+
|
21
|
+
msg.join ' '
|
12
22
|
end
|
13
23
|
|
14
24
|
failure_message_when_negated do
|
15
|
-
|
25
|
+
msg = []
|
26
|
+
|
27
|
+
msg << %(expected that response of "#{resource}" does not have status code 2xx.)
|
28
|
+
|
29
|
+
if proxy.nil? || proxy.empty?
|
30
|
+
msg << %(No proxy was used.)
|
31
|
+
else
|
32
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
33
|
+
end
|
34
|
+
|
35
|
+
msg.join ' '
|
16
36
|
end
|
17
37
|
end
|
@@ -4,6 +4,34 @@ RSpec::Matchers.define :have_mime_type do |expected|
|
|
4
4
|
@actual = actual.mime_type
|
5
5
|
values_match?(expected, @actual)
|
6
6
|
end
|
7
|
+
|
8
|
+
failure_message do |actual|
|
9
|
+
msg = []
|
10
|
+
|
11
|
+
msg << %(expected that response of "#{resource}" has mime type "#{expected}", but has "#{actual}".)
|
12
|
+
|
13
|
+
if proxy.nil? || proxy.empty?
|
14
|
+
msg << %(No proxy was used.)
|
15
|
+
else
|
16
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
17
|
+
end
|
18
|
+
|
19
|
+
msg.join ' '
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message_when_negated do
|
23
|
+
msg = []
|
24
|
+
|
25
|
+
msg << %(expected that response of "#{resource}" does not have mime type "#{expected}".)
|
26
|
+
|
27
|
+
if proxy.nil? || proxy.empty?
|
28
|
+
msg << %(No proxy was used.)
|
29
|
+
else
|
30
|
+
msg << %(It was fetched via proxy "#{proxy.to_s}".)
|
31
|
+
end
|
32
|
+
|
33
|
+
msg.join ' '
|
34
|
+
end
|
7
35
|
end
|
8
36
|
|
9
37
|
RSpec::Matchers.alias_matcher :be_of_mime_type, :have_mime_type
|
data/lib/proxy_rb/proxy_url.rb
CHANGED
data/lib/proxy_rb/rspec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'proxy_rb/api'
|
3
|
+
require 'proxy_rb/main'
|
3
4
|
|
4
5
|
# Main Module
|
5
6
|
module ProxyRb
|
@@ -33,24 +34,12 @@ RSpec.configure do |config|
|
|
33
34
|
config.before :each do |example|
|
34
35
|
next unless self.class.include? ProxyRb::Api
|
35
36
|
|
36
|
-
|
37
|
-
proxy
|
38
|
-
proxy_user
|
39
|
-
resource
|
40
|
-
resource_user
|
41
|
-
http_response_headers
|
42
|
-
).each do |announcer|
|
37
|
+
ProxyRb::ANNOUNCERS.each do |announcer|
|
43
38
|
proxy_rb.announcer.activate(announcer) if example.metadata["announce_#{announcer}".to_sym]
|
44
39
|
end
|
45
40
|
|
46
41
|
if example.metadata[:announce]
|
47
|
-
|
48
|
-
proxy
|
49
|
-
proxy_user
|
50
|
-
resource
|
51
|
-
resource_user
|
52
|
-
http_response_headers
|
53
|
-
).each do |announcer|
|
42
|
+
ProxyRb::ANNOUNCERS.each do |announcer|
|
54
43
|
proxy_rb.announcer.activate(announcer)
|
55
44
|
end
|
56
45
|
end
|
data/lib/proxy_rb/setup.rb
CHANGED
@@ -61,6 +61,7 @@ module ProxyRb
|
|
61
61
|
proc do |event|
|
62
62
|
begin
|
63
63
|
runtime.announcer.announce :http_response_headers, event.entity.driver.response_headers
|
64
|
+
runtime.announcer.announce :status_code, event.entity.driver.status_code
|
64
65
|
rescue Capybara::NotSupportedByDriverError
|
65
66
|
runtime.announcer.announce :http_response_headers, 'Message': format('Using #response_headers with the current driver "%s" is currently not supported', event.entity.driver.class)
|
66
67
|
end
|
data/lib/proxy_rb/version.rb
CHANGED