File tree 5 files changed +74
-16
lines changed
5 files changed +74
-16
lines changed Original file line number Diff line number Diff line change 3
3
require 'pact_broker/logging'
4
4
require 'pact_broker/messages'
5
5
require 'net/http'
6
+ require 'pact_broker/webhooks/redact_logs'
6
7
7
8
module PactBroker
8
9
@@ -56,7 +57,7 @@ def execute
56
57
execution_logger . info "HTTP/1.1 #{ method . upcase } #{ url_with_credentials } "
57
58
58
59
headers . each_pair do | name , value |
59
- execution_logger . info "#{ name } : #{ value } "
60
+ execution_logger . info Webhooks :: RedactLogs . call ( "#{ name } : #{ value } " )
60
61
req [ name ] = value
61
62
end
62
63
@@ -91,9 +92,8 @@ def execute
91
92
92
93
rescue StandardError => e
93
94
logger . error "Error executing webhook #{ uuid } #{ e . class . name } - #{ e . message } "
94
- execution_logger . error "Error executing webhook #{ uuid } #{ e . class . name } - #{ e . message } "
95
95
logger . error e . backtrace . join ( "\n " )
96
- execution_logger . error e . backtrace . join ( " \n " )
96
+ execution_logger . error "Error executing webhook #{ uuid } #{ e . class . name } - #{ e . message } "
97
97
WebhookExecutionResult . new ( nil , logs . string , e )
98
98
end
99
99
end
@@ -118,7 +118,5 @@ def url_with_credentials
118
118
u
119
119
end
120
120
end
121
-
122
121
end
123
-
124
122
end
Original file line number Diff line number Diff line change
1
+ module PactBroker
2
+ module Webhooks
3
+ class RedactLogs
4
+ def self . call logs
5
+ logs . gsub ( /(Authorization: )(.*)/i , '\1[REDACTED]' )
6
+ . gsub ( /(Token: )(.*)/i , '\1[REDACTED]' )
7
+ end
8
+ end
9
+ end
10
+ end
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ module Domain
19
19
WebhookRequest . new (
20
20
method : 'post' ,
21
21
url : url ,
22
- headers : { 'Content-Type' => 'text/plain' } ,
22
+ headers : { 'Content-Type' => 'text/plain' , 'Authorization' => 'foo' } ,
23
23
username : username ,
24
24
password : password ,
25
25
body : body )
@@ -73,9 +73,6 @@ module Domain
73
73
end
74
74
75
75
describe "execution logs" do
76
- before do
77
-
78
- end
79
76
80
77
let ( :logs ) { subject . execute . logs }
81
78
@@ -87,6 +84,10 @@ module Domain
87
84
expect ( logs ) . to include "Content-Type: text/plain"
88
85
end
89
86
87
+ it "redacts potentially sensitive headers" do
88
+ expect ( logs ) . to include "Authorization: [REDACTED]"
89
+ end
90
+
90
91
it "logs the request body" do
91
92
expect ( logs ) . to include body
92
93
end
Original file line number Diff line number Diff line change
1
+ require 'pact_broker/webhooks/redact_logs'
2
+
3
+ module PactBroker
4
+ module Webhooks
5
+ describe RedactLogs do
6
+ describe ".call" do
7
+ let ( :string ) do
8
+ "Authorization: foo\n X-Thing: bar"
9
+ end
10
+
11
+ let ( :x_auth_string ) do
12
+ "X-Authorization: bar foo\n X-Thing: bar"
13
+ end
14
+
15
+ let ( :x_auth_token ) do
16
+ "X-Auth-Token: bar foo\n X-Thing: bar"
17
+ end
18
+
19
+ let ( :x_authorization_token ) do
20
+ "X-Authorization-Token: bar foo\n X-Thing: bar"
21
+ end
22
+
23
+ let ( :string_lower ) do
24
+ "authorization: foo\n X-Thing: bar"
25
+ end
26
+
27
+ it "hides the value of the Authorization header" do
28
+ expect ( RedactLogs . call ( string ) ) . to eq "Authorization: [REDACTED]\n X-Thing: bar"
29
+ end
30
+
31
+ it "hides the value of the X-Authorization header" do
32
+ expect ( RedactLogs . call ( x_auth_string ) ) . to eq "X-Authorization: [REDACTED]\n X-Thing: bar"
33
+ end
34
+
35
+ it "hides the value of the X-Auth-Token header" do
36
+ expect ( RedactLogs . call ( x_auth_token ) ) . to eq "X-Auth-Token: [REDACTED]\n X-Thing: bar"
37
+ end
38
+
39
+ it "hides the value of the X-Authorization-Token header" do
40
+ expect ( RedactLogs . call ( x_authorization_token ) ) . to eq "X-Authorization-Token: [REDACTED]\n X-Thing: bar"
41
+ end
42
+
43
+ it "hides the value of the authorization header" do
44
+ expect ( RedactLogs . call ( string_lower ) ) . to eq "authorization: [REDACTED]\n X-Thing: bar"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
Original file line number Diff line number Diff line change 5
5
RACK_ENV = 'test'
6
6
7
7
$: << File . expand_path ( "../../" , __FILE__ )
8
- require 'rack/test'
8
+
9
9
require 'db'
10
- require 'pact_broker/api'
11
10
require 'tasks/database'
11
+ require 'pact_broker/db'
12
+ raise "Wrong environment!!! Don't run this script!! ENV['RACK_ENV'] is #{ ENV [ 'RACK_ENV' ] } and RACK_ENV is #{ RACK_ENV } " if ENV [ 'RACK_ENV' ] != 'test' || RACK_ENV != 'test'
13
+ PactBroker ::DB . connection = PactBroker ::Database . database = DB ::PACT_BROKER_DB
14
+
15
+ require 'rack/test'
16
+ require 'pact_broker/api'
12
17
require 'rspec/its'
13
18
14
19
Dir . glob ( "./spec/support/**/*.rb" ) { |file | require file }
15
20
16
21
I18n . config . enforce_available_locales = false
17
22
18
23
RSpec . configure do | config |
19
- config . before :suite do
20
- raise "Wrong environment!!! Don't run this script!! ENV['RACK_ENV'] is #{ ENV [ 'RACK_ENV' ] } and RACK_ENV is #{ RACK_ENV } " if ENV [ 'RACK_ENV' ] != 'test' || RACK_ENV != 'test'
21
- PactBroker ::DB . connection = PactBroker ::Database . database = DB ::PACT_BROKER_DB
22
- end
23
-
24
24
config . before :each do
25
25
PactBroker . reset_configuration
26
26
end
You can’t perform that action at this time.
0 commit comments