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

Update the regex to properly capture the authorisation token #56

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion lib/avatax/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
42 changes: 42 additions & 0 deletions spec/avatax/connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require File.expand_path('../../spec_helper', __FILE__)

describe AvaTax::Connection do
describe "AUTHORIZATION_FILTER_REGEX" do
let(:message) do
<<EOS
Accept: "application/json; charset=utf-8"
User-Agent: "AvaTax Ruby Gem 19.7.0"
X-Avalara-Client: ";;RubySdk;19.7.0;"
Authorization: "Basic #{encoded_token}"
Content-Type: "application/json"
EOS
end

context "a base 64 encoded value ending with =" do
let(:encoded_token) { "YmFzZTY0cGFzc3dvcmQuUmVhbGx5Pwo=" }

it "should match regex" do
expect(message).to match(described_class::AUTHORIZATION_FILTER_REGEX)
end

it "should capture the whole auth token" do
groups = message.match(described_class::AUTHORIZATION_FILTER_REGEX)
expect(groups[2]).to eq(encoded_token)
end
end

context "a base 64 encoded value NOT ending with =" do
let(:encoded_token) { "bm9hcGlrZXlpbjIwMTkK" }

it "should match regex" do
expect(message).to match(described_class::AUTHORIZATION_FILTER_REGEX)
end

it "should capture the whole auth token" do
groups = message.match(described_class::AUTHORIZATION_FILTER_REGEX)
expect(groups[2]).to eq(encoded_token)
end
end
end
end