Skip to content

Commit

Permalink
Fix lint errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
candita committed Oct 9, 2024
1 parent 512866f commit a785d3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions conformance/tests/backendtlspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"k8s.io/apimachinery/pkg/types"

"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
Expand Down
2 changes: 1 addition & 1 deletion conformance/utils/kubernetes/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func generateRSACert(hosts []string, keyOut, certOut io.Writer) error {
for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil {
template.IPAddresses = append(template.IPAddresses, ip)
} else if err := validateHost(h); err == nil {
} else if err = validateHost(h); err == nil {
template.DNSNames = append(template.DNSNames, h)
}
}
Expand Down
28 changes: 15 additions & 13 deletions conformance/utils/kubernetes/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,28 @@ func Test_generateCACert(t *testing.T) {
block, _ := pem.Decode(serverCert.Bytes())
if block == nil {
require.FailNow(t, "failed to decode PEM block containing cert")
}
if block.Type == "CERTIFICATE" {
cert, err := x509.ParseCertificate(block.Bytes)
require.NoError(t, err, "failed to parse certificate")
for _, h := range tc.hosts {
if err = cert.VerifyHostname(h); err != nil {
require.EqualValues(t, tc.expectedErr, err.Error(), "certificate verification failed")
} else if len(tc.hosts) < 2 && err == nil && tc.expectedErr != "" {
require.EqualValues(t, tc.expectedErr, nil, "expected an error but certification verification succeeded")
} else {
if block.Type == "CERTIFICATE" {
cert, err := x509.ParseCertificate(block.Bytes)
require.NoError(t, err, "failed to parse certificate")
for _, h := range tc.hosts {
if err = cert.VerifyHostname(h); err != nil {
require.EqualValues(t, tc.expectedErr, err.Error(), "certificate verification failed")
} else if len(tc.hosts) < 2 && err == nil && tc.expectedErr != "" {
require.EqualValues(t, tc.expectedErr, err, "expected an error but certification verification succeeded")
}
}
}
}
// Test that the server key is decodable and parseable.
block, _ = pem.Decode(serverKey.Bytes())
if block == nil {
require.FailNow(t, "failed to decode PEM block containing public key")
}
if block.Type == "RSA PRIVATE KEY" {
_, err := x509.ParsePKCS1PrivateKey(block.Bytes)
require.NoError(t, err, "failed to parse key")
} else {
if block.Type == "RSA PRIVATE KEY" {
_, err := x509.ParsePKCS1PrivateKey(block.Bytes)
require.NoError(t, err, "failed to parse key")
}
}
})
}
Expand Down

0 comments on commit a785d3b

Please sign in to comment.