mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-01 23:31:51 +00:00
manually sync with k8s.io/kubernetest at 17375fc59fff39135af63bd1750bb07c36ef873b, k8s.io/apimachinery at d90aa2c8531f13b0ca734845934c10dcb6a56ca7
This commit is contained in:
@@ -17,7 +17,9 @@ limitations under the License.
|
||||
package cert
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"crypto/x509/pkix"
|
||||
"encoding/pem"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"testing"
|
||||
@@ -39,8 +41,35 @@ func TestMakeCSR(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = MakeCSR(key, subject, dnsSANs, ipSANs)
|
||||
csrPEM, err := MakeCSR(key, subject, dnsSANs, ipSANs)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
csrBlock, rest := pem.Decode(csrPEM)
|
||||
if csrBlock == nil {
|
||||
t.Error("Unable to decode MakeCSR result.")
|
||||
}
|
||||
if len(rest) != 0 {
|
||||
t.Error("Found more than one PEM encoded block in the result.")
|
||||
}
|
||||
if csrBlock.Type != "CERTIFICATE REQUEST" {
|
||||
t.Errorf("Found block type %q, wanted 'CERTIFICATE REQUEST'", csrBlock.Type)
|
||||
}
|
||||
csr, err := x509.ParseCertificateRequest(csrBlock.Bytes)
|
||||
if err != nil {
|
||||
t.Errorf("Found %v parsing MakeCSR result as a CertificateRequest.", err)
|
||||
}
|
||||
if csr.Subject.CommonName != subject.CommonName {
|
||||
t.Errorf("Wanted %v, got %v", subject, csr.Subject)
|
||||
}
|
||||
if len(csr.DNSNames) != 1 {
|
||||
t.Errorf("Wanted 1 DNS name in the result, got %d", len(csr.DNSNames))
|
||||
} else if csr.DNSNames[0] != dnsSANs[0] {
|
||||
t.Errorf("Wanted %v, got %v", dnsSANs[0], csr.DNSNames[0])
|
||||
}
|
||||
if len(csr.IPAddresses) != 1 {
|
||||
t.Errorf("Wanted 1 IP address in the result, got %d", len(csr.IPAddresses))
|
||||
} else if csr.IPAddresses[0].String() != ipSANs[0].String() {
|
||||
t.Errorf("Wanted %v, got %v", ipSANs[0], csr.IPAddresses[0])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user