Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/avatax/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module AvaTax

module Connection
private
AUTHORIZATION_FILTER_REGEX = /(Authorization\:\ \"Basic\ )(\w+)\=/

AUTHORIZATION_FILTER_REGEX = /(Authorization:\ "Basic\ )(\w+)/
REMOVED_LABEL = '\1[REMOVED]'

def connection
Expand Down
19 changes: 19 additions & 0 deletions spec/avatax/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path('../../spec_helper', __FILE__)
require 'logger'

describe AvaTax::Request do

Expand All @@ -22,4 +23,22 @@
expect(response.env.request['timeout']).to eq(10)
end
end

describe 'filter credentials from logs' do
let(:string_io) { StringIO.new }
let(:logger) { Logger.new(string_io) }

it 'replaces credentials with a label' do
# Make 'name:pass' string length a multiple of three so the base64
# encoded string will not have padding characters '=' at the end.
@client.username = 'name'
@client.password = 'pass'

@client.custom_logger = logger
response = @client.request(:get, 'path', 'model')

expect(response.env.request_headers).to include('Authorization' => 'Basic bmFtZTpwYXNz')
expect(string_io.string).to match(/Authorization: "Basic \[REMOVED\]"/)
end
end
end