restforce 6.2.0 → 6.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f7a29ac5ff461f9db1f386570aceebfa30244ec519ccd26320e6255cdaddc57
4
- data.tar.gz: 556b7407db043fe2a3d5e9fe9183be767693cacacd31fe8ac492aca9fd195194
3
+ metadata.gz: 18f985dc2a3f2b1776f442009e24453e35c19d946f1d0f6ecdd42af56693c8ca
4
+ data.tar.gz: a9ab15688f2eaf7122b57bdca9bdbd54724983f6c38ee311aed095cd7ed3c950
5
5
  SHA512:
6
- metadata.gz: '0585185aed0e16fea289b78ccb16122306186901195daa5d2b323dedcbb4999e5760910e5d8ceb7966424b8e4d636d20c92f61bcc283f1fe75de3857ca35d68b'
7
- data.tar.gz: b17650d7d7984b0b412c2c678a49d61d8d69fc961454aad313c4a8c1ed25ea49f04d68b1d658bb4464b4514f81118f1e69392465a541f0431571d60096e9d9c0
6
+ metadata.gz: 22bdd50789784b18f20dabaa86358db0d05e37e630770ea70da379b5c3410059b8b003e7e8a26347c3ee0141f8b81dc1d422d796454e32bca7531b9f81f72041
7
+ data.tar.gz: 520de3d9f192d6f658fc8bca961975550432054b8c6db5710a5198bb7947c0b485b5a9ff112a1e4cf1848a13344f6cdc0adb2ef498a2ea5175c76582f4bdd395
@@ -10,7 +10,7 @@ jobs:
10
10
  # For v2.0.x, we test v2.0.0 and v2.0.1 because v2.0.0 has a special behaviour where
11
11
  # the Net::HTTP adapter is not included. See
12
12
  # https://github.com/lostisland/faraday/blob/main/UPGRADING.md#faraday-20.
13
- faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.1', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.0', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.0', '2.6.0', '2.7.0']
13
+ faraday_version: ['1.1.0', '1.2.0', '1.3.1', '1.4.3', '1.5.1', '1.6.0', '1.7.2', '1.8.0', '1.9.3', '1.10.3', '2.0.0', '2.0.1', '2.1.0', '2.2.0', '2.3.0', '2.4.0', '2.5.2', '2.6.0', '2.7.4']
14
14
  env:
15
15
  FARADAY_VERSION: ~> ${{ matrix.faraday_version }}
16
16
  steps:
@@ -24,4 +24,4 @@ jobs:
24
24
  - name: Install dependencies
25
25
  run: bundle install
26
26
  - name: Run RSpec tests
27
- run: bundle exec rspec
27
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -19,3 +19,6 @@ tmp
19
19
  .rspec
20
20
  .ruby-version
21
21
  *.swp
22
+ .idea
23
+ Vagrantfile
24
+ .vagrant/
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 6.2.2 (Mar 24 2023)
2
+
3
+ * Handle the `INSUFFICIENT_ACCESS` error returned by the Salesforce API (@timrogers, @nstuart-at-salesforce)
4
+
5
+ # 6.2.1 (Jan 18 2023)
6
+
7
+ * When a response claims to be gzipped but isn't, return the body as it is and don't explode (@timrogers)
8
+
1
9
  # 6.2.0 (Jan 18 2023)
2
10
 
3
11
  * Add support for `faraday` v2.7.x (@timrogers)
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.7.3')
7
7
 
8
8
  # Enable us to explicitly pick a Faraday version when running tests
9
9
  gem 'faraday', faraday_version
10
- gem 'faraday-typhoeus', '~> 0.2.1' unless faraday_version.start_with?("~> 1")
10
+ gem 'faraday-typhoeus', '~> 1.0.0' unless faraday_version.start_with?("~> 1")
11
11
  gem 'faye' unless RUBY_PLATFORM == 'java'
12
12
  gem 'guard-rspec'
13
13
  gem 'guard-rubocop'
@@ -17,6 +17,6 @@ gem 'rspec', '~> 3.12.0'
17
17
  gem 'rspec-collection_matchers', '~> 1.2.0'
18
18
  gem 'rspec-its', '~> 1.3.0'
19
19
  gem 'rspec_junit_formatter', '~> 0.6.0'
20
- gem 'rubocop', '~> 1.43.0'
20
+ gem 'rubocop', '~> 1.48.0'
21
21
  gem 'simplecov', '~> 0.22.0'
22
22
  gem 'webmock', '~> 3.18.1'
data/README.md CHANGED
@@ -27,7 +27,7 @@ Features include:
27
27
 
28
28
  Add this line to your application's Gemfile:
29
29
 
30
- gem 'restforce', '~> 6.2.0'
30
+ gem 'restforce', '~> 6.2.2'
31
31
 
32
32
  And then execute:
33
33
 
@@ -112,12 +112,13 @@ The `id` field can be used to [uniquely identify](https://developer.salesforce.c
112
112
  If you prefer to use a username and password to authenticate:
113
113
 
114
114
  ```ruby
115
- client = Restforce.new(username: 'foo',
116
- password: 'bar',
117
- security_token: 'security token',
118
- client_id: 'client_id',
119
- client_secret: 'client_secret',
120
- api_version: '41.0')
115
+ client = Restforce.new(username: config['username'],
116
+ password: config['password'],
117
+ instance_url: config['instance_url'],
118
+ host: config['host'], # https://test.salesforce.com for sandbox (optional)
119
+ client_id: config['client_key'], # Salesforce Client Key
120
+ client_secret: config['client_secret'], # Salesforce Client Secret
121
+ api_version: '55.0')
121
122
  ```
122
123
 
123
124
  #### JWT Bearer Token
@@ -57,6 +57,11 @@ module Restforce
57
57
  #
58
58
  # :request_headers - A hash containing custom headers that will be
59
59
  # appended to each request
60
+ #
61
+ # :clear_authorization_header - A boolean that when set to true will cause
62
+ # the Faraday::FollowRedirects middleware to
63
+ # omit the auth header when following
64
+ # redirects (default: false)
60
65
 
61
66
  def initialize(opts = {})
62
67
  raise ArgumentError, 'Please specify a hash of options' unless opts.is_a?(Hash)
@@ -20,6 +20,8 @@ module Restforce
20
20
  private
21
21
 
22
22
  # Internal: Internal faraday connection where all requests go through
23
+ # rubocop:disable Metrics/AbcSize
24
+ # rubocop:disable Metrics/BlockLength
23
25
  def connection
24
26
  @connection ||= Faraday.new(options[:instance_url],
25
27
  connection_options) do |builder|
@@ -43,7 +45,10 @@ module Restforce
43
45
  # Caches GET requests.
44
46
  builder.use Restforce::Middleware::Caching, cache, options if cache
45
47
  # Follows 30x redirects.
46
- builder.use Faraday::FollowRedirects::Middleware
48
+ builder.use Faraday::FollowRedirects::Middleware, {
49
+ # Pass the option to clear or send the auth header on redirects through
50
+ clear_authorization_header: options[:clear_authorization_header]
51
+ }
47
52
  # Raises errors for 40x responses.
48
53
  builder.use Restforce::Middleware::RaiseError
49
54
  # Parses returned JSON response into a hash.
@@ -64,6 +69,8 @@ module Restforce
64
69
  builder.adapter adapter
65
70
  end
66
71
  end
72
+ # rubocop:enable Metrics/BlockLength
73
+ # rubocop:enable Metrics/AbcSize
67
74
 
68
75
  def adapter
69
76
  options[:adapter]
@@ -161,6 +161,10 @@ module Restforce
161
161
  # Set use_cache to false to opt in to caching with client.with_caching
162
162
  option :use_cache, default: true
163
163
 
164
+ # Set to true to have Faraday::FollowRedirects middleware omit the auth header
165
+ # when following redirects
166
+ option :clear_authorization_header, default: false
167
+
164
168
  def options
165
169
  self.class.options
166
170
  end
@@ -171,6 +171,8 @@ module Restforce
171
171
 
172
172
  class InsertUpdateDeleteNotAllowedDuringMaintenance < ResponseError; end
173
173
 
174
+ class InsufficientAccess < ResponseError; end
175
+
174
176
  class InsufficientAccessOnCrossReferenceEntity < ResponseError; end
175
177
 
176
178
  class InsufficientAccessOrReadonly < ResponseError; end
@@ -500,6 +502,8 @@ module Restforce
500
502
  "INACTIVE_OWNER_OR_USER" => InactiveOwnerOrUser,
501
503
  "INSERT_UPDATE_DELETE_NOT_ALLOWED_DURING_MAINTENANCE" =>
502
504
  InsertUpdateDeleteNotAllowedDuringMaintenance,
505
+ "INSUFFICIENT_ACCESS" =>
506
+ InsufficientAccess,
503
507
  "INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY" =>
504
508
  InsufficientAccessOnCrossReferenceEntity,
505
509
  "INSUFFICIENT_ACCESS_OR_READONLY" => InsufficientAccessOrReadonly,
@@ -29,4 +29,6 @@ end
29
29
 
30
30
  # This patch is only needed with multipart-post < 2.0.0
31
31
  # 2.0.0 was released in 2013.
32
- require 'restforce/patches/parts' unless Parts::Part.method(:new).arity.abs == 4
32
+ if defined?(Parts) && Parts::Part.method(:new).arity.abs != 4
33
+ require 'restforce/patches/parts'
34
+ end
@@ -28,6 +28,10 @@ module Restforce
28
28
  # Internal: Decompresses a gzipped string.
29
29
  def decompress(body)
30
30
  Zlib::GzipReader.new(StringIO.new(body)).read
31
+ rescue Zlib::GzipFile::Error
32
+ # We thought the response was gzipped, but it wasn't. Return the original
33
+ # body back to the caller. See https://github.com/restforce/restforce/issues/761.
34
+ body
31
35
  end
32
36
  end
33
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restforce
4
- VERSION = '6.2.0'
4
+ VERSION = '6.2.2'
5
5
  end
@@ -62,7 +62,7 @@ describe Restforce do
62
62
  %i[username password security_token client_id client_secret compress
63
63
  timeout oauth_token refresh_token instance_url api_version host mashify
64
64
  authentication_retries proxy_uri authentication_callback ssl
65
- request_headers log_level logger].each do |attr|
65
+ request_headers log_level logger clear_authorization_header].each do |attr|
66
66
  it "allows #{attr} to be set" do
67
67
  Restforce.configure do |config|
68
68
  config.send("#{attr}=", 'foobar')
@@ -17,38 +17,73 @@ describe Restforce::Middleware::Gzip do
17
17
  describe '.call' do
18
18
  subject { lambda { middleware.call(env) } }
19
19
 
20
- before do
21
- app.should_receive(:on_complete) { middleware.on_complete(env) }
22
- app.should_receive(:call) do
23
- env[:body] = gzip fixture('sobject/query_success_response')
24
- env[:response_headers]['Content-Encoding'] = 'gzip'
25
- app
20
+ context 'when the response is gzipped' do
21
+ before do
22
+ app.should_receive(:on_complete) { middleware.on_complete(env) }
23
+ app.should_receive(:call) do
24
+ env[:body] = gzip fixture('sobject/query_success_response')
25
+ env[:response_headers]['Content-Encoding'] = 'gzip'
26
+ app
27
+ end
28
+ end
29
+
30
+ it 'decompresses the body' do
31
+ expect { subject.call }.to change {
32
+ env[:body]
33
+ }.to(fixture('sobject/query_success_response'))
34
+ end
35
+
36
+ context 'when :compress is false' do
37
+ it 'does not set request headers to ask the response to be compressed' do
38
+ expect { subject.call }.
39
+ not_to(change { env[:request_headers]['Accept-Encoding'] })
40
+ end
26
41
  end
27
- end
28
42
 
29
- it 'decompresses the body' do
30
- expect { subject.call }.to change {
31
- env[:body]
32
- }.to(fixture('sobject/query_success_response'))
43
+ context 'when :compress is true' do
44
+ before do
45
+ options[:compress] = true
46
+ end
47
+
48
+ it 'sets request headers to ask the response to be compressed' do
49
+ expect { subject.call }.to change {
50
+ env[:request_headers]['Accept-Encoding']
51
+ }.to('gzip')
52
+ end
53
+ end
33
54
  end
34
55
 
35
- context 'when :compress is false' do
36
- it {
37
- expect { subject.call }.
38
- not_to(change { env[:request_headers]['Accept-Encoding'] })
39
- }
56
+ context 'when the response claims to be gzipped, but is not' do
57
+ before do
58
+ app.should_receive(:on_complete) { middleware.on_complete(env) }
59
+ app.should_receive(:call) do
60
+ env[:body] = fixture('sobject/query_success_response')
61
+ env[:response_headers]['Content-Encoding'] = 'gzip'
62
+ app
63
+ end
64
+ end
65
+
66
+ it 'does not decompress the body' do
67
+ expect { subject.call }.to change {
68
+ env[:body]
69
+ }.to(fixture('sobject/query_success_response'))
70
+ end
40
71
  end
41
72
 
42
- context 'when :compress is true' do
73
+ context 'when the response does not even claim to be gzipped' do
43
74
  before do
44
- options[:compress] = true
75
+ app.should_receive(:on_complete) { middleware.on_complete(env) }
76
+ app.should_receive(:call) do
77
+ env[:body] = fixture('sobject/query_success_response')
78
+ app
79
+ end
45
80
  end
46
81
 
47
- it {
82
+ it 'does not decompress the body' do
48
83
  expect { subject.call }.to change {
49
- env[:request_headers]['Accept-Encoding']
50
- }.to('gzip')
51
- }
84
+ env[:body]
85
+ }.to(fixture('sobject/query_success_response'))
86
+ end
52
87
  end
53
88
  end
54
89
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 6.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rogers
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-01-18 00:00:00.000000000 Z
12
+ date: 2023-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
293
  - !ruby/object:Gem::Version
294
294
  version: '0'
295
295
  requirements: []
296
- rubygems_version: 3.4.1
296
+ rubygems_version: 3.4.7
297
297
  signing_key:
298
298
  specification_version: 4
299
299
  summary: A lightweight Ruby client for the Salesforce REST API