Skip to content

Commit d0a7571

Browse files
authored
Merge pull request #28 from github/general-updates
General updates and new supported redaction classes
2 parents c4ff4ec + db3a430 commit d0a7571

20 files changed

+76
-41
lines changed

Gemfile.lock

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (7.1.2)
4+
activesupport (7.1.3.2)
55
base64
66
bigdecimal
77
concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -13,8 +13,8 @@ GEM
1313
tzinfo (~> 2.0)
1414
ast (2.4.2)
1515
base64 (0.2.0)
16-
bigdecimal (3.1.4)
17-
concurrent-ruby (1.2.2)
16+
bigdecimal (3.1.6)
17+
concurrent-ruby (1.2.3)
1818
connection_pool (2.4.1)
1919
diff-lcs (1.5.1)
2020
docile (1.4.0)
@@ -29,7 +29,7 @@ GEM
2929
json (2.7.1)
3030
language_server-protocol (3.17.0.3)
3131
logger (1.6.0)
32-
minitest (5.20.0)
32+
minitest (5.22.2)
3333
mutex_m (0.2.0)
3434
parallel (1.24.0)
3535
parser (3.3.0.5)
@@ -43,7 +43,7 @@ GEM
4343
rdoc (6.6.2)
4444
psych (>= 4.0.0)
4545
regexp_parser (2.9.0)
46-
reline (0.4.2)
46+
reline (0.4.3)
4747
io-console (~> 0.5)
4848
rexml (3.2.6)
4949
rspec (3.13.0)
@@ -58,7 +58,7 @@ GEM
5858
rspec-mocks (3.13.0)
5959
diff-lcs (>= 1.2.0, < 2.0)
6060
rspec-support (~> 3.13.0)
61-
rspec-support (3.13.0)
61+
rspec-support (3.13.1)
6262
rubocop (1.60.2)
6363
json (~> 2.3)
6464
language_server-protocol (>= 3.17.0)
@@ -83,10 +83,11 @@ GEM
8383
rubocop-performance (1.20.2)
8484
rubocop (>= 1.48.1, < 2.0)
8585
rubocop-ast (>= 1.30.0, < 2.0)
86-
rubocop-rails (2.22.1)
86+
rubocop-rails (2.23.1)
8787
activesupport (>= 4.2.0)
8888
rack (>= 1.1)
8989
rubocop (>= 1.33.0, < 2.0)
90+
rubocop-ast (>= 1.30.0, < 2.0)
9091
rubocop-rspec (2.26.1)
9192
rubocop (~> 1.40)
9293
rubocop-capybara (~> 2.17)

lib/redacting_logger.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class RedactingLogger < Logger
2020
def initialize(
2121
logdev = $stdout,
2222
shift_age = 0,
23-
shift_size = 1048576,
23+
shift_size = 1_048_576,
2424
redact_patterns: [],
2525
redacted_msg: "[REDACTED]",
2626
use_default_patterns: true,
@@ -43,18 +43,18 @@ def add(severity, message = nil, progname = nil)
4343
@redact_patterns.each do |pattern|
4444
case message
4545

46-
when String
46+
when String, Symbol, Numeric
4747
message = message.to_s.gsub(pattern, @redacted_msg)
4848

4949
when Array
5050
message = message.map do |m|
51-
m = m.to_s.gsub(pattern, @redacted_msg)
51+
m.to_s.gsub(pattern, @redacted_msg)
5252
end
5353

5454
when Hash
55-
message = message.map do |k, v|
56-
[k, v.to_s.gsub(pattern, @redacted_msg)]
57-
end.to_h
55+
message = message.transform_values do |v|
56+
v.to_s.gsub(pattern, @redacted_msg)
57+
end
5858
end
5959
end
6060

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module RedactingLogger
44
module Version
5-
VERSION = "1.1.0"
5+
VERSION = "1.2.0"
66
end
77
end

script/bootstrap

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,33 @@ OFF='\033[0m'
55
RED='\033[0;31m'
66
GREEN='\033[0;32m'
77
BLUE='\033[0;34m'
8+
PURPLE='\033[0;35m'
89

910
set -e # Prevent any kind of script failures
1011

12+
# if any of the following env vars are set, use them for the APP_ENV value
13+
if [ -n "$APP_ENV" ]; then
14+
export APP_ENV="$APP_ENV"
15+
elif [ -n "$ENV" ]; then
16+
export APP_ENV="$ENV"
17+
elif [ -n "$ENVIRONMENT" ]; then
18+
export APP_ENV="$ENVIRONMENT"
19+
elif [ -n "$RAILS_ENV" ]; then
20+
export APP_ENV="$RAILS_ENV"
21+
elif [ -n "$RACK_ENV" ]; then
22+
export APP_ENV="$RACK_ENV"
23+
fi
24+
25+
# set the working directory to the root of the project
1126
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
27+
28+
# set the ruby version to the one specified in the .ruby-version file
1229
[ -z "$RBENV_VERSION" ] && export RBENV_VERSION=$(cat "$DIR/.ruby-version")
30+
31+
# set the app environment to development if it's not set
1332
[ -z "$APP_ENV" ] && export APP_ENV="development"
33+
34+
# set the path to include the rbenv shims if they exist
1435
[ -d "/usr/share/rbenv/shims" ] && export PATH=/usr/share/rbenv/shims:$PATH
1536

1637
TRASHDIR=$(mktemp -d /tmp/bootstrap.XXXXXXXXXXXXXXXXX)
@@ -22,11 +43,12 @@ cleanup() {
2243
trap cleanup EXIT
2344

2445
# Bootstrap gem dependencies.
25-
echo -e "💎 ${BLUE}Installing Gems...${OFF}"
2646
if [ "$APP_ENV" == "production" ]; then
27-
bundle install --path vendor/gems --local --without development
28-
bundle binstubs --all
47+
echo -e "💎 ${BLUE}Installing Gems for ${GREEN}production${BLUE}...${OFF}"
48+
BUNDLE_WITHOUT=development bundle install --local
49+
BUNDLE_WITHOUT=development bundle binstubs --all
2950
else
30-
bundle install --path vendor/gems --local --with development
51+
echo -e "💎 ${BLUE}Installing Gems for ${PURPLE}development${BLUE}...${OFF}"
52+
bundle install --local
3153
bundle binstubs --all
32-
fi
54+
fi

script/test

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,12 @@ export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
4949
if [[ -z $no_bootstrap ]]; then
5050
# bootstrap
5151
echo -e "\n🥾 ${BLUE}Bootstrapping: $(date "+%H:%M:%S")${OFF}\n"
52-
echo "%%%FOLD {bootstrap}%%%"
5352
cd "$DIR"
5453
script/bootstrap
55-
echo "%%%END FOLD%%%"
5654
else
5755
echo -e "\n⏩ ${BLUE}Skipping Bootstrap${OFF}"
5856
fi
5957

60-
# jump out to the lint build
61-
if [[ "$JOB_NAME" = *-lint ]]; then
62-
exec script/cibuild-lint
63-
fi
64-
6558
# Run Rubocop
6659
if [[ -z $no_linter ]]; then
6760
echo -e "\n🤖 ${BLUE}Running Rubocop: $(date "+%H:%M:%S")${OFF}\n"

spec/lib/redacting_logger_spec.rb

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,74 +43,94 @@
4343

4444
context "#add" do
4545
let(:logdev) { StringIO.new }
46-
let(:logger) { RedactingLogger.new(logdev, redact_patterns: [/secret/, /password/, /token_[A-Z]{5}/]) }
46+
let(:logger) { RedactingLogger.new(logdev, redact_patterns: [/secret/, /password/, /token_[A-Z]{5}/, /999999999/]) }
4747

4848
[
4949
{
5050
case: "secret message",
5151
message: "This is a secret password",
52-
expected_message: "This is a [REDACTED] [REDACTED]",
52+
expected_message: "This is a [REDACTED] [REDACTED]"
5353
},
5454
{
5555
case: "secret progname",
5656
progname: "secret progname",
57-
expected_progname: "[REDACTED] progname",
57+
expected_progname: "[REDACTED] progname"
5858
},
5959
{
6060
case: "secret substring",
6161
message: "This is a supersecretmessage",
62-
expected_message: "This is a super[REDACTED]message",
62+
expected_message: "This is a super[REDACTED]message"
6363
},
6464
{
6565
case: "github token",
6666
message: "token ghp_aBcdeFghIjklMnoPqRSTUvwXYZ1234567890",
67-
expected_message: "token [REDACTED]",
67+
expected_message: "token [REDACTED]"
6868
},
6969
{
7070
case: "github token hidden in another string",
7171
message: "token ghp_aBcdeFghIjklMnoPqRSTUvwXYZ1234567890ohnothisisnotgood",
72-
expected_message: "token [REDACTED]",
72+
expected_message: "token [REDACTED]"
7373
},
7474
{
7575
case: "fine-grained github pat",
7676
message: "token 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",
77-
expected_message: "token [REDACTED]",
77+
expected_message: "token [REDACTED]"
7878
},
7979
{
8080
case: "github action pat",
8181
message: "token ghs_1234567890abcdefghijklmnopqrstuvwxyz123456",
82-
expected_message: "token [REDACTED]123456",
82+
expected_message: "token [REDACTED]123456"
8383
},
8484
{
8585
case: "custom token",
8686
message: "token token_ABCDE",
87-
expected_message: "token [REDACTED]",
87+
expected_message: "token [REDACTED]"
8888
},
8989
{
9090
case: "custom token only if long enough",
9191
message: "token token_ABCD",
92-
expected_message: "token token_ABCD",
92+
expected_message: "token token_ABCD"
9393
},
9494
{
9595
case: "JWT token",
9696
message: "token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
97-
expected_message: "token [REDACTED]",
97+
expected_message: "token [REDACTED]"
9898
},
9999
{
100100
case: "RSA private key",
101101
message: "token #{File.read("spec/fixtures/fake.private_key")}",
102-
expected_message: "token [REDACTED]-\n",
102+
expected_message: "token [REDACTED]-\n"
103103
},
104104
{
105105
case: "list of messages",
106106
message: ["this", "is", "a", "secret"],
107-
expected_message: ["this", "is", "a", "[REDACTED]"],
107+
expected_message: ["this", "is", "a", "[REDACTED]"]
108108
},
109109
{
110110
case: "hash of messages",
111111
message: { this: "is", "a" => "secret" },
112-
expected_message: { this: "is", "a" => "[REDACTED]" },
112+
expected_message: { this: "is", "a" => "[REDACTED]" }
113113
},
114+
{
115+
case: "hash of messages more complex",
116+
message: { this: "is", "a" => "super top secret" },
117+
expected_message: { this: "is", "a" => "super top [REDACTED]" }
118+
},
119+
{
120+
case: "redacts from a symbol",
121+
message: :top_secret,
122+
expected_message: "top_[REDACTED]"
123+
},
124+
{
125+
case: "redacts from a Numeric full match",
126+
message: 999_999_999,
127+
expected_message: "[REDACTED]"
128+
},
129+
{
130+
case: "redacts from a Numeric match with extra numbers",
131+
message: 123_999_999_999_123,
132+
expected_message: "123[REDACTED]123"
133+
}
114134
].each do |test|
115135
it "redacts #{test[:case]}" do
116136
expect_any_instance_of(Logger).to receive(:add).with(0, test[:expected_message], test[:expected_progname])
@@ -126,6 +146,5 @@
126146

127147
expect(log_output).to match(/This is a \[REDACTED\] \[REDACTED\]/)
128148
end
129-
130149
end
131150
end
-251 KB
Binary file not shown.
252 KB
Binary file not shown.

vendor/cache/bigdecimal-3.1.4.gem

-85 KB
Binary file not shown.

vendor/cache/bigdecimal-3.1.6.gem

86 KB
Binary file not shown.

0 commit comments

Comments
 (0)