search_flip 3.7.0 → 3.7.2

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
  SHA256:
3
- metadata.gz: 06f3e293add0a92612ea73a6b8d448cc3866f30c908d96af5700466254b779d1
4
- data.tar.gz: 158f3cf97a4ac2443a38d71f61764e7b10e9ba9df21883722e1fa5e300f5d9ca
3
+ metadata.gz: d8c5d0e833c92cf4584fe620634d0c2633cc82248a5cae91c256799d280057f5
4
+ data.tar.gz: 62f5f4944c3a1dc823f75f9bcede05c69ab103d19ae19cfec8f3c518a3829723
5
5
  SHA512:
6
- metadata.gz: 83e349b1b4f9a67335b71e2d818649e4550fe42ae39d354aae9ca078f7c484e37169e33eea5bd7802002e09e7efbc41f09e67fbb7024d7541037af7dd7081d8f
7
- data.tar.gz: 559742084c2374b6c66f1ec3c9edd3c4193d897b3b2df2c3935e5a2587bf558aaf062fcb9428b2601b33abe0ab79c6b46e6c100ef3b1a25e845461a053da293f
6
+ metadata.gz: 5480c57d7d814d96903aab184a82831d4f78d3613249eb8c6951992deaf873bba00ee3d5f8053050775973ac70cb2fc4665b7b15503634b53e853b8d0c29b198
7
+ data.tar.gz: 648f80a25a38e6ec50ab3ecec25a4b6dee92902804c6ee82409d7084c27527cea9788458f5e674dcbf2d0eea5aef401a13e3f1a3b23bd2e6ef1c5659e3a915d3
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
 
2
2
  # CHANGELOG
3
3
 
4
+ ## v3.7.2
5
+
6
+ * Fix wrong AWS signatures by generating the json before passing it to http-rb
7
+
8
+ ## v3.7.1
9
+
10
+ * Fix thread-safety issue of http-rb
11
+
4
12
  ## v3.7.0
5
13
 
6
14
  * Add `SearchFlip::Connection#bulk` to allow more clean bulk indexing to
@@ -37,7 +37,6 @@ module SearchFlip
37
37
  }
38
38
 
39
39
  signature_request[:body] = options[:body] if options.key?(:body)
40
- signature_request[:body] = options[:json].respond_to?(:to_str) ? options[:json] : JSON.generate(options[:json]) if options[:json]
41
40
 
42
41
  signature = signer.sign_request(signature_request)
43
42
 
@@ -58,8 +58,22 @@ module SearchFlip
58
58
  private
59
59
 
60
60
  def execute(method, uri, options = {})
61
- final_request = plugins.inject(self) { |res, cur| cur.call(res, method, uri, options) }
62
- response = final_request.request.send(method, uri, options)
61
+ opts = options.dup
62
+ final_request = self
63
+
64
+ if opts[:json]
65
+ # Manually generate and pass the json body to http-rb to guarantee that
66
+ # we have the same json which is used for aws signatures and to
67
+ # guarantee that json is always generated as stated in the config
68
+
69
+ opts[:body] = JSON.generate(opts.delete(:json))
70
+ final_request = final_request.headers(content_type: "application/json")
71
+ end
72
+
73
+ final_request = plugins.inject(final_request) { |res, cur| cur.call(res, method, uri, opts) }
74
+ final_request = final_request.headers({}) # Prevent thread-safety issue of http-rb: https://github.com/httprb/http/issues/558
75
+
76
+ response = final_request.request.send(method, uri, opts)
63
77
 
64
78
  raise SearchFlip::ResponseError.new(code: response.code, body: response.body.to_s) unless response.status.success?
65
79
 
@@ -1,3 +1,3 @@
1
1
  module SearchFlip
2
- VERSION = "3.7.0"
2
+ VERSION = "3.7.2"
3
3
  end
@@ -29,15 +29,17 @@ RSpec.describe SearchFlip::AwsSigv4Plugin do
29
29
  end
30
30
 
31
31
  it "feeds the http method, full url and body to the signer" do
32
+ body = JSON.generate(key: "value")
33
+
32
34
  signing_request = {
33
35
  http_method: "GET",
34
36
  url: "http://localhost/index?param=value",
35
- body: JSON.generate(key: "value")
37
+ body: body
36
38
  }
37
39
 
38
40
  expect(plugin.signer).to receive(:sign_request).with(signing_request).and_call_original
39
41
 
40
- plugin.call(client, :get, "http://localhost/index", params: { param: "value" }, json: { key: "value" })
42
+ plugin.call(client, :get, "http://localhost/index", params: { param: "value" }, body: body)
41
43
  end
42
44
  end
43
45
  end
@@ -36,6 +36,12 @@ RSpec.describe SearchFlip::HTTPClient do
36
36
 
37
37
  expect(SearchFlip::HTTPClient.new.send(method, "http://localhost/path", body: "body", params: { key: "value" }).body.to_s).to eq("success")
38
38
  end
39
+
40
+ it "generates json, passes it as body and sets the content type when the json option is used" do
41
+ stub_request(method, "http://localhost/path").with(body: '{"key":"value"}', headers: { "Content-Type" => "application/json" }).to_return(body: "success")
42
+
43
+ expect(SearchFlip::HTTPClient.new.send(method, "http://localhost/path", json: { "key" => "value" }).body.to_s).to eq("success")
44
+ end
39
45
  end
40
46
  end
41
47
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_flip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0
4
+ version: 3.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Vetter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-27 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord