From 7490788417ff4789c3ea52ec018671110c112a83 Mon Sep 17 00:00:00 2001 From: dbecker-stripe <88861694+dbecker-stripe@users.noreply.github.com> Date: Mon, 27 Mar 2023 09:53:34 -0700 Subject: [PATCH] Optionally pass in `proxy` parameter to Savon (#548) * Optionally pass in `proxy` parameter to Savon Savon will call `to_s` on any `proxy` value passed in so it will treat `nil` like an empty string instead of not using it. This causes requests to fail with an invalid proxy. This change will not pass in a value for `proxy` if the attribute is `nil`. This change also updates history with addition of the proxy attribute. * Updated PR with cleaner way to add the proxy and added testing --------- Co-authored-by: Michael Bianco --- HISTORY.md | 3 +++ lib/netsuite/configuration.rb | 2 +- spec/netsuite/configuration_spec.rb | 10 +++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index f17e3ffd..cc5f16be 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -30,6 +30,9 @@ The following were removed as `fields` since their sublist class is not yet impl * Add `update` action to `File` records (#544) * Expose `errors` after calls to `delete` action (#545) * Add `update_list` action where missing on supported item records (#546) +* Add `proxy` attribute to `NetSuite::Configuration` to set a proxy used by the savon client (#547) + +### Fixed * Ignore `after_submit_failed` status details (>= 2018.2) when collating errors in add action (#550) * Add `NullFieldList` to `SalesOrder` (#552) * Add thread safety to NetSuite configuration and utilities (#549) diff --git a/lib/netsuite/configuration.rb b/lib/netsuite/configuration.rb index 0eaf0ae6..85b36210 100644 --- a/lib/netsuite/configuration.rb +++ b/lib/netsuite/configuration.rb @@ -31,8 +31,8 @@ def connection(params={}, credentials={}, soap_header_extra_info={}) logger: logger, log_level: log_level, log: !silent, # turn off logging entirely if configured - proxy: proxy, }.update(params)) + client.globals.proxy(proxy) if proxy cache_wsdl(client) return client end diff --git a/spec/netsuite/configuration_spec.rb b/spec/netsuite/configuration_spec.rb index 04e06094..9d5f9ee8 100644 --- a/spec/netsuite/configuration_spec.rb +++ b/spec/netsuite/configuration_spec.rb @@ -519,13 +519,21 @@ expect(config.proxy).to be_nil end + it 'does not pass in nil proxy to savon' do + connection = config.connection + + expect(connection.globals.include?(:proxy)).to eql(false) + end + it 'can be set with proxy=' do config.proxy = "https://my-proxy" expect(config.proxy).to eql("https://my-proxy") # ensure no exception is raised - config.connection + connection = config.connection + + expect(connection.globals.include?(:proxy)).to eql(true) end it 'can be set with proxy(value)' do