Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regex for filtering credentials from logs #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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