httpi 2.1.1 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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).should match_response(:body => Fixture.xml)
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).should match_response(:body => Fixture.xml)
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).should match_response(:body => Fixture.xml)
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).should match_response(:body => Fixture.xml)
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).should match_response(:body => Fixture.xml)
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).should match_response(:body => Fixture.xml)
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.should include("HTTPI")
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.should eq("get")
28
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("post")
34
- response.headers["Content-Type"].should eq("text/plain")
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.should == 200
40
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("put")
46
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("delete")
52
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("basic-auth")
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.should include("HTTPI")
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.should eq("get")
28
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("post")
34
- response.headers["Content-Type"].should eq("text/plain")
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.should == 200
40
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("put")
46
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("delete")
52
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("basic-auth")
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.should eq("ntlm-auth")
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.should include("HTTPI")
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.should eq("get")
27
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("post")
33
- response.headers["Content-Type"].should eq("text/plain")
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.should == 200
39
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("put")
45
- response.headers["Content-Type"].should eq("text/plain")
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.should eq("delete")
51
- response.headers["Content-Type"].should eq("text/plain")
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
@@ -12,8 +12,8 @@ describe HTTPI::Adapter do
12
12
 
13
13
  adapter.register(name, klass, deps)
14
14
 
15
- HTTPI::Adapter::ADAPTERS[:custom].should include(:class => klass, :deps => deps)
16
- HTTPI::Adapter::ADAPTER_CLASS_MAP[klass].should be(name)
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.should_not == :net_http
28
+ expect(adapter.use).not_to eq(:net_http)
29
29
 
30
30
  adapter.use = :net_http
31
- adapter.use.should == :net_http
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.should == :httpclient
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).should == HTTPI::Adapter::NetHTTP
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).should == HTTPI::Adapter::HTTPClient
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.should == ["username", "password"]
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.should == ["username", "password"]
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.should == :basic
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.should_not be_basic
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.should be_basic
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.should == ["username", "password"]
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.should == ["username", "password"]
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.should == :digest
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.should_not be_digest
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.should be_digest
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.should == :gssnegotiate
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.should_not be_gssnegotiate
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.should be_gssnegotiate
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.should_not be_http
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.should be_http
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.should be_http
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.should be_a(HTTPI::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.should_not be_ssl
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.should be_ssl
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.should == :basic
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.should == ["username", "basic"]
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.should == ["username", "digest"]
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.should == ["username", "password"]
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.should == ["username", "password"]
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.should == :ntlm
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.should_not be_ntlm
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.should be_ntlm
159
+ expect(auth).to be_ntlm
160
160
  end
161
161
  end
162
162