Skip to content

Commit

Permalink
fix: preserve first-added token when using payload tokens (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
waltjones authored Nov 16, 2020
1 parent 81e440c commit 4c8f738
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rollbar/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def add_access_token_to_payload(payload)
# Until the delayed sender interface is changed to allow passing dynamic config options,
# this workaround allows the main process to set the token by adding it to the payload.
if (configuration && configuration.use_payload_access_token)
payload['access_token'] = configuration.access_token
payload['access_token'] ||= configuration.access_token
end

payload
Expand Down
37 changes: 37 additions & 0 deletions spec/rollbar/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,43 @@

end # end #build

describe '#build_with' do
context 'when use_payload_access_token is set' do
let(:configuration) do
Rollbar.configure do |c|
c.enabled = true
c.access_token = 'new-token'
c.use_payload_access_token = true
end
Rollbar.configuration
end

context 'when no token is in payload' do
it 'adds token to payload' do
item = described_class.build_with(
{ 'foo' => 'bar' },
{ :configuration => configuration }
)
payload = item.payload

expect(payload['access_token']).to be_eql('new-token')
end
end

context 'when token is in payload' do
it 'preserves original token' do
item = described_class.build_with(
{ 'foo' => 'bar', 'access_token' => 'original-token' },
{ :configuration => configuration }
)
payload = item.payload

expect(payload['access_token']).to be_eql('original-token')
end
end
end
end

describe '#dump' do
context 'with recursing instance in payload and ActiveSupport is enabled' do
class Recurse
Expand Down

0 comments on commit 4c8f738

Please sign in to comment.