Skip to content

Commit a82f4c1

Browse files
config: extend validity of testdata certs (#186)
Signed-off-by: Simon Pasquier <[email protected]>
1 parent 5df5c82 commit a82f4c1

8 files changed

+385
-383
lines changed

config/http_config_test.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ const (
3939
TLSCAChainPath = "testdata/tls-ca-chain.pem"
4040
ServerCertificatePath = "testdata/server.crt"
4141
ServerKeyPath = "testdata/server.key"
42-
BarneyCertificatePath = "testdata/barney.crt"
43-
BarneyKeyNoPassPath = "testdata/barney-no-pass.key"
44-
InvalidCA = "testdata/barney-no-pass.key"
42+
ClientCertificatePath = "testdata/client.crt"
43+
ClientKeyNoPassPath = "testdata/client-no-pass.key"
44+
InvalidCA = "testdata/client-no-pass.key"
4545
WrongClientCertPath = "testdata/self-signed-client.crt"
4646
WrongClientKeyPath = "testdata/self-signed-client.key"
4747
EmptyFile = "testdata/empty"
@@ -113,8 +113,8 @@ func TestNewClientFromConfig(t *testing.T) {
113113
clientConfig: HTTPClientConfig{
114114
TLSConfig: TLSConfig{
115115
CAFile: "",
116-
CertFile: BarneyCertificatePath,
117-
KeyFile: BarneyKeyNoPassPath,
116+
CertFile: ClientCertificatePath,
117+
KeyFile: ClientKeyNoPassPath,
118118
ServerName: "",
119119
InsecureSkipVerify: true},
120120
},
@@ -125,8 +125,8 @@ func TestNewClientFromConfig(t *testing.T) {
125125
clientConfig: HTTPClientConfig{
126126
TLSConfig: TLSConfig{
127127
CAFile: TLSCAChainPath,
128-
CertFile: BarneyCertificatePath,
129-
KeyFile: BarneyKeyNoPassPath,
128+
CertFile: ClientCertificatePath,
129+
KeyFile: ClientKeyNoPassPath,
130130
ServerName: "",
131131
InsecureSkipVerify: false},
132132
},
@@ -138,8 +138,8 @@ func TestNewClientFromConfig(t *testing.T) {
138138
BearerToken: BearerToken,
139139
TLSConfig: TLSConfig{
140140
CAFile: TLSCAChainPath,
141-
CertFile: BarneyCertificatePath,
142-
KeyFile: BarneyKeyNoPassPath,
141+
CertFile: ClientCertificatePath,
142+
KeyFile: ClientKeyNoPassPath,
143143
ServerName: "",
144144
InsecureSkipVerify: false},
145145
},
@@ -157,8 +157,8 @@ func TestNewClientFromConfig(t *testing.T) {
157157
BearerTokenFile: BearerTokenFile,
158158
TLSConfig: TLSConfig{
159159
CAFile: TLSCAChainPath,
160-
CertFile: BarneyCertificatePath,
161-
KeyFile: BarneyKeyNoPassPath,
160+
CertFile: ClientCertificatePath,
161+
KeyFile: ClientKeyNoPassPath,
162162
ServerName: "",
163163
InsecureSkipVerify: false},
164164
},
@@ -179,8 +179,8 @@ func TestNewClientFromConfig(t *testing.T) {
179179
},
180180
TLSConfig: TLSConfig{
181181
CAFile: TLSCAChainPath,
182-
CertFile: BarneyCertificatePath,
183-
KeyFile: BarneyKeyNoPassPath,
182+
CertFile: ClientCertificatePath,
183+
KeyFile: ClientKeyNoPassPath,
184184
ServerName: "",
185185
InsecureSkipVerify: false},
186186
},
@@ -274,8 +274,8 @@ func TestMissingBearerAuthFile(t *testing.T) {
274274
BearerTokenFile: MissingBearerTokenFile,
275275
TLSConfig: TLSConfig{
276276
CAFile: TLSCAChainPath,
277-
CertFile: BarneyCertificatePath,
278-
KeyFile: BarneyKeyNoPassPath,
277+
CertFile: ClientCertificatePath,
278+
KeyFile: ClientKeyNoPassPath,
279279
ServerName: "",
280280
InsecureSkipVerify: false},
281281
}
@@ -361,8 +361,8 @@ func TestBearerAuthFileRoundTripper(t *testing.T) {
361361
func TestTLSConfig(t *testing.T) {
362362
configTLSConfig := TLSConfig{
363363
CAFile: TLSCAChainPath,
364-
CertFile: BarneyCertificatePath,
365-
KeyFile: BarneyKeyNoPassPath,
364+
CertFile: ClientCertificatePath,
365+
KeyFile: ClientKeyNoPassPath,
366366
ServerName: "localhost",
367367
InsecureSkipVerify: false}
368368

@@ -384,17 +384,17 @@ func TestTLSConfig(t *testing.T) {
384384
t.Fatalf("Can't create a new TLS Config from a configuration (%s).", err)
385385
}
386386

387-
barneyCertificate, err := tls.LoadX509KeyPair(BarneyCertificatePath, BarneyKeyNoPassPath)
387+
clientCertificate, err := tls.LoadX509KeyPair(ClientCertificatePath, ClientKeyNoPassPath)
388388
if err != nil {
389389
t.Fatalf("Can't load the client key pair ('%s' and '%s'). Reason: %s",
390-
BarneyCertificatePath, BarneyKeyNoPassPath, err)
390+
ClientCertificatePath, ClientKeyNoPassPath, err)
391391
}
392392
cert, err := tlsConfig.GetClientCertificate(nil)
393393
if err != nil {
394394
t.Fatalf("unexpected error returned by tlsConfig.GetClientCertificate(): %s", err)
395395
}
396-
if !reflect.DeepEqual(cert, &barneyCertificate) {
397-
t.Fatalf("Unexpected client certificate result: \n\n%+v\n expected\n\n%+v", cert, barneyCertificate)
396+
if !reflect.DeepEqual(cert, &clientCertificate) {
397+
t.Fatalf("Unexpected client certificate result: \n\n%+v\n expected\n\n%+v", cert, clientCertificate)
398398
}
399399

400400
// non-nil functions are never equal.
@@ -440,18 +440,18 @@ func TestTLSConfigInvalidCA(t *testing.T) {
440440
configTLSConfig: TLSConfig{
441441
CAFile: "",
442442
CertFile: MissingCert,
443-
KeyFile: BarneyKeyNoPassPath,
443+
KeyFile: ClientKeyNoPassPath,
444444
ServerName: "",
445445
InsecureSkipVerify: false},
446-
errorMessage: fmt.Sprintf("unable to use specified client cert (%s) & key (%s):", MissingCert, BarneyKeyNoPassPath),
446+
errorMessage: fmt.Sprintf("unable to use specified client cert (%s) & key (%s):", MissingCert, ClientKeyNoPassPath),
447447
}, {
448448
configTLSConfig: TLSConfig{
449449
CAFile: "",
450-
CertFile: BarneyCertificatePath,
450+
CertFile: ClientCertificatePath,
451451
KeyFile: MissingKey,
452452
ServerName: "",
453453
InsecureSkipVerify: false},
454-
errorMessage: fmt.Sprintf("unable to use specified client cert (%s) & key (%s):", BarneyCertificatePath, MissingKey),
454+
errorMessage: fmt.Sprintf("unable to use specified client cert (%s) & key (%s):", ClientCertificatePath, MissingKey),
455455
},
456456
}
457457

@@ -548,8 +548,8 @@ func TestBasicAuthPasswordFile(t *testing.T) {
548548
func getCertificateBlobs(t *testing.T) map[string][]byte {
549549
files := []string{
550550
TLSCAChainPath,
551-
BarneyCertificatePath,
552-
BarneyKeyNoPassPath,
551+
ClientCertificatePath,
552+
ClientKeyNoPassPath,
553553
ServerCertificatePath,
554554
ServerKeyPath,
555555
WrongClientCertPath,
@@ -608,14 +608,14 @@ func TestTLSRoundTripper(t *testing.T) {
608608
{
609609
// Valid certs.
610610
ca: TLSCAChainPath,
611-
cert: BarneyCertificatePath,
612-
key: BarneyKeyNoPassPath,
611+
cert: ClientCertificatePath,
612+
key: ClientKeyNoPassPath,
613613
},
614614
{
615615
// CA not matching.
616-
ca: BarneyCertificatePath,
617-
cert: BarneyCertificatePath,
618-
key: BarneyKeyNoPassPath,
616+
ca: ClientCertificatePath,
617+
cert: ClientCertificatePath,
618+
key: ClientKeyNoPassPath,
619619

620620
errMsg: "certificate signed by unknown authority",
621621
},
@@ -630,32 +630,32 @@ func TestTLSRoundTripper(t *testing.T) {
630630
{
631631
// CA file empty
632632
ca: EmptyFile,
633-
cert: BarneyCertificatePath,
634-
key: BarneyKeyNoPassPath,
633+
cert: ClientCertificatePath,
634+
key: ClientKeyNoPassPath,
635635

636636
errMsg: "unable to use specified CA cert",
637637
},
638638
{
639639
// cert file empty
640640
ca: TLSCAChainPath,
641641
cert: EmptyFile,
642-
key: BarneyKeyNoPassPath,
642+
key: ClientKeyNoPassPath,
643643

644644
errMsg: "failed to find any PEM data in certificate input",
645645
},
646646
{
647647
// key file empty
648648
ca: TLSCAChainPath,
649-
cert: BarneyCertificatePath,
649+
cert: ClientCertificatePath,
650650
key: EmptyFile,
651651

652652
errMsg: "failed to find any PEM data in key input",
653653
},
654654
{
655655
// Valid certs again.
656656
ca: TLSCAChainPath,
657-
cert: BarneyCertificatePath,
658-
key: BarneyKeyNoPassPath,
657+
cert: ClientCertificatePath,
658+
key: ClientKeyNoPassPath,
659659
},
660660
}
661661

@@ -745,8 +745,8 @@ func TestTLSRoundTripperRaces(t *testing.T) {
745745

746746
var c *http.Client
747747
writeCertificate(bs, TLSCAChainPath, ca)
748-
writeCertificate(bs, BarneyCertificatePath, cert)
749-
writeCertificate(bs, BarneyKeyNoPassPath, key)
748+
writeCertificate(bs, ClientCertificatePath, cert)
749+
writeCertificate(bs, ClientKeyNoPassPath, key)
750750
c, err = NewClientFromConfig(cfg, "test")
751751
if err != nil {
752752
t.Fatalf("Error creating HTTP Client: %v", err)
@@ -785,7 +785,7 @@ func TestTLSRoundTripperRaces(t *testing.T) {
785785
tick := time.NewTicker(10 * time.Millisecond)
786786
<-tick.C
787787
if i%2 == 0 {
788-
writeCertificate(bs, BarneyCertificatePath, ca)
788+
writeCertificate(bs, ClientCertificatePath, ca)
789789
} else {
790790
writeCertificate(bs, TLSCAChainPath, ca)
791791
}

config/testdata/barney-no-pass.key

Lines changed: 0 additions & 27 deletions
This file was deleted.

config/testdata/barney.crt

Lines changed: 0 additions & 96 deletions
This file was deleted.

config/testdata/client-no-pass.key

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC307b8Il9zajKw
3+
mkOih8sfYI+O9gSTvvyQN7Bh+Bu6lLN+XhtRxt+ZqOHfqo30EuPmdScMrqregqup
4+
VPGKgfkXVP3hF5rYdWqZx4XOKdyxbaarZupkAv2gtVNEBSmVSj8urt5WZOJVnF7Q
5+
GmhCAHpx34L5CCPYDXJBd5ExLwGIByKxQNugor7dJx8ehmVkGKto01GWjgY+sPYp
6+
lV9KxvD49ygXYQ6VAqgt/V2EG/PMmT0/jUtmM2tYDFztPkSISJg0vB/f9zHlYIdD
7+
GjkBjngekAij77T93xEuouox25UtXmg6ApqvDVEiBxZmN5Dt70HBsQ+IftENEUoY
8+
8jhrImwBAgMBAAECggEBAJNlgjK3SPvdKln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