15
15
package kafka
16
16
17
17
import (
18
+ "bytes"
18
19
"errors"
19
20
"testing"
20
21
@@ -24,6 +25,7 @@ import (
24
25
"github.com/stretchr/testify/require"
25
26
"github.com/uber/jaeger-lib/metrics"
26
27
"go.uber.org/zap"
28
+ "go.uber.org/zap/zapcore"
27
29
28
30
"github.com/jaegertracing/jaeger/pkg/config"
29
31
kafkaConfig "github.com/jaegertracing/jaeger/pkg/kafka/producer"
@@ -105,6 +107,58 @@ func TestKafkaFactoryMarshallerErr(t *testing.T) {
105
107
assert .Error (t , f .Initialize (metrics .NullFactory , zap .NewNop ()))
106
108
}
107
109
110
+ func TestKafkaFactoryDoesNotLogPassword (t * testing.T ) {
111
+ tests := []struct {
112
+ name string
113
+ flags []string
114
+ }{
115
+ {
116
+ name : "plaintext" ,
117
+ flags : []string {
118
+ "--kafka.producer.authentication=plaintext" ,
119
+ "--kafka.producer.plaintext.username=username" ,
120
+ "--kafka.producer.plaintext.password=SECRET" ,
121
+ "--kafka.producer.brokers=localhost:9092" ,
122
+ },
123
+ },
124
+ {
125
+ name : "kerberos" ,
126
+ flags : []string {
127
+ "--kafka.producer.authentication=kerberos" ,
128
+ "--kafka.producer.kerberos.username=username" ,
129
+ "--kafka.producer.kerberos.password=SECRET" ,
130
+ "--kafka.producer.brokers=localhost:9092" ,
131
+ },
132
+ },
133
+ }
134
+
135
+ for _ , test := range tests {
136
+ t .Run (test .name , func (t * testing.T ) {
137
+
138
+ f := NewFactory ()
139
+ v , command := config .Viperize (f .AddFlags )
140
+ err := command .ParseFlags (test .flags )
141
+ require .NoError (t , err )
142
+
143
+ f .InitFromViper (v )
144
+
145
+ parsedConfig := f .Builder .(* kafkaConfig.Configuration )
146
+ f .Builder = & mockProducerBuilder {t : t , Configuration : * parsedConfig }
147
+ logbuf := & bytes.Buffer {}
148
+ logger := zap .New (zapcore .NewCore (
149
+ zapcore .NewJSONEncoder (zap .NewProductionEncoderConfig ()),
150
+ zapcore .AddSync (logbuf ),
151
+ zap .NewAtomicLevel (),
152
+ ))
153
+ err = f .Initialize (metrics .NullFactory , logger )
154
+ require .NoError (t , err )
155
+ logger .Sync ()
156
+
157
+ require .NotContains (t , logbuf .String (), "SECRET" , "log output must not contain password in clear text" )
158
+ })
159
+ }
160
+ }
161
+
108
162
func TestInitFromOptions (t * testing.T ) {
109
163
f := NewFactory ()
110
164
o := Options {Topic : "testTopic" , Config : kafkaConfig.Configuration {Brokers : []string {"host" }}}
0 commit comments