httparty 0.17.0 → 0.17.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Changelog.md +7 -0
- data/Gemfile +1 -0
- data/httparty.gemspec +0 -1
- data/lib/httparty.rb +2 -18
- data/lib/httparty/connection_adapter.rb +10 -0
- data/lib/httparty/headers_processor.rb +30 -0
- data/lib/httparty/request.rb +4 -4
- data/lib/httparty/version.rb +1 -1
- metadata +4 -103
- data/features/basic_authentication.feature +0 -20
- data/features/command_line.feature +0 -95
- data/features/deals_with_http_error_codes.feature +0 -26
- data/features/digest_authentication.feature +0 -30
- data/features/handles_compressed_responses.feature +0 -27
- data/features/handles_multiple_formats.feature +0 -57
- data/features/steps/env.rb +0 -27
- data/features/steps/httparty_response_steps.rb +0 -56
- data/features/steps/httparty_steps.rb +0 -43
- data/features/steps/mongrel_helper.rb +0 -127
- data/features/steps/remote_service_steps.rb +0 -92
- data/features/supports_read_timeout_option.feature +0 -13
- data/features/supports_redirection.feature +0 -22
- data/features/supports_timeout_option.feature +0 -13
- data/spec/fixtures/delicious.xml +0 -23
- data/spec/fixtures/empty.xml +0 -0
- data/spec/fixtures/example.html +0 -10
- data/spec/fixtures/ssl/generate.sh +0 -29
- data/spec/fixtures/ssl/generated/bogushost.crt +0 -29
- data/spec/fixtures/ssl/generated/ca.crt +0 -31
- data/spec/fixtures/ssl/generated/ca.key +0 -52
- data/spec/fixtures/ssl/generated/selfsigned.crt +0 -29
- data/spec/fixtures/ssl/generated/server.crt +0 -30
- data/spec/fixtures/ssl/generated/server.key +0 -52
- data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
- data/spec/fixtures/tiny.gif +0 -0
- data/spec/fixtures/twitter.csv +0 -2
- data/spec/fixtures/twitter.json +0 -1
- data/spec/fixtures/twitter.xml +0 -403
- data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
- data/spec/httparty/connection_adapter_spec.rb +0 -628
- data/spec/httparty/cookie_hash_spec.rb +0 -100
- data/spec/httparty/exception_spec.rb +0 -45
- data/spec/httparty/hash_conversions_spec.rb +0 -58
- data/spec/httparty/logger/apache_formatter_spec.rb +0 -40
- data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
- data/spec/httparty/logger/logger_spec.rb +0 -43
- data/spec/httparty/logger/logstash_formatter_spec.rb +0 -44
- data/spec/httparty/net_digest_auth_spec.rb +0 -270
- data/spec/httparty/parser_spec.rb +0 -190
- data/spec/httparty/request/body_spec.rb +0 -165
- data/spec/httparty/request_spec.rb +0 -1389
- data/spec/httparty/response_fragment_spec.rb +0 -17
- data/spec/httparty/response_spec.rb +0 -374
- data/spec/httparty/ssl_spec.rb +0 -82
- data/spec/httparty_spec.rb +0 -943
- data/spec/spec_helper.rb +0 -57
- data/spec/support/ssl_test_helper.rb +0 -47
- data/spec/support/ssl_test_server.rb +0 -80
- data/spec/support/stub_response.rb +0 -50
@@ -1,30 +0,0 @@
|
|
1
|
-
Feature: Digest Authentication
|
2
|
-
|
3
|
-
As a developer
|
4
|
-
I want to be able to use a service that requires Digest Authentication
|
5
|
-
Because that is not an uncommon requirement
|
6
|
-
|
7
|
-
Scenario: Passing no credentials to a page requiring Digest Authentication
|
8
|
-
Given a restricted page at '/digest_auth.html'
|
9
|
-
When I call HTTParty#get with '/digest_auth.html'
|
10
|
-
Then it should return a response with a 401 response code
|
11
|
-
|
12
|
-
Scenario: Passing proper credentials to a page requiring Digest Authentication
|
13
|
-
Given a remote service that returns 'Digest Authenticated Page'
|
14
|
-
And that service is accessed at the path '/digest_auth.html'
|
15
|
-
And that service is protected by Digest Authentication
|
16
|
-
And that service requires the username 'jcash' with the password 'maninblack'
|
17
|
-
When I call HTTParty#get with '/digest_auth.html' and a digest_auth hash:
|
18
|
-
| username | password |
|
19
|
-
| jcash | maninblack |
|
20
|
-
Then the return value should match 'Digest Authenticated Page'
|
21
|
-
|
22
|
-
Scenario: Passing proper credentials to a page requiring Digest Authentication using md5-sess algorithm
|
23
|
-
Given a remote service that returns 'Digest Authenticated Page Using MD5-sess'
|
24
|
-
And that service is accessed at the path '/digest_auth.html'
|
25
|
-
And that service is protected by MD5-sess Digest Authentication
|
26
|
-
And that service requires the username 'jcash' with the password 'maninblack'
|
27
|
-
When I call HTTParty#get with '/digest_auth.html' and a digest_auth hash:
|
28
|
-
| username | password |
|
29
|
-
| jcash | maninblack |
|
30
|
-
Then the return value should match 'Digest Authenticated Page Using MD5-sess'
|
@@ -1,27 +0,0 @@
|
|
1
|
-
Feature: Handles Compressed Responses
|
2
|
-
|
3
|
-
In order to save bandwidth
|
4
|
-
As a developer
|
5
|
-
I want to uncompress compressed responses
|
6
|
-
|
7
|
-
Scenario: Supports deflate encoding
|
8
|
-
Given a remote deflate service
|
9
|
-
And the response from the service has a body of '<h1>Some HTML</h1>'
|
10
|
-
And that service is accessed at the path '/deflate_service.html'
|
11
|
-
When I call HTTParty#get with '/deflate_service.html'
|
12
|
-
Then the return value should match '<h1>Some HTML</h1>'
|
13
|
-
|
14
|
-
Scenario: Supports gzip encoding
|
15
|
-
Given a remote gzip service
|
16
|
-
And the response from the service has a body of '<h1>Some HTML</h1>'
|
17
|
-
And that service is accessed at the path '/gzip_service.html'
|
18
|
-
When I call HTTParty#get with '/gzip_service.html'
|
19
|
-
Then the return value should match '<h1>Some HTML</h1>'
|
20
|
-
|
21
|
-
Scenario: Supports HEAD request with gzip encoding
|
22
|
-
Given a remote gzip service
|
23
|
-
And that service is accessed at the path '/gzip_head.gz.js'
|
24
|
-
When I call HTTParty#head with '/gzip_head.gz.js'
|
25
|
-
Then it should return a response with a 200 response code
|
26
|
-
Then it should return a response with a gzip content-encoding
|
27
|
-
Then it should return a response with a blank body
|
@@ -1,57 +0,0 @@
|
|
1
|
-
Feature: Handles Multiple Formats
|
2
|
-
|
3
|
-
As a developer
|
4
|
-
I want to be able to consume remote services of many different formats
|
5
|
-
And I want those formats to be automatically detected and handled
|
6
|
-
Because web services take many forms
|
7
|
-
And I don't want to have to do any extra work
|
8
|
-
|
9
|
-
Scenario: An HTML service
|
10
|
-
Given a remote service that returns '<h1>Some HTML</h1>'
|
11
|
-
And that service is accessed at the path '/html_service.html'
|
12
|
-
And the response from the service has a Content-Type of 'text/html'
|
13
|
-
When I call HTTParty#get with '/html_service.html'
|
14
|
-
Then it should return a String
|
15
|
-
And the return value should match '<h1>Some HTML</h1>'
|
16
|
-
|
17
|
-
Scenario: A CSV service
|
18
|
-
Given a remote service that returns:
|
19
|
-
"""
|
20
|
-
"Last Name","Name"
|
21
|
-
"jennings","waylon"
|
22
|
-
"cash","johnny"
|
23
|
-
"""
|
24
|
-
And that service is accessed at the path '/service.csv'
|
25
|
-
And the response from the service has a Content-Type of 'application/csv'
|
26
|
-
When I call HTTParty#get with '/service.csv'
|
27
|
-
Then it should return an Array equaling:
|
28
|
-
| Last Name | Name |
|
29
|
-
| jennings | waylon |
|
30
|
-
| cash | johnny |
|
31
|
-
|
32
|
-
Scenario: A JSON service
|
33
|
-
Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
|
34
|
-
And that service is accessed at the path '/service.json'
|
35
|
-
And the response from the service has a Content-Type of 'application/json'
|
36
|
-
When I call HTTParty#get with '/service.json'
|
37
|
-
Then it should return a Hash equaling:
|
38
|
-
| key | value |
|
39
|
-
| jennings | waylon |
|
40
|
-
| cash | johnny |
|
41
|
-
|
42
|
-
Scenario: An XML Service
|
43
|
-
Given a remote service that returns '<singer>waylon jennings</singer>'
|
44
|
-
And that service is accessed at the path '/service.xml'
|
45
|
-
And the response from the service has a Content-Type of 'text/xml'
|
46
|
-
When I call HTTParty#get with '/service.xml'
|
47
|
-
Then it should return a Hash equaling:
|
48
|
-
| key | value |
|
49
|
-
| singer | waylon jennings |
|
50
|
-
|
51
|
-
Scenario: A Javascript remote file
|
52
|
-
Given a remote service that returns '$(function() { alert("hi"); });'
|
53
|
-
And that service is accessed at the path '/service.js'
|
54
|
-
And the response from the service has a Content-Type of 'application/javascript'
|
55
|
-
When I call HTTParty#get with '/service.js'
|
56
|
-
Then it should return a String
|
57
|
-
And the return value should match '$(function() { alert("hi"); });'
|
data/features/steps/env.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'mongrel'
|
2
|
-
require './lib/httparty'
|
3
|
-
require 'rspec/expectations'
|
4
|
-
require 'aruba/cucumber'
|
5
|
-
|
6
|
-
def run_server(port)
|
7
|
-
@host_and_port = "0.0.0.0:#{port}"
|
8
|
-
@server = Mongrel::HttpServer.new("0.0.0.0", port)
|
9
|
-
@server.run
|
10
|
-
@request_options = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
def new_port
|
14
|
-
server = TCPServer.new('0.0.0.0', nil)
|
15
|
-
port = server.addr[1]
|
16
|
-
ensure
|
17
|
-
server.close
|
18
|
-
end
|
19
|
-
|
20
|
-
Before('~@command_line') do
|
21
|
-
port = ENV["HTTPARTY_PORT"] || new_port
|
22
|
-
run_server(port)
|
23
|
-
end
|
24
|
-
|
25
|
-
After do
|
26
|
-
@server.stop if @server
|
27
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# Not needed anymore in ruby 2.0, but needed to resolve constants
|
2
|
-
# in nested namespaces. This is taken from rails :)
|
3
|
-
def constantize(camel_cased_word)
|
4
|
-
names = camel_cased_word.split('::')
|
5
|
-
names.shift if names.empty? || names.first.empty?
|
6
|
-
|
7
|
-
constant = Object
|
8
|
-
names.each do |name|
|
9
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
10
|
-
end
|
11
|
-
constant
|
12
|
-
end
|
13
|
-
|
14
|
-
Then /it should return an? ([\w\:]+)$/ do |class_string|
|
15
|
-
expect(@response_from_httparty.parsed_response).to be_a(Object.const_get(class_string))
|
16
|
-
end
|
17
|
-
|
18
|
-
Then /the return value should match '(.*)'/ do |expected_text|
|
19
|
-
expect(@response_from_httparty.parsed_response).to eq(expected_text)
|
20
|
-
end
|
21
|
-
|
22
|
-
Then /it should return a Hash equaling:/ do |hash_table|
|
23
|
-
expect(@response_from_httparty.parsed_response).to be_a(Hash)
|
24
|
-
expect(@response_from_httparty.keys.length).to eq(hash_table.rows.length)
|
25
|
-
hash_table.hashes.each do |pair|
|
26
|
-
key, value = pair["key"], pair["value"]
|
27
|
-
expect(@response_from_httparty.keys).to include(key)
|
28
|
-
expect(@response_from_httparty[key]).to eq(value)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Then /it should return an Array equaling:/ do |array|
|
33
|
-
expect(@response_from_httparty.parsed_response).to be_a(Array)
|
34
|
-
expect(@response_from_httparty.parsed_response).to eq(array.raw)
|
35
|
-
end
|
36
|
-
|
37
|
-
Then /it should return a response with a (\d+) response code/ do |code|
|
38
|
-
expect(@response_from_httparty.code).to eq(code.to_i)
|
39
|
-
end
|
40
|
-
|
41
|
-
Then /it should return a response with a (.*) content\-encoding$/ do |content_type|
|
42
|
-
expect(@response_from_httparty.headers['content-encoding']).to eq('gzip')
|
43
|
-
end
|
44
|
-
|
45
|
-
Then /it should return a response with a blank body$/ do
|
46
|
-
expect(@response_from_httparty.body).to be_nil
|
47
|
-
end
|
48
|
-
|
49
|
-
Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
|
50
|
-
expect(@exception_from_httparty).to_not be_nil
|
51
|
-
expect(@exception_from_httparty).to be_a constantize(exception)
|
52
|
-
end
|
53
|
-
|
54
|
-
Then /it should not raise (?:an|a) ([\w:]+) exception/ do |exception|
|
55
|
-
expect(@exception_from_httparty).to be_nil
|
56
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
When /^I set my HTTParty timeout option to (\d+)$/ do |timeout|
|
2
|
-
@request_options[:timeout] = timeout.to_i
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I set my HTTParty open_timeout option to (\d+)$/ do |timeout|
|
6
|
-
@request_options[:open_timeout] = timeout.to_i
|
7
|
-
end
|
8
|
-
|
9
|
-
When /^I set my HTTParty read_timeout option to (\d+)$/ do |timeout|
|
10
|
-
@request_options[:read_timeout] = timeout.to_i
|
11
|
-
end
|
12
|
-
|
13
|
-
When /I call HTTParty#get with '(.*)'$/ do |url|
|
14
|
-
begin
|
15
|
-
@response_from_httparty = HTTParty.get("http://#{@host_and_port}#{url}", @request_options)
|
16
|
-
rescue HTTParty::RedirectionTooDeep, Timeout::Error => e
|
17
|
-
@exception_from_httparty = e
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
When /^I call HTTParty#head with '(.*)'$/ do |url|
|
22
|
-
begin
|
23
|
-
@response_from_httparty = HTTParty.head("http://#{@host_and_port}#{url}", @request_options)
|
24
|
-
rescue HTTParty::RedirectionTooDeep, Timeout::Error => e
|
25
|
-
@exception_from_httparty = e
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
When /I call HTTParty#get with '(.*)' and a basic_auth hash:/ do |url, auth_table|
|
30
|
-
h = auth_table.hashes.first
|
31
|
-
@response_from_httparty = HTTParty.get(
|
32
|
-
"http://#{@host_and_port}#{url}",
|
33
|
-
basic_auth: { username: h["username"], password: h["password"] }
|
34
|
-
)
|
35
|
-
end
|
36
|
-
|
37
|
-
When /I call HTTParty#get with '(.*)' and a digest_auth hash:/ do |url, auth_table|
|
38
|
-
h = auth_table.hashes.first
|
39
|
-
@response_from_httparty = HTTParty.get(
|
40
|
-
"http://#{@host_and_port}#{url}",
|
41
|
-
digest_auth: { username: h["username"], password: h["password"] }
|
42
|
-
)
|
43
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'base64'
|
2
|
-
class BasicMongrelHandler < Mongrel::HttpHandler
|
3
|
-
attr_accessor :content_type, :custom_headers, :response_body, :response_code, :preprocessor, :username, :password
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@content_type = "text/html"
|
7
|
-
@response_body = ""
|
8
|
-
@response_code = 200
|
9
|
-
@custom_headers = {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def process(request, response)
|
13
|
-
instance_eval(&preprocessor) if preprocessor
|
14
|
-
reply_with(response, response_code, response_body)
|
15
|
-
end
|
16
|
-
|
17
|
-
def reply_with(response, code, response_body)
|
18
|
-
response.start(code) do |head, body|
|
19
|
-
head["Content-Type"] = content_type
|
20
|
-
custom_headers.each { |k, v| head[k] = v }
|
21
|
-
body.write(response_body)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class DeflateHandler < BasicMongrelHandler
|
27
|
-
def process(request, response)
|
28
|
-
response.start do |head, body|
|
29
|
-
head['Content-Encoding'] = 'deflate'
|
30
|
-
body.write Zlib::Deflate.deflate(response_body)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class GzipHandler < BasicMongrelHandler
|
36
|
-
def process(request, response)
|
37
|
-
response.start do |head, body|
|
38
|
-
head['Content-Encoding'] = 'gzip'
|
39
|
-
body.write gzip(response_body)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
protected
|
44
|
-
|
45
|
-
def gzip(string)
|
46
|
-
sio = StringIO.new('', 'r+')
|
47
|
-
gz = Zlib::GzipWriter.new sio
|
48
|
-
gz.write string
|
49
|
-
gz.finish
|
50
|
-
sio.rewind
|
51
|
-
sio.read
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
module BasicAuthentication
|
56
|
-
def self.extended(base)
|
57
|
-
base.custom_headers["WWW-Authenticate"] = 'Basic Realm="Super Secret Page"'
|
58
|
-
end
|
59
|
-
|
60
|
-
def process(request, response)
|
61
|
-
if authorized?(request)
|
62
|
-
super
|
63
|
-
else
|
64
|
-
reply_with(response, 401, "Incorrect. You have 20 seconds to comply.")
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def authorized?(request)
|
69
|
-
request.params["HTTP_AUTHORIZATION"] == "Basic " + Base64.encode64("#{@username}:#{@password}").strip
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
module DigestAuthentication
|
74
|
-
def self.extended(base)
|
75
|
-
base.custom_headers["WWW-Authenticate"] = 'Digest realm="testrealm@host.com",qop="auth,auth-int",nonce="nonce",opaque="opaque"'
|
76
|
-
end
|
77
|
-
|
78
|
-
def process(request, response)
|
79
|
-
if authorized?(request)
|
80
|
-
super
|
81
|
-
else
|
82
|
-
reply_with(response, 401, "Incorrect. You have 20 seconds to comply.")
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def authorized?(request)
|
87
|
-
request.params["HTTP_AUTHORIZATION"] =~ /Digest.*uri=/
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
module DigestAuthenticationUsingMD5Sess
|
92
|
-
NONCE = 'nonce'
|
93
|
-
REALM = 'testrealm@host.com'
|
94
|
-
QOP = 'auth,auth-int'
|
95
|
-
def self.extended(base)
|
96
|
-
base.custom_headers["WWW-Authenticate"] = %(Digest realm="#{REALM}",qop="#{QOP}",algorithm="MD5-sess",nonce="#{NONCE}",opaque="opaque"')
|
97
|
-
end
|
98
|
-
|
99
|
-
def process(request, response)
|
100
|
-
if authorized?(request)
|
101
|
-
super
|
102
|
-
else
|
103
|
-
reply_with(response, 401, "Incorrect. You have 20 seconds to comply.")
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def md5(str)
|
108
|
-
Digest::MD5.hexdigest(str)
|
109
|
-
end
|
110
|
-
|
111
|
-
def authorized?(request)
|
112
|
-
auth = request.params["HTTP_AUTHORIZATION"]
|
113
|
-
params = {}
|
114
|
-
auth.to_s.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }.gsub(/(\w+)=([^,]*)/) { params[$1] = $2 }
|
115
|
-
a1a = [@username,REALM,@password].join(':')
|
116
|
-
a1 = [md5(a1a),NONCE,params['cnonce'] ].join(':')
|
117
|
-
a2 = [ request.params["REQUEST_METHOD"], request.params["REQUEST_URI"] ] .join(':')
|
118
|
-
expected_response = md5( [md5(a1), NONCE, params['nc'], params['cnonce'], QOP, md5(a2)].join(':') )
|
119
|
-
expected_response == params['response']
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
def new_mongrel_redirector(target_url, relative_path = false)
|
125
|
-
target_url = "http://#{@host_and_port}#{target_url}" unless relative_path
|
126
|
-
Mongrel::RedirectHandler.new(target_url)
|
127
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
Given /a remote service that returns '(.*)'/ do |response_body|
|
2
|
-
@handler = BasicMongrelHandler.new
|
3
|
-
step "the response from the service has a body of '#{response_body}'"
|
4
|
-
end
|
5
|
-
|
6
|
-
Given /^a remote service that returns:$/ do |response_body|
|
7
|
-
@handler = BasicMongrelHandler.new
|
8
|
-
@handler.response_body = response_body
|
9
|
-
end
|
10
|
-
|
11
|
-
Given /a remote service that returns a (\d+) status code/ do |code|
|
12
|
-
@handler = BasicMongrelHandler.new
|
13
|
-
@handler.response_code = code
|
14
|
-
end
|
15
|
-
|
16
|
-
Given /that service is accessed at the path '(.*)'/ do |path|
|
17
|
-
@server.register(path, @handler)
|
18
|
-
end
|
19
|
-
|
20
|
-
Given /^that service takes (\d+) (.*) to generate a response$/ do |time, unit|
|
21
|
-
time = time.to_i
|
22
|
-
time *= 60 if unit =~ /minute/
|
23
|
-
@server_response_time = time
|
24
|
-
@handler.preprocessor = proc { sleep time }
|
25
|
-
end
|
26
|
-
|
27
|
-
Given /^a remote deflate service$/ do
|
28
|
-
@handler = DeflateHandler.new
|
29
|
-
end
|
30
|
-
|
31
|
-
Given /^a remote deflate service on port '(\d+)'/ do |port|
|
32
|
-
run_server(port)
|
33
|
-
@handler = DeflateHandler.new
|
34
|
-
end
|
35
|
-
|
36
|
-
Given /^a remote gzip service$/ do
|
37
|
-
@handler = GzipHandler.new
|
38
|
-
end
|
39
|
-
|
40
|
-
Given /the response from the service has a Content-Type of '(.*)'/ do |content_type|
|
41
|
-
@handler.content_type = content_type
|
42
|
-
end
|
43
|
-
|
44
|
-
Given /the response from the service has a body of '(.*)'/ do |response_body|
|
45
|
-
@handler.response_body = response_body
|
46
|
-
end
|
47
|
-
|
48
|
-
Given /the url '(.*)' redirects to '(.*)'/ do |redirection_url, target_url|
|
49
|
-
@server.register redirection_url, new_mongrel_redirector(target_url)
|
50
|
-
end
|
51
|
-
|
52
|
-
Given /that service is protected by Basic Authentication/ do
|
53
|
-
@handler.extend BasicAuthentication
|
54
|
-
end
|
55
|
-
|
56
|
-
Given /that service is protected by Digest Authentication/ do
|
57
|
-
@handler.extend DigestAuthentication
|
58
|
-
end
|
59
|
-
|
60
|
-
Given /that service is protected by MD5-sess Digest Authentication/ do
|
61
|
-
@handler.extend DigestAuthenticationUsingMD5Sess
|
62
|
-
end
|
63
|
-
|
64
|
-
Given /that service requires the username '(.*)' with the password '(.*)'/ do |username, password|
|
65
|
-
@handler.username = username
|
66
|
-
@handler.password = password
|
67
|
-
end
|
68
|
-
|
69
|
-
# customize aruba cucumber step
|
70
|
-
Then /^the output should contain '(.*)'$/ do |expected|
|
71
|
-
expect(all_commands.map(&:output).join("\n")).to match_output_string(expected)
|
72
|
-
end
|
73
|
-
|
74
|
-
Given /a restricted page at '(.*)'/ do |url|
|
75
|
-
steps "
|
76
|
-
Given a remote service that returns 'A response I will never see'
|
77
|
-
And that service is accessed at the path '#{url}'
|
78
|
-
And that service is protected by Basic Authentication
|
79
|
-
And that service requires the username 'something' with the password 'secret'
|
80
|
-
"
|
81
|
-
end
|
82
|
-
|
83
|
-
# This joins the server thread, and halts cucumber, so you can actually hit the
|
84
|
-
# server with a browser. Runs until you kill it with Ctrl-c
|
85
|
-
Given /I want to hit this in a browser/ do
|
86
|
-
@server.acceptor.join
|
87
|
-
end
|
88
|
-
|
89
|
-
Then /I wait for the server to recover/ do
|
90
|
-
timeout = @request_options[:timeout] || 0
|
91
|
-
sleep @server_response_time - timeout
|
92
|
-
end
|