Perform more redactions in Redis performance bar traces

HMSET and AUTH commands were not properly redacted. This commit
does that and adds a test.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/64309
This commit is contained in:
Stan Hu 2019-07-09 07:07:41 -07:00
parent db1b15e424
commit 3084c37f3e
2 changed files with 42 additions and 2 deletions

View file

@ -37,6 +37,8 @@ end
module Peek
module Views
module RedisDetailed
REDACTED_MARKER = "<redacted>"
def results
super.merge(details: details)
end
@ -57,10 +59,12 @@ module Peek
end
def format_command(cmd)
if cmd.length >= 2 && cmd.first =~ /^auth$/i
cmd[-1] = REDACTED_MARKER
# Scrub out the value of the SET calls to avoid binary
# data or large data from spilling into the view
if cmd.length >= 2 && cmd.first =~ /set/i
cmd[-1] = "<redacted>"
elsif cmd.length >= 3 && cmd.first =~ /set/i
cmd[2..-1] = REDACTED_MARKER
end
cmd.join(' ')

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'spec_helper'
describe Peek::Views::RedisDetailed do
let(:redis_detailed_class) do
Class.new do
include Peek::Views::RedisDetailed
end
end
subject { redis_detailed_class.new }
using RSpec::Parameterized::TableSyntax
where(:cmd, :expected) do
[:auth, 'test'] | 'auth <redacted>'
[:set, 'key', 'value'] | 'set key <redacted>'
[:set, 'bad'] | 'set bad'
[:hmset, 'key1', 'value1', 'key2', 'value2'] | 'hmset key1 <redacted>'
[:get, 'key'] | 'get key'
end
with_them do
it 'scrubs Redis commands', :request_store do
subject.detail_store << { cmd: cmd, duration: 1.second }
expect(subject.details.count).to eq(1)
expect(subject.details.first)
.to eq({
cmd: expected,
duration: 1000
})
end
end
end