excon 0.62.0 → 0.92.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +0 -1
- data/LICENSE.md +1 -1
- data/README.md +7 -6
- data/data/cacert.pem +1220 -1828
- data/excon.gemspec +19 -3
- data/lib/excon/connection.rb +216 -139
- data/lib/excon/constants.rb +38 -13
- data/lib/excon/error.rb +15 -0
- data/lib/excon/headers.rb +4 -3
- data/lib/excon/instrumentors/logging_instrumentor.rb +5 -16
- data/lib/excon/instrumentors/standard_instrumentor.rb +2 -9
- data/lib/excon/middlewares/base.rb +6 -0
- data/lib/excon/middlewares/capture_cookies.rb +1 -1
- data/lib/excon/middlewares/decompress.rb +11 -4
- data/lib/excon/middlewares/expects.rb +7 -1
- data/lib/excon/middlewares/idempotent.rb +20 -3
- data/lib/excon/middlewares/instrumentor.rb +8 -0
- data/lib/excon/middlewares/mock.rb +12 -3
- data/lib/excon/middlewares/redirect_follower.rb +25 -3
- data/lib/excon/middlewares/response_parser.rb +3 -0
- data/lib/excon/pretty_printer.rb +1 -8
- data/lib/excon/response.rb +12 -9
- data/lib/excon/socket.rb +59 -42
- data/lib/excon/ssl_socket.rb +37 -15
- data/lib/excon/test/plugin/server/exec.rb +5 -2
- data/lib/excon/test/plugin/server/puma.rb +4 -1
- data/lib/excon/test/plugin/server/unicorn.rb +5 -0
- data/lib/excon/test/plugin/server/webrick.rb +4 -1
- data/lib/excon/test/server.rb +1 -1
- data/lib/excon/unix_socket.rb +1 -0
- data/lib/excon/utils.rb +59 -5
- data/lib/excon/version.rb +1 -1
- data/lib/excon.rb +25 -17
- metadata +27 -98
- data/.document +0 -5
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -29
- data/Gemfile +0 -19
- data/Rakefile +0 -41
- data/benchmarks/class_vs_lambda.rb +0 -50
- data/benchmarks/concat_vs_insert.rb +0 -21
- data/benchmarks/concat_vs_interpolate.rb +0 -22
- data/benchmarks/cr_lf.rb +0 -21
- data/benchmarks/downcase-eq-eq_vs_casecmp.rb +0 -169
- data/benchmarks/excon.rb +0 -69
- data/benchmarks/excon_vs.rb +0 -165
- data/benchmarks/for_vs_array_each.rb +0 -27
- data/benchmarks/for_vs_hash_each.rb +0 -27
- data/benchmarks/has_key-vs-lookup.rb +0 -177
- data/benchmarks/headers_case_sensitivity.rb +0 -83
- data/benchmarks/headers_split_vs_match.rb +0 -34
- data/benchmarks/implicit_block-vs-explicit_block.rb +0 -98
- data/benchmarks/merging.rb +0 -21
- data/benchmarks/single_vs_double_quotes.rb +0 -21
- data/benchmarks/string_ranged_index.rb +0 -87
- data/benchmarks/strip_newline.rb +0 -115
- data/benchmarks/vs_stdlib.rb +0 -82
- data/changelog.txt +0 -1083
- data/spec/excon/error_spec.rb +0 -139
- data/spec/excon/test/server_spec.rb +0 -28
- data/spec/excon_spec.rb +0 -7
- data/spec/helpers/file_path_helpers.rb +0 -22
- data/spec/requests/basic_spec.rb +0 -40
- data/spec/requests/eof_requests_spec.rb +0 -36
- data/spec/requests/unix_socket_spec.rb +0 -46
- data/spec/spec_helper.rb +0 -24
- data/spec/support/shared_contexts/test_server_context.rb +0 -83
- data/spec/support/shared_examples/shared_example_for_clients.rb +0 -218
- data/spec/support/shared_examples/shared_example_for_streaming_clients.rb +0 -20
- data/spec/support/shared_examples/shared_example_for_test_servers.rb +0 -16
- data/tests/authorization_header_tests.rb +0 -29
- data/tests/bad_tests.rb +0 -47
- data/tests/basic_tests.rb +0 -351
- data/tests/batch_requests.rb +0 -133
- data/tests/complete_responses.rb +0 -31
- data/tests/data/127.0.0.1.cert.crt +0 -20
- data/tests/data/127.0.0.1.cert.key +0 -27
- data/tests/data/excon.cert.crt +0 -20
- data/tests/data/excon.cert.key +0 -27
- data/tests/data/xs +0 -1
- data/tests/error_tests.rb +0 -145
- data/tests/header_tests.rb +0 -119
- data/tests/middlewares/canned_response_tests.rb +0 -34
- data/tests/middlewares/capture_cookies_tests.rb +0 -34
- data/tests/middlewares/decompress_tests.rb +0 -157
- data/tests/middlewares/escape_path_tests.rb +0 -36
- data/tests/middlewares/idempotent_tests.rb +0 -206
- data/tests/middlewares/instrumentation_tests.rb +0 -315
- data/tests/middlewares/mock_tests.rb +0 -304
- data/tests/middlewares/redirect_follower_tests.rb +0 -112
- data/tests/pipeline_tests.rb +0 -40
- data/tests/proxy_tests.rb +0 -306
- data/tests/query_string_tests.rb +0 -87
- data/tests/rackups/basic.rb +0 -41
- data/tests/rackups/basic.ru +0 -3
- data/tests/rackups/basic_auth.ru +0 -14
- data/tests/rackups/deflater.ru +0 -4
- data/tests/rackups/proxy.ru +0 -18
- data/tests/rackups/query_string.ru +0 -13
- data/tests/rackups/redirecting.ru +0 -23
- data/tests/rackups/redirecting_with_cookie.ru +0 -40
- data/tests/rackups/request_headers.ru +0 -15
- data/tests/rackups/request_methods.ru +0 -21
- data/tests/rackups/response_header.ru +0 -18
- data/tests/rackups/ssl.ru +0 -16
- data/tests/rackups/ssl_mismatched_cn.ru +0 -15
- data/tests/rackups/ssl_verify_peer.ru +0 -16
- data/tests/rackups/streaming.ru +0 -30
- data/tests/rackups/thread_safety.ru +0 -17
- data/tests/rackups/timeout.ru +0 -14
- data/tests/rackups/webrick_patch.rb +0 -34
- data/tests/request_headers_tests.rb +0 -21
- data/tests/request_method_tests.rb +0 -47
- data/tests/request_tests.rb +0 -59
- data/tests/response_tests.rb +0 -197
- data/tests/servers/bad.rb +0 -20
- data/tests/servers/eof.rb +0 -17
- data/tests/servers/error.rb +0 -20
- data/tests/servers/good.rb +0 -350
- data/tests/test_helper.rb +0 -306
- data/tests/thread_safety_tests.rb +0 -39
- data/tests/timeout_tests.rb +0 -12
- data/tests/utils_tests.rb +0 -81
@@ -1,206 +0,0 @@
|
|
1
|
-
Shindo.tests('Excon request idempotencey') do
|
2
|
-
|
3
|
-
before do
|
4
|
-
@connection = Excon.new('http://127.0.0.1:9292', :mock => true)
|
5
|
-
end
|
6
|
-
|
7
|
-
after do
|
8
|
-
# flush any existing stubs after each test
|
9
|
-
Excon.stubs.clear
|
10
|
-
end
|
11
|
-
|
12
|
-
tests("Non-idempotent call with an erroring socket").raises(Excon::Errors::SocketError) do
|
13
|
-
run_count = 0
|
14
|
-
Excon.stub({:method => :get}) { |params|
|
15
|
-
run_count += 1
|
16
|
-
if run_count <= 3 # First 3 calls fail.
|
17
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
18
|
-
else
|
19
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
20
|
-
end
|
21
|
-
}
|
22
|
-
|
23
|
-
@connection.request(:method => :get, :path => '/some-path')
|
24
|
-
end
|
25
|
-
|
26
|
-
tests("Idempotent request with socket erroring first 3 times").returns(200) do
|
27
|
-
run_count = 0
|
28
|
-
Excon.stub({:method => :get}) { |params|
|
29
|
-
run_count += 1
|
30
|
-
if run_count <= 3 # First 3 calls fail.
|
31
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
32
|
-
else
|
33
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
34
|
-
end
|
35
|
-
}
|
36
|
-
|
37
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
|
38
|
-
response.status
|
39
|
-
end
|
40
|
-
|
41
|
-
tests("Idempotent request with socket erroring first 5 times").raises(Excon::Errors::SocketError) do
|
42
|
-
run_count = 0
|
43
|
-
Excon.stub({:method => :get}) { |params|
|
44
|
-
run_count += 1
|
45
|
-
if run_count <= 5 # First 5 calls fail.
|
46
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
47
|
-
else
|
48
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
49
|
-
end
|
50
|
-
}
|
51
|
-
|
52
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path')
|
53
|
-
response.status
|
54
|
-
end
|
55
|
-
|
56
|
-
tests("Lowered retry limit with socket erroring first time").returns(200) do
|
57
|
-
run_count = 0
|
58
|
-
Excon.stub({:method => :get}) { |params|
|
59
|
-
run_count += 1
|
60
|
-
if run_count <= 1 # First call fails.
|
61
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
62
|
-
else
|
63
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
64
|
-
end
|
65
|
-
}
|
66
|
-
|
67
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
|
68
|
-
response.status
|
69
|
-
end
|
70
|
-
|
71
|
-
tests("Lowered retry limit with socket erroring first 3 times").raises(Excon::Errors::SocketError) do
|
72
|
-
run_count = 0
|
73
|
-
Excon.stub({:method => :get}) { |params|
|
74
|
-
run_count += 1
|
75
|
-
if run_count <= 3 # First 3 calls fail.
|
76
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
77
|
-
else
|
78
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
79
|
-
end
|
80
|
-
}
|
81
|
-
|
82
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2)
|
83
|
-
response.status
|
84
|
-
end
|
85
|
-
|
86
|
-
tests("Raised retry limit with socket erroring first 5 times").returns(200) do
|
87
|
-
run_count = 0
|
88
|
-
Excon.stub({:method => :get}) { |params|
|
89
|
-
run_count += 1
|
90
|
-
if run_count <= 5 # First 5 calls fail.
|
91
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
92
|
-
else
|
93
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
94
|
-
end
|
95
|
-
}
|
96
|
-
|
97
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
|
98
|
-
response.status
|
99
|
-
end
|
100
|
-
|
101
|
-
tests("Raised retry limit with socket erroring first 9 times").raises(Excon::Errors::SocketError) do
|
102
|
-
run_count = 0
|
103
|
-
Excon.stub({:method => :get}) { |params|
|
104
|
-
run_count += 1
|
105
|
-
if run_count <= 9 # First 9 calls fail.
|
106
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
107
|
-
else
|
108
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
109
|
-
end
|
110
|
-
}
|
111
|
-
|
112
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 8)
|
113
|
-
response.status
|
114
|
-
end
|
115
|
-
|
116
|
-
tests("Retry limit in constructor with socket erroring first 5 times").returns(200) do
|
117
|
-
run_count = 0
|
118
|
-
Excon.stub({:method => :get}) { |params|
|
119
|
-
run_count += 1
|
120
|
-
if run_count <= 5 # First 5 calls fail.
|
121
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
122
|
-
else
|
123
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
124
|
-
end
|
125
|
-
}
|
126
|
-
|
127
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 6)
|
128
|
-
response.status
|
129
|
-
end
|
130
|
-
|
131
|
-
tests("Retry limit and sleep in constructor with socket erroring first 2 times").returns(200) do
|
132
|
-
run_count = 0
|
133
|
-
Excon.stub({:method => :get}) { |params|
|
134
|
-
run_count += 1
|
135
|
-
if run_count <= 2 # First 5 calls fail.
|
136
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
137
|
-
else
|
138
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
139
|
-
end
|
140
|
-
}
|
141
|
-
|
142
|
-
|
143
|
-
# NOTE: A short :retry_interval will avoid slowing down the tests.
|
144
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 3, :retry_interval => 0.1)
|
145
|
-
response.status
|
146
|
-
end
|
147
|
-
|
148
|
-
tests("Retry limit and sleep in constructor with socket erroring first 2 times").raises(Excon::Errors::SocketError) do
|
149
|
-
run_count = 0
|
150
|
-
Excon.stub({:method => :get}) { |params|
|
151
|
-
run_count += 1
|
152
|
-
if run_count <= 2 # First 5 calls fail.
|
153
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
154
|
-
else
|
155
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
156
|
-
end
|
157
|
-
}
|
158
|
-
|
159
|
-
# NOTE: A short :retry_interval will avoid slowing down the tests.
|
160
|
-
response = @connection.request(:method => :get, :idempotent => true, :path => '/some-path', :retry_limit => 2, :retry_interval => 0.1)
|
161
|
-
response.status
|
162
|
-
end
|
163
|
-
|
164
|
-
class Block
|
165
|
-
attr_reader :rewound
|
166
|
-
def initialize
|
167
|
-
@rewound = false
|
168
|
-
end
|
169
|
-
def call(_)
|
170
|
-
end
|
171
|
-
def rewind
|
172
|
-
@rewound = true
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
tests("request_block rewound").returns(true) do
|
177
|
-
run_count = 0
|
178
|
-
Excon.stub({:method => :get}) { |params|
|
179
|
-
run_count += 1
|
180
|
-
if run_count <= 1 # First call fails.
|
181
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
182
|
-
else
|
183
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
184
|
-
end
|
185
|
-
}
|
186
|
-
request_block = Block.new
|
187
|
-
@connection.request(:method => :get, :idempotent => true, :path => '/some-path', :request_block => request_block, :retry_limit => 2, :retry_interval => 0.1)
|
188
|
-
request_block.rewound
|
189
|
-
end
|
190
|
-
|
191
|
-
tests("response_block rewound").returns(true) do
|
192
|
-
run_count = 0
|
193
|
-
Excon.stub({:method => :get}) { |params|
|
194
|
-
run_count += 1
|
195
|
-
if run_count <= 1 # First call fails.
|
196
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
197
|
-
else
|
198
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
199
|
-
end
|
200
|
-
}
|
201
|
-
response_block = Block.new
|
202
|
-
@connection.request(:method => :get, :idempotent => true, :path => '/some-path', :response_block => response_block, :retry_limit => 2, :retry_interval => 0.1)
|
203
|
-
response_block.rewound
|
204
|
-
end
|
205
|
-
|
206
|
-
end
|
@@ -1,315 +0,0 @@
|
|
1
|
-
require 'active_support/notifications'
|
2
|
-
require 'securerandom'
|
3
|
-
|
4
|
-
class SimpleInstrumentor
|
5
|
-
class << self
|
6
|
-
attr_accessor :events, :blocks
|
7
|
-
|
8
|
-
def instrument(name, params = {}, &block)
|
9
|
-
@events << name
|
10
|
-
@blocks << name if block_given?
|
11
|
-
|
12
|
-
yield if block_given?
|
13
|
-
end
|
14
|
-
|
15
|
-
def reset!
|
16
|
-
@events = []
|
17
|
-
@blocks = []
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
Shindo.tests('Excon instrumentation') do
|
23
|
-
|
24
|
-
after do
|
25
|
-
ActiveSupport::Notifications.unsubscribe("excon")
|
26
|
-
ActiveSupport::Notifications.unsubscribe("excon.request")
|
27
|
-
ActiveSupport::Notifications.unsubscribe("excon.response")
|
28
|
-
ActiveSupport::Notifications.unsubscribe("excon.retry")
|
29
|
-
ActiveSupport::Notifications.unsubscribe("excon.error")
|
30
|
-
ActiveSupport::Notifications.unsubscribe("gug")
|
31
|
-
Delorean.back_to_the_present
|
32
|
-
Excon.stubs.clear
|
33
|
-
end
|
34
|
-
|
35
|
-
before do
|
36
|
-
SimpleInstrumentor.reset!
|
37
|
-
end
|
38
|
-
|
39
|
-
def subscribe(match)
|
40
|
-
@events = []
|
41
|
-
ActiveSupport::Notifications.subscribe(match) do |*args|
|
42
|
-
@events << ActiveSupport::Notifications::Event.new(*args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def make_request(idempotent = false, params = {})
|
47
|
-
connection = Excon.new(
|
48
|
-
'http://127.0.0.1:9292',
|
49
|
-
:instrumentor => ActiveSupport::Notifications,
|
50
|
-
:mock => true
|
51
|
-
)
|
52
|
-
if idempotent
|
53
|
-
params[:idempotent] = :true
|
54
|
-
end
|
55
|
-
connection.get(params)
|
56
|
-
end
|
57
|
-
|
58
|
-
REQUEST_DELAY_SECONDS = 30
|
59
|
-
def stub_success
|
60
|
-
Excon.stub({:method => :get}) { |params|
|
61
|
-
Delorean.jump REQUEST_DELAY_SECONDS
|
62
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
def stub_retries
|
67
|
-
run_count = 0
|
68
|
-
Excon.stub({:method => :get}) { |params|
|
69
|
-
run_count += 1
|
70
|
-
if run_count <= 3 # First 3 calls fail.
|
71
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
72
|
-
else
|
73
|
-
{:body => params[:body], :headers => params[:headers], :status => 200}
|
74
|
-
end
|
75
|
-
}
|
76
|
-
end
|
77
|
-
|
78
|
-
def stub_failure
|
79
|
-
Excon.stub({:method => :get}) { |params|
|
80
|
-
raise Excon::Errors::SocketError.new(Exception.new "Mock Error")
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
tests('basic notification').returns(['excon.request', 'excon.response']) do
|
85
|
-
subscribe(/excon/)
|
86
|
-
stub_success
|
87
|
-
make_request
|
88
|
-
@events.map(&:name)
|
89
|
-
end
|
90
|
-
|
91
|
-
tests('captures scheme, host, port, and path').returns([:host, :path, :port, :scheme]) do
|
92
|
-
subscribe(/excon/)
|
93
|
-
stub_success
|
94
|
-
make_request
|
95
|
-
[:host, :path, :port, :scheme].select {|k| @events.first.payload.has_key? k}
|
96
|
-
end
|
97
|
-
|
98
|
-
tests('params in request overwrite those in constructor').returns('/cheezburger') do
|
99
|
-
subscribe(/excon/)
|
100
|
-
stub_success
|
101
|
-
make_request(false, :path => '/cheezburger')
|
102
|
-
@events.first.payload[:path]
|
103
|
-
end
|
104
|
-
|
105
|
-
tests('notify on retry').returns(3) do
|
106
|
-
subscribe(/excon/)
|
107
|
-
stub_retries
|
108
|
-
make_request(true)
|
109
|
-
@events.count{|e| e.name =~ /retry/}
|
110
|
-
end
|
111
|
-
|
112
|
-
tests('notify on error').returns(true) do
|
113
|
-
subscribe(/excon/)
|
114
|
-
stub_failure
|
115
|
-
raises(Excon::Errors::SocketError) do
|
116
|
-
make_request
|
117
|
-
end
|
118
|
-
|
119
|
-
@events.any?{|e| e.name =~ /error/}
|
120
|
-
end
|
121
|
-
|
122
|
-
tests('filtering').returns(['excon.request', 'excon.error']) do
|
123
|
-
subscribe(/excon.request/)
|
124
|
-
subscribe(/excon.error/)
|
125
|
-
stub_failure
|
126
|
-
raises(Excon::Errors::SocketError) do
|
127
|
-
make_request(true)
|
128
|
-
end
|
129
|
-
|
130
|
-
@events.map(&:name)
|
131
|
-
end
|
132
|
-
|
133
|
-
tests('more filtering').returns(['excon.retry', 'excon.retry', 'excon.retry']) do
|
134
|
-
subscribe(/excon.retry/)
|
135
|
-
stub_failure
|
136
|
-
raises(Excon::Errors::SocketError) do
|
137
|
-
make_request(true)
|
138
|
-
end
|
139
|
-
|
140
|
-
@events.map(&:name)
|
141
|
-
end
|
142
|
-
|
143
|
-
tests('indicates duration').returns(true) do
|
144
|
-
subscribe(/excon/)
|
145
|
-
stub_success
|
146
|
-
make_request
|
147
|
-
(@events.first.duration/1000 - REQUEST_DELAY_SECONDS).abs < 1
|
148
|
-
end
|
149
|
-
|
150
|
-
tests('standard instrumentor') do
|
151
|
-
|
152
|
-
tests('success').returns(
|
153
|
-
['excon.request', 'excon.retry', 'excon.retry', 'excon.retry', 'excon.error']) do
|
154
|
-
|
155
|
-
begin
|
156
|
-
original_stderr = $stderr
|
157
|
-
$stderr = captured_stderr = StringIO.new
|
158
|
-
stub_failure
|
159
|
-
connection = Excon.new(
|
160
|
-
'http://127.0.0.1:9292',
|
161
|
-
:instrumentor => Excon::StandardInstrumentor,
|
162
|
-
:mock => true
|
163
|
-
)
|
164
|
-
raises(Excon::Errors::SocketError) do
|
165
|
-
connection.get(:idempotent => true)
|
166
|
-
end
|
167
|
-
|
168
|
-
captured_stderr.string.split("\n").reject {|line| line =~ %r{^ }}.map {|event| event.split(' ').first}
|
169
|
-
ensure
|
170
|
-
$stderr = original_stderr
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
tests('authorization header REDACT') do
|
175
|
-
|
176
|
-
@auth_header = 'Basic dXNlcjpwYXNz'
|
177
|
-
|
178
|
-
begin
|
179
|
-
original_stderr = $stderr
|
180
|
-
$stderr = @captured_stderr = StringIO.new
|
181
|
-
stub_failure
|
182
|
-
raises(Excon::Errors::SocketError) do
|
183
|
-
@connection = Excon.new(
|
184
|
-
'http://user:pass@127.0.0.1:9292',
|
185
|
-
:headers => {
|
186
|
-
'Authorization' => @auth_header
|
187
|
-
},
|
188
|
-
:instrumentor => Excon::StandardInstrumentor,
|
189
|
-
:mock => true
|
190
|
-
)
|
191
|
-
@connection.get(:idempotent => true)
|
192
|
-
end
|
193
|
-
ensure
|
194
|
-
$stderr = original_stderr
|
195
|
-
end
|
196
|
-
|
197
|
-
test('does not appear in response') do
|
198
|
-
!@captured_stderr.string.include?(@auth_header)
|
199
|
-
end
|
200
|
-
|
201
|
-
test('does not mutate Authorization value') do
|
202
|
-
@connection.data[:headers]['Authorization'] == @auth_header
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
|
-
tests('password REDACT') do
|
208
|
-
|
209
|
-
begin
|
210
|
-
original_stderr = $stderr
|
211
|
-
$stderr = @captured_stderr = StringIO.new
|
212
|
-
stub_failure
|
213
|
-
raises(Excon::Errors::SocketError) do
|
214
|
-
@connection = Excon.new(
|
215
|
-
'http://user:pass@127.0.0.1:9292',
|
216
|
-
:instrumentor => Excon::StandardInstrumentor,
|
217
|
-
:mock => true
|
218
|
-
)
|
219
|
-
@connection.get(:idempotent => true)
|
220
|
-
end
|
221
|
-
ensure
|
222
|
-
$stderr = original_stderr
|
223
|
-
end
|
224
|
-
|
225
|
-
@password_param = '"pass"'
|
226
|
-
|
227
|
-
test('does not appear in response') do
|
228
|
-
!@captured_stderr.string.include?(@password_param)
|
229
|
-
end
|
230
|
-
|
231
|
-
test('does not mutate password value') do
|
232
|
-
@connection.data[:password] == "pass"
|
233
|
-
end
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
238
|
-
|
239
|
-
tests('use our own instrumentor').returns(
|
240
|
-
['excon.request', 'excon.retry', 'excon.retry', 'excon.retry', 'excon.error']) do
|
241
|
-
stub_failure
|
242
|
-
connection = Excon.new(
|
243
|
-
'http://127.0.0.1:9292',
|
244
|
-
:instrumentor => SimpleInstrumentor,
|
245
|
-
:mock => true
|
246
|
-
)
|
247
|
-
raises(Excon::Errors::SocketError) do
|
248
|
-
connection.get(:idempotent => true)
|
249
|
-
end
|
250
|
-
|
251
|
-
SimpleInstrumentor.events
|
252
|
-
end
|
253
|
-
|
254
|
-
tests('always passes the block').returns(
|
255
|
-
['excon.request', 'excon.response']) do
|
256
|
-
stub_success
|
257
|
-
connection = Excon.new(
|
258
|
-
'http://127.0.0.1:9292',
|
259
|
-
:instrumentor => SimpleInstrumentor,
|
260
|
-
:mock => true
|
261
|
-
)
|
262
|
-
connection.get(:idempotent => true)
|
263
|
-
|
264
|
-
SimpleInstrumentor.blocks
|
265
|
-
end
|
266
|
-
|
267
|
-
tests('does not generate events when not provided').returns(0) do
|
268
|
-
subscribe(/excon/)
|
269
|
-
stub_success
|
270
|
-
connection = Excon.new('http://127.0.0.1:9292', :mock => true)
|
271
|
-
connection.get(:idempotent => true)
|
272
|
-
@events.count
|
273
|
-
end
|
274
|
-
|
275
|
-
tests('allows setting the prefix').returns(
|
276
|
-
['gug.request', 'gug.retry', 'gug.retry','gug.retry', 'gug.error']) do
|
277
|
-
subscribe(/gug/)
|
278
|
-
stub_failure
|
279
|
-
connection = Excon.new(
|
280
|
-
'http://127.0.0.1:9292',
|
281
|
-
:instrumentor => ActiveSupport::Notifications,
|
282
|
-
:instrumentor_name => 'gug',
|
283
|
-
:mock => true
|
284
|
-
)
|
285
|
-
raises(Excon::Errors::SocketError) do
|
286
|
-
connection.get(:idempotent => true)
|
287
|
-
end
|
288
|
-
@events.map(&:name)
|
289
|
-
end
|
290
|
-
|
291
|
-
tests('allows setting the prefix when not idempotent', 'foo').returns(
|
292
|
-
['gug.request', 'gug.error']) do
|
293
|
-
subscribe(/gug/)
|
294
|
-
stub_failure
|
295
|
-
connection = Excon.new(
|
296
|
-
'http://127.0.0.1:9292',
|
297
|
-
:instrumentor => ActiveSupport::Notifications,
|
298
|
-
:instrumentor_name => 'gug',
|
299
|
-
:mock => true
|
300
|
-
)
|
301
|
-
raises(Excon::Errors::SocketError) do
|
302
|
-
connection.get()
|
303
|
-
end
|
304
|
-
@events.map(&:name)
|
305
|
-
end
|
306
|
-
|
307
|
-
with_rackup('basic.ru') do
|
308
|
-
tests('works unmocked').returns(['excon.request', 'excon.response']) do
|
309
|
-
subscribe(/excon/)
|
310
|
-
make_request(false, :mock => false)
|
311
|
-
@events.map(&:name)
|
312
|
-
end
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|