-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redact short and known private tokens
Prior this commit very short private tokens (< 4 chars) triggered: ArgumentError: negative argument Also, if private token was a term which was part of the inspected string only the first occurrence was redacted.
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
RSpec.describe Gitlab::Client do | ||
subject(:client) { described_class.new(options) } | ||
|
||
describe '#inspect' do | ||
subject { client.inspect } | ||
|
||
context 'without private token' do | ||
let(:options) { { private_token: nil } } | ||
|
||
it { is_expected.not_to include('@private_token=') } | ||
end | ||
|
||
context 'with a some lengthy private token' do | ||
let(:options) { { private_token: 'some token' } } | ||
|
||
it { is_expected.to include('@private_token="******oken"') } | ||
end | ||
|
||
context 'with a known private token' do | ||
let(:options) { { private_token: 'endpoint' } } | ||
|
||
it { is_expected.to include('@private_token="****oint"') } | ||
it { is_expected.to include('@endpoint=') } | ||
end | ||
|
||
context 'with empty private token' do | ||
let(:options) { { private_token: '' } } | ||
|
||
it { is_expected.to include('@private_token="****"') } | ||
end | ||
|
||
context 'with short private token' do | ||
let(:options) { { private_token: 'abcd' } } | ||
|
||
it { is_expected.to include('@private_token="****"') } | ||
end | ||
end | ||
end |