Skip to content

Commit bcd3c74

Browse files
committed
address comment
1 parent 33e3b69 commit bcd3c74

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cns/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,13 @@ func verifyPeerCertificate(verifiedChains [][]*x509.Certificate, clientSubjectNa
184184
}
185185

186186
// maskHalf of the DNS names
187+
maskedDNS := make([]string, len(dnsNames))
187188
for i, dns := range dnsNames {
188-
dnsNames[i] = maskHalf(dns)
189+
maskedDNS[i] = maskHalf(dns)
189190
}
190191

191192
return errors.Errorf("Failed to verify client certificate subject name during mTLS, clientSubjectName: %s, client cert SANs: %+v, clientCN: %s",
192-
clientSubjectName, dnsNames, maskHalf(clientCN))
193+
clientSubjectName, maskedDNS, maskHalf(clientCN))
193194
}
194195

195196
// maskHalf masks half of the input string with asterisks.

cns/service_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,29 +207,29 @@ func TestNewService(t *testing.T) {
207207
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, tlsURL, http.NoBody)
208208
require.NoError(t, err)
209209
resp, err := client.Do(req)
210-
t.Cleanup(func() {
211-
if resp != nil && resp.Body != nil {
212-
resp.Body.Close()
213-
}
214-
})
215210
if tc.handshakeFailureExpected {
216211
require.Error(t, err)
217212
require.ErrorContains(t, err, "Failed to verify client certificate subject name during mTLS")
218213
} else {
219214
require.NoError(t, err)
215+
t.Cleanup(func() {
216+
if resp != nil && resp.Body != nil {
217+
resp.Body.Close()
218+
}
219+
})
220220
}
221221

222222
// HTTP listener
223223
httpClient := &http.Client{}
224224
req, err = http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://localhost:10090", http.NoBody)
225225
require.NoError(t, err)
226226
resp, err = httpClient.Do(req)
227+
require.NoError(t, err)
227228
t.Cleanup(func() {
228229
if resp != nil && resp.Body != nil {
229230
resp.Body.Close()
230231
}
231232
})
232-
require.NoError(t, err)
233233

234234
// Cleanup
235235
svc.Uninitialize()

0 commit comments

Comments
 (0)