smaak 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/smaak/client.rb +2 -1
- data/lib/smaak/version.rb +1 -1
- data/spec/lib/smaak/client_spec.rb +25 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb8410c5b436029e036acecdf7c192f5c9d807de
|
4
|
+
data.tar.gz: cc6f08a6ca3df055ba225d6ca696a4102ac05795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee40f00cbd01cc9c1f8fdfb2a478795c2f5637ab0425aef711181517368480c85fb8fd76eeacb237af3d978974631a106351c714188feb53bd1ab79756da2ace
|
7
|
+
data.tar.gz: 7ed63f1be7a63c2deb37b3692a4665253ee30e0b1b7c60113bfc243b3bbcb23191f03ab5555b6e9aa772315145e4176949ac8f5718d0f19dfcf21491927720ac
|
data/lib/smaak/client.rb
CHANGED
@@ -51,7 +51,8 @@ module Smaak
|
|
51
51
|
adaptor = Smaak::create_adaptor(req)
|
52
52
|
req = (sign_request(identifier, adaptor)).request
|
53
53
|
response = http.request(req)
|
54
|
-
response.body = Smaak::Crypto::decrypt(response.body, @key) if @association_store[identifier]['encrypt']
|
54
|
+
response.body = Smaak::Crypto::decrypt(response.body, @key) if @association_store[identifier]['encrypt'] and response.code[0] == '2'
|
55
|
+
puts "[smaak error]: response from #{identifier} was #{response.code}" if not response.code[0] == '2'
|
55
56
|
response
|
56
57
|
end
|
57
58
|
end
|
data/lib/smaak/version.rb
CHANGED
@@ -151,7 +151,9 @@ describe Smaak::Client do
|
|
151
151
|
mock_req = Net::HTTP::Post.new(url.to_s)
|
152
152
|
expect(Net::HTTP).to receive(:new).with(url.host, url.port).and_return(mock_http)
|
153
153
|
expect(Net::HTTP::Post).to receive(:new).with(url.to_s).and_return(mock_req)
|
154
|
-
|
154
|
+
mock_response = ""
|
155
|
+
allow(mock_response).to receive(:code).and_return "200"
|
156
|
+
expect(mock_http).to receive(:request).with(mock_req).and_return(mock_response)
|
155
157
|
@iut.post(@test_service_identifier, @test_uri, @test_body, false, OpenSSL::SSL::VERIFY_NONE)
|
156
158
|
end
|
157
159
|
|
@@ -164,6 +166,7 @@ describe Smaak::Client do
|
|
164
166
|
expect(Net::HTTP::Post).to receive(:new).with(url.to_s).and_return(mock_req)
|
165
167
|
mock_response = ""
|
166
168
|
expect(mock_response).to receive(:body).and_return ""
|
169
|
+
allow(mock_response).to receive(:code).and_return "200"
|
167
170
|
expect(mock_response).to receive(:body=)
|
168
171
|
expect(mock_http).to receive(:request).with(mock_req).and_return(mock_response)
|
169
172
|
expect(Smaak::Crypto).to receive(:encrypt).and_return ""
|
@@ -172,13 +175,33 @@ describe Smaak::Client do
|
|
172
175
|
@iut.post('encrypted', @test_uri, @test_body, false, OpenSSL::SSL::VERIFY_NONE)
|
173
176
|
end
|
174
177
|
|
178
|
+
it "should decrypt the response body only if the response code is a 200 class code (2XX)" do
|
179
|
+
@iut.add_association('encrypted', @test_service_public_key, @test_service_psk, true)
|
180
|
+
url = URI.parse(@test_uri)
|
181
|
+
mock_http = Net::HTTP.new(url.host, url.port)
|
182
|
+
mock_req = Net::HTTP::Post.new(url.to_s)
|
183
|
+
expect(Net::HTTP).to receive(:new).with(url.host, url.port).and_return(mock_http)
|
184
|
+
expect(Net::HTTP::Post).to receive(:new).with(url.to_s).and_return(mock_req)
|
185
|
+
mock_response = ""
|
186
|
+
expect(mock_response).to receive(:body).and_return ""
|
187
|
+
allow(mock_response).to receive(:code).and_return "200"
|
188
|
+
expect(mock_response).to receive(:body=)
|
189
|
+
expect(mock_http).to receive(:request).with(mock_req).and_return(mock_response)
|
190
|
+
expect(Smaak::Crypto).to receive(:encrypt).and_return ""
|
191
|
+
expect(Smaak::Crypto).to receive(:decrypt).with("", @iut.key)
|
192
|
+
|
193
|
+
@iut.post('encrypted', @test_uri, @test_body, false, OpenSSL::SSL::VERIFY_NONE)
|
194
|
+
end
|
195
|
+
|
175
196
|
it "should return the response" do
|
176
197
|
url = URI.parse(@test_uri)
|
177
198
|
mock_http = Net::HTTP.new(url.host, url.port)
|
178
199
|
mock_req = Net::HTTP::Post.new(url.to_s)
|
179
200
|
expect(Net::HTTP).to receive(:new).with(url.host, url.port).and_return(mock_http)
|
180
201
|
expect(Net::HTTP::Post).to receive(:new).with(url.to_s).and_return(mock_req)
|
181
|
-
|
202
|
+
mock_response = "response"
|
203
|
+
allow(mock_response).to receive(:code).and_return "200"
|
204
|
+
expect(mock_http).to receive(:request).with(mock_req).and_return mock_response
|
182
205
|
expect(@iut.post(@test_service_identifier, @test_uri, @test_body, false, OpenSSL::SSL::VERIFY_NONE)).to eql("response")
|
183
206
|
end
|
184
207
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smaak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernst van Graan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: persistent-cache
|