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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01d73a7bae2454b5626a8a50fd7028c62cf071b0
4
- data.tar.gz: e562fc1e85c951f86b4dedb8fbdcc9ebf17487c6
3
+ metadata.gz: fb8410c5b436029e036acecdf7c192f5c9d807de
4
+ data.tar.gz: cc6f08a6ca3df055ba225d6ca696a4102ac05795
5
5
  SHA512:
6
- metadata.gz: 4305d3436bea55aba4e63b131792edb6b6df5715a8537519703930f8774ceb74c878bdf5cb2a06345ad0e96f75879ebb7c40b49d368dab289219b2e05b90a910
7
- data.tar.gz: a52f81b5f4a7b5dad3991bac7720c2af94cfffbf0bf791f101ca794f1cb5a78f96547158b9c06680920693276103d414f602cdbe2e68f58da4f68ea65052519e
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
@@ -1,3 +1,3 @@
1
1
  module Smaak
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -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
- expect(mock_http).to receive(:request).with(mock_req)
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
- expect(mock_http).to receive(:request).with(mock_req).and_return "response"
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.8
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-10 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: persistent-cache