-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure docker registry CA is trusted in e2e tests
- Loading branch information
1 parent
52246e1
commit 33e3fc3
Showing
9 changed files
with
158 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"encoding/pem" | ||
"math/big" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"github.com/go-logr/logr/testr" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_newCertPool(t *testing.T) { | ||
t.Parallel() | ||
|
||
// set up our CA certificate | ||
ca := &x509.Certificate{ | ||
SerialNumber: big.NewInt(2019), | ||
Subject: pkix.Name{ | ||
Organization: []string{"Company, INC."}, | ||
Country: []string{"US"}, | ||
Province: []string{""}, | ||
Locality: []string{"San Francisco"}, | ||
StreetAddress: []string{"Golden Gate Bridge"}, | ||
PostalCode: []string{"94016"}, | ||
}, | ||
NotBefore: time.Now(), | ||
NotAfter: time.Now().AddDate(10, 0, 0), | ||
IsCA: true, | ||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, | ||
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, | ||
BasicConstraintsValid: true, | ||
} | ||
|
||
// create our private and public key | ||
caPrivKey, err := rsa.GenerateKey(rand.Reader, 4096) | ||
require.NoError(t, err) | ||
|
||
// create the CA | ||
caBytes, err := x509.CreateCertificate(rand.Reader, ca, ca, &caPrivKey.PublicKey, caPrivKey) | ||
require.NoError(t, err) | ||
|
||
// pem encode | ||
err = os.MkdirAll("testdata/newCertPool/subfolder", 0700) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
require.NoError(t, os.RemoveAll("testdata/newCertPool")) | ||
}) | ||
|
||
caPEM, err := os.Create("testdata/newCertPool/my.pem") | ||
require.NoError(t, err) | ||
err = pem.Encode(caPEM, &pem.Block{ | ||
Type: "CERTIFICATE", | ||
Bytes: caBytes, | ||
}) | ||
require.NoError(t, err) | ||
|
||
_, err = newCertPool("testdata/newCertPool", testr.New(t)) | ||
require.NoError(t, err) | ||
} | ||
|
||
func Test_newCertPool_empty(t *testing.T) { | ||
err := os.MkdirAll("testdata/newCertPoolEmpty", 0700) | ||
require.NoError(t, err) | ||
|
||
_, err = newCertPool("testdata/newCertPoolEmpty", testr.New(t)) | ||
require.EqualError(t, err, `no certificates found in "testdata/newCertPoolEmpty"`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters