httpi 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -6
- data/CHANGELOG.md +6 -0
- data/httpi.gemspec +14 -13
- data/lib/httpi/adapter/curb.rb +20 -10
- data/lib/httpi/adapter/excon.rb +0 -1
- data/lib/httpi/adapter/httpclient.rb +11 -8
- data/lib/httpi/adapter/net_http.rb +27 -15
- data/lib/httpi/version.rb +1 -1
- data/spec/httpi/adapter/curb_spec.rb +41 -33
- data/spec/httpi/adapter/em_http_spec.rb +6 -6
- data/spec/httpi/adapter/excon_spec.rb +12 -12
- data/spec/httpi/adapter/httpclient_spec.rb +19 -6
- data/spec/httpi/adapter/net_http_persistent_spec.rb +12 -12
- data/spec/httpi/adapter/net_http_spec.rb +24 -13
- data/spec/httpi/adapter/rack_spec.rb +11 -11
- data/spec/httpi/adapter_spec.rb +7 -7
- data/spec/httpi/auth/config_spec.rb +27 -27
- data/spec/httpi/auth/ssl_spec.rb +23 -23
- data/spec/httpi/cookie_spec.rb +5 -5
- data/spec/httpi/cookie_store_spec.rb +3 -3
- data/spec/httpi/httpi_spec.rb +3 -3
- data/spec/httpi/request_spec.rb +33 -33
- data/spec/httpi/response_spec.rb +16 -16
- data/spec/integration/curb_spec.rb +16 -16
- data/spec/integration/em_http_spec.rb +13 -13
- data/spec/integration/httpclient_spec.rb +16 -16
- data/spec/integration/net_http_persistent_spec.rb +16 -16
- data/spec/integration/net_http_spec.rb +16 -16
- data/spec/support/matchers.rb +4 -4
- metadata +26 -25
@@ -13,7 +13,7 @@ describe HTTPI::Adapter::HTTPClient do
|
|
13
13
|
describe "#request(:get)" do
|
14
14
|
it "returns a valid HTTPI::Response" do
|
15
15
|
httpclient_expects(:get)
|
16
|
-
adapter.request(:get).
|
16
|
+
expect(adapter.request(:get)).to match_response(:body => Fixture.xml)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -22,14 +22,14 @@ describe HTTPI::Adapter::HTTPClient do
|
|
22
22
|
request.body = Fixture.xml
|
23
23
|
httpclient_expects(:post)
|
24
24
|
|
25
|
-
adapter.request(:post).
|
25
|
+
expect(adapter.request(:post)).to match_response(:body => Fixture.xml)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#request(:head)" do
|
30
30
|
it "returns a valid HTTPI::Response" do
|
31
31
|
httpclient_expects(:head)
|
32
|
-
adapter.request(:head).
|
32
|
+
expect(adapter.request(:head)).to match_response(:body => Fixture.xml)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -38,21 +38,21 @@ describe HTTPI::Adapter::HTTPClient do
|
|
38
38
|
request.body = Fixture.xml
|
39
39
|
httpclient_expects(:put)
|
40
40
|
|
41
|
-
adapter.request(:put).
|
41
|
+
expect(adapter.request(:put)).to match_response(:body => Fixture.xml)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#request(:delete)" do
|
46
46
|
it "returns a valid HTTPI::Response" do
|
47
47
|
httpclient_expects(:delete)
|
48
|
-
adapter.request(:delete).
|
48
|
+
expect(adapter.request(:delete)).to match_response(:body => Fixture.xml)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#request(:custom)" do
|
53
53
|
it "returns a valid HTTPI::Response" do
|
54
54
|
httpclient_expects(:custom)
|
55
|
-
adapter.request(:custom).
|
55
|
+
expect(adapter.request(:custom)).to match_response(:body => Fixture.xml)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -107,6 +107,19 @@ describe HTTPI::Adapter::HTTPClient do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
context "(for SSL without auth)" do
|
111
|
+
before do
|
112
|
+
request.ssl = true
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should set the ssl_version if specified' do
|
116
|
+
request.auth.ssl.ssl_version = :SSLv3
|
117
|
+
ssl_config.expects(:ssl_version=).with('SSLv3')
|
118
|
+
|
119
|
+
adapter.request(:get)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
110
123
|
context "(for SSL client auth)" do
|
111
124
|
before do
|
112
125
|
request.auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
@@ -19,37 +19,37 @@ describe HTTPI::Adapter::NetHTTPPersistent do
|
|
19
19
|
request.headers["X-Header"] = "HTTPI"
|
20
20
|
|
21
21
|
response = HTTPI.get(request, adapter)
|
22
|
-
response.body.
|
22
|
+
expect(response.body).to include("HTTPI")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "executes GET requests" do
|
26
26
|
response = HTTPI.get(@server.url, adapter)
|
27
|
-
response.body.
|
28
|
-
response.headers["Content-Type"].
|
27
|
+
expect(response.body).to eq("get")
|
28
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "executes POST requests" do
|
32
32
|
response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
|
33
|
-
response.body.
|
34
|
-
response.headers["Content-Type"].
|
33
|
+
expect(response.body).to eq("post")
|
34
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
35
35
|
end
|
36
36
|
|
37
37
|
it "executes HEAD requests" do
|
38
38
|
response = HTTPI.head(@server.url, adapter)
|
39
|
-
response.code.
|
40
|
-
response.headers["Content-Type"].
|
39
|
+
expect(response.code).to eq(200)
|
40
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
41
41
|
end
|
42
42
|
|
43
43
|
it "executes PUT requests" do
|
44
44
|
response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
|
45
|
-
response.body.
|
46
|
-
response.headers["Content-Type"].
|
45
|
+
expect(response.body).to eq("put")
|
46
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "executes DELETE requests" do
|
50
50
|
response = HTTPI.delete(@server.url, adapter)
|
51
|
-
response.body.
|
52
|
-
response.headers["Content-Type"].
|
51
|
+
expect(response.body).to eq("delete")
|
52
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "supports basic authentication" do
|
@@ -57,7 +57,7 @@ describe HTTPI::Adapter::NetHTTPPersistent do
|
|
57
57
|
request.auth.basic("admin", "secret")
|
58
58
|
|
59
59
|
response = HTTPI.get(request, adapter)
|
60
|
-
response.body.
|
60
|
+
expect(response.body).to eq("basic-auth")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "does not support ntlm authentication" do
|
@@ -19,37 +19,37 @@ describe HTTPI::Adapter::NetHTTP do
|
|
19
19
|
request.headers["X-Header"] = "HTTPI"
|
20
20
|
|
21
21
|
response = HTTPI.get(request, adapter)
|
22
|
-
response.body.
|
22
|
+
expect(response.body).to include("HTTPI")
|
23
23
|
end
|
24
24
|
|
25
25
|
it "executes GET requests" do
|
26
26
|
response = HTTPI.get(@server.url, adapter)
|
27
|
-
response.body.
|
28
|
-
response.headers["Content-Type"].
|
27
|
+
expect(response.body).to eq("get")
|
28
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "executes POST requests" do
|
32
32
|
response = HTTPI.post(@server.url, "<some>xml</some>", adapter)
|
33
|
-
response.body.
|
34
|
-
response.headers["Content-Type"].
|
33
|
+
expect(response.body).to eq("post")
|
34
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
35
35
|
end
|
36
36
|
|
37
37
|
it "executes HEAD requests" do
|
38
38
|
response = HTTPI.head(@server.url, adapter)
|
39
|
-
response.code.
|
40
|
-
response.headers["Content-Type"].
|
39
|
+
expect(response.code).to eq(200)
|
40
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
41
41
|
end
|
42
42
|
|
43
43
|
it "executes PUT requests" do
|
44
44
|
response = HTTPI.put(@server.url, "<some>xml</some>", adapter)
|
45
|
-
response.body.
|
46
|
-
response.headers["Content-Type"].
|
45
|
+
expect(response.body).to eq("put")
|
46
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "executes DELETE requests" do
|
50
50
|
response = HTTPI.delete(@server.url, adapter)
|
51
|
-
response.body.
|
52
|
-
response.headers["Content-Type"].
|
51
|
+
expect(response.body).to eq("delete")
|
52
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
53
53
|
end
|
54
54
|
|
55
55
|
it "supports basic authentication" do
|
@@ -57,7 +57,7 @@ describe HTTPI::Adapter::NetHTTP do
|
|
57
57
|
request.auth.basic("admin", "secret")
|
58
58
|
|
59
59
|
response = HTTPI.get(request, adapter)
|
60
|
-
response.body.
|
60
|
+
expect(response.body).to eq("basic-auth")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "does not support digest authentication" do
|
@@ -73,7 +73,18 @@ describe HTTPI::Adapter::NetHTTP do
|
|
73
73
|
request.auth.ntlm("tester", "vReqSoafRe5O")
|
74
74
|
|
75
75
|
response = HTTPI.get(request, adapter)
|
76
|
-
response.body.
|
76
|
+
expect(response.body).to eq("ntlm-auth")
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'fatal logs when net/ntlm is not available, but ntlm authentication was requested' do
|
80
|
+
Net.expects(:const_defined?).with(:NTLM).returns false
|
81
|
+
|
82
|
+
request = HTTPI::Request.new(@server.url + 'ntlm-auth')
|
83
|
+
request.auth.ntlm("testing", "failures")
|
84
|
+
HTTPI.logger.expects(:fatal)
|
85
|
+
|
86
|
+
response = HTTPI.get(request, adapter)
|
87
|
+
expect(response.body).to eq("ntlm-auth")
|
77
88
|
end
|
78
89
|
end
|
79
90
|
|
@@ -18,37 +18,37 @@ describe HTTPI::Adapter::NetHTTP do
|
|
18
18
|
request.headers["X-Header"] = "HTTPI"
|
19
19
|
|
20
20
|
response = HTTPI.get(request, adapter)
|
21
|
-
response.body.
|
21
|
+
expect(response.body).to include("HTTPI")
|
22
22
|
end
|
23
23
|
|
24
24
|
it "executes GET requests" do
|
25
25
|
response = HTTPI.get(@url, adapter)
|
26
|
-
response.body.
|
27
|
-
response.headers["Content-Type"].
|
26
|
+
expect(response.body).to eq("get")
|
27
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
28
28
|
end
|
29
29
|
|
30
30
|
it "executes POST requests" do
|
31
31
|
response = HTTPI.post(@url, "<some>xml</some>", adapter)
|
32
|
-
response.body.
|
33
|
-
response.headers["Content-Type"].
|
32
|
+
expect(response.body).to eq("post")
|
33
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
34
34
|
end
|
35
35
|
|
36
36
|
it "executes HEAD requests" do
|
37
37
|
response = HTTPI.head(@url, adapter)
|
38
|
-
response.code.
|
39
|
-
response.headers["Content-Type"].
|
38
|
+
expect(response.code).to eq(200)
|
39
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "executes PUT requests" do
|
43
43
|
response = HTTPI.put(@url, "<some>xml</some>", adapter)
|
44
|
-
response.body.
|
45
|
-
response.headers["Content-Type"].
|
44
|
+
expect(response.body).to eq("put")
|
45
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
46
46
|
end
|
47
47
|
|
48
48
|
it "executes DELETE requests" do
|
49
49
|
response = HTTPI.delete(@url, adapter)
|
50
|
-
response.body.
|
51
|
-
response.headers["Content-Type"].
|
50
|
+
expect(response.body).to eq("delete")
|
51
|
+
expect(response.headers["Content-Type"]).to eq("text/plain")
|
52
52
|
end
|
53
53
|
|
54
54
|
describe "settings:" do
|
data/spec/httpi/adapter_spec.rb
CHANGED
@@ -12,8 +12,8 @@ describe HTTPI::Adapter do
|
|
12
12
|
|
13
13
|
adapter.register(name, klass, deps)
|
14
14
|
|
15
|
-
HTTPI::Adapter::ADAPTERS[:custom].
|
16
|
-
HTTPI::Adapter::ADAPTER_CLASS_MAP[klass].
|
15
|
+
expect(HTTPI::Adapter::ADAPTERS[:custom]).to include(:class => klass, :deps => deps)
|
16
|
+
expect(HTTPI::Adapter::ADAPTER_CLASS_MAP[klass]).to be(name)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -25,14 +25,14 @@ describe HTTPI::Adapter do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it "sets the adapter to use" do
|
28
|
-
adapter.use.
|
28
|
+
expect(adapter.use).not_to eq(:net_http)
|
29
29
|
|
30
30
|
adapter.use = :net_http
|
31
|
-
adapter.use.
|
31
|
+
expect(adapter.use).to eq(:net_http)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "defaults to use the HTTPClient adapter" do
|
35
|
-
adapter.use.
|
35
|
+
expect(adapter.use).to eq(:httpclient)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "loads the adapter's client library" do
|
@@ -48,13 +48,13 @@ describe HTTPI::Adapter do
|
|
48
48
|
describe ".load" do
|
49
49
|
context "called with a valid adapter" do
|
50
50
|
it "returns the adapter's name and class" do
|
51
|
-
adapter.load(:net_http).
|
51
|
+
expect(adapter.load(:net_http)).to eq(HTTPI::Adapter::NetHTTP)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
context "called with nil" do
|
56
56
|
it "returns the default adapter's name and class" do
|
57
|
-
adapter.load(nil).
|
57
|
+
expect(adapter.load(nil)).to eq(HTTPI::Adapter::HTTPClient)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -7,156 +7,156 @@ describe HTTPI::Auth::Config do
|
|
7
7
|
describe "#basic" do
|
8
8
|
it "lets you specify the basic auth credentials" do
|
9
9
|
auth.basic "username", "password"
|
10
|
-
auth.basic.
|
10
|
+
expect(auth.basic).to eq(["username", "password"])
|
11
11
|
end
|
12
12
|
|
13
13
|
it "also accepts an Array of credentials" do
|
14
14
|
auth.basic ["username", "password"]
|
15
|
-
auth.basic.
|
15
|
+
expect(auth.basic).to eq(["username", "password"])
|
16
16
|
end
|
17
17
|
|
18
18
|
it "sets the authentication type to :basic" do
|
19
19
|
auth.basic "username", "password"
|
20
|
-
auth.type.
|
20
|
+
expect(auth.type).to eq(:basic)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#basic?" do
|
25
25
|
it "defaults to return false" do
|
26
|
-
auth.
|
26
|
+
expect(auth).not_to be_basic
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns true for HTTP basic auth" do
|
30
30
|
auth.basic "username", "password"
|
31
|
-
auth.
|
31
|
+
expect(auth).to be_basic
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#digest" do
|
36
36
|
it "lets you specify the digest auth credentials" do
|
37
37
|
auth.digest "username", "password"
|
38
|
-
auth.digest.
|
38
|
+
expect(auth.digest).to eq(["username", "password"])
|
39
39
|
end
|
40
40
|
|
41
41
|
it "also accepts an Array of credentials" do
|
42
42
|
auth.digest ["username", "password"]
|
43
|
-
auth.digest.
|
43
|
+
expect(auth.digest).to eq(["username", "password"])
|
44
44
|
end
|
45
45
|
|
46
46
|
it "sets the authentication type to :digest" do
|
47
47
|
auth.digest "username", "password"
|
48
|
-
auth.type.
|
48
|
+
expect(auth.type).to eq(:digest)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe "#digest?" do
|
53
53
|
it "defaults to return false" do
|
54
|
-
auth.
|
54
|
+
expect(auth).not_to be_digest
|
55
55
|
end
|
56
56
|
|
57
57
|
it "returns true for HTTP digest auth" do
|
58
58
|
auth.digest "username", "password"
|
59
|
-
auth.
|
59
|
+
expect(auth).to be_digest
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#gssnegotiate" do
|
64
64
|
it "sets the authentication type to :gssnegotiate" do
|
65
65
|
auth.gssnegotiate
|
66
|
-
auth.type.
|
66
|
+
expect(auth.type).to eq(:gssnegotiate)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "#gssnegotiate?" do
|
71
71
|
it "defaults to return false" do
|
72
|
-
auth.
|
72
|
+
expect(auth).not_to be_gssnegotiate
|
73
73
|
end
|
74
74
|
|
75
75
|
it "returns true for HTTP Negotiate auth" do
|
76
76
|
auth.gssnegotiate
|
77
|
-
auth.
|
77
|
+
expect(auth).to be_gssnegotiate
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
describe "#http?" do
|
82
82
|
it "defaults to return false" do
|
83
|
-
auth.
|
83
|
+
expect(auth).not_to be_http
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns true for HTTP basic auth" do
|
87
87
|
auth.basic "username", "password"
|
88
|
-
auth.
|
88
|
+
expect(auth).to be_http
|
89
89
|
end
|
90
90
|
|
91
91
|
it "returns true for HTTP digest auth" do
|
92
92
|
auth.digest "username", "password"
|
93
|
-
auth.
|
93
|
+
expect(auth).to be_http
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "#ssl" do
|
98
98
|
it "returns the HTTPI::Auth::SSL object" do
|
99
|
-
auth.ssl.
|
99
|
+
expect(auth.ssl).to be_a(HTTPI::Auth::SSL)
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
103
|
describe "#ssl?" do
|
104
104
|
it "defaults to return false" do
|
105
|
-
auth.
|
105
|
+
expect(auth).not_to be_ssl
|
106
106
|
end
|
107
107
|
|
108
108
|
it "returns true for SSL client auth" do
|
109
109
|
auth.ssl.cert_key_file = "spec/fixtures/client_key.pem"
|
110
110
|
auth.ssl.cert_file = "spec/fixtures/client_cert.pem"
|
111
111
|
|
112
|
-
auth.
|
112
|
+
expect(auth).to be_ssl
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
116
|
describe "#type" do
|
117
117
|
it "returns the authentication type" do
|
118
118
|
auth.basic "username", "password"
|
119
|
-
auth.type.
|
119
|
+
expect(auth.type).to eq(:basic)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
describe "#credentials" do
|
124
124
|
it "returns the credentials for HTTP basic auth" do
|
125
125
|
auth.basic "username", "basic"
|
126
|
-
auth.credentials.
|
126
|
+
expect(auth.credentials).to eq(["username", "basic"])
|
127
127
|
end
|
128
128
|
|
129
129
|
it "returns the credentials for HTTP digest auth" do
|
130
130
|
auth.digest "username", "digest"
|
131
|
-
auth.credentials.
|
131
|
+
expect(auth.credentials).to eq(["username", "digest"])
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
describe "#ntlm" do
|
136
136
|
it "lets you specify the ntlm auth credentials" do
|
137
137
|
auth.ntlm "username", "password"
|
138
|
-
auth.ntlm.
|
138
|
+
expect(auth.ntlm).to eq(["username", "password"])
|
139
139
|
end
|
140
140
|
|
141
141
|
it "also accepts an Array of credentials" do
|
142
142
|
auth.ntlm ["username", "password"]
|
143
|
-
auth.ntlm.
|
143
|
+
expect(auth.ntlm).to eq(["username", "password"])
|
144
144
|
end
|
145
145
|
|
146
146
|
it "sets the authentication type to :ntlm" do
|
147
147
|
auth.ntlm "username", "password"
|
148
|
-
auth.type.
|
148
|
+
expect(auth.type).to eq(:ntlm)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
152
|
describe "#ntlm?" do
|
153
153
|
it "defaults to return false" do
|
154
|
-
auth.
|
154
|
+
expect(auth).not_to be_ntlm
|
155
155
|
end
|
156
156
|
|
157
157
|
it "returns true for HTTP ntlm auth" do
|
158
158
|
auth.ntlm "username", "password"
|
159
|
-
auth.
|
159
|
+
expect(auth).to be_ntlm
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|