func TestCSRSignerNameDefaulting(t *testing.T) {
	strPtr := func(s string) *string { return &s }
	tests := map[string]struct {
		csr                capi.CertificateSigningRequestSpec
		expectedSignerName string
	}{
		"defaults to legacy-unknown if not recognised": {
			csr: capi.CertificateSigningRequestSpec{
				Request: pemWithGroup(""),
				Usages:  []capi.KeyUsage{capi.UsageKeyEncipherment, capi.UsageDigitalSignature},
			},
			expectedSignerName: capi.LegacyUnknownSignerName,
		},
		"does not default signerName if an explicit value is provided": {
			csr: capi.CertificateSigningRequestSpec{
				Request:    pemWithGroup(""),
				Usages:     []capi.KeyUsage{capi.UsageKeyEncipherment, capi.UsageDigitalSignature},
				SignerName: strPtr("example.com/my-custom-signer"),
			},
			expectedSignerName: "example.com/my-custom-signer",
		},
	}
	for name, test := range tests {
		t.Run(name, func(t *testing.T) {
			_, s, closeFn := framework.RunAMaster(nil)
			defer closeFn()
			client := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
			csrClient := client.CertificatesV1beta1().CertificateSigningRequests()
			csr := &capi.CertificateSigningRequest{
				ObjectMeta: metav1.ObjectMeta{Name: "testcsr"},
				Spec:       test.csr,
			}
			csr, err := csrClient.Create(context.TODO(), csr, metav1.CreateOptions{})
			if err != nil {
				t.Fatalf("failed to create CSR resource: %v", err)
			}
			if *csr.Spec.SignerName != test.expectedSignerName {
				t.Errorf("expected CSR signerName to be %q but it was %q", test.expectedSignerName, *csr.Spec.SignerName)
			}
		})
	}
}
// Verifies that the signerName field defaulting is wired up correctly.
// An exhaustive set of test cases for all permutations of the possible
// defaulting cases is written as a unit tests in the
// `pkg/apis/certificates/...` directory.
// This test cases exists to show that the defaulting function is wired up into
// the apiserver correctly.
Verifies that the signerName field defaulting is wired up correctly.
An exhaustive set of test cases for all permutations of the possible
defaulting cases is written as a unit tests in the
`pkg/apis/certificates/...` directory.
This test cases exists to show that the defaulting function is wired up into
the apiserver correctly.
// Verifies that the signerName field defaulting is wired up correctly . // An exhaustive set of test cases for all permutations of the possible // defaulting cases is written as a unit tests in the // ` pkg / apis / certificates / ... ` directory . // This test cases exists to show that the defaulting function is wired up into // the apiserver correctly .
func TestCSRSignerNameDefaulting(t *testing.T) {
	strPtr := func(s string) *string { return &s }
	tests := map[string]struct {
		csr                capi.CertificateSigningRequestSpec
		expectedSignerName string
	}{
		"defaults to legacy-unknown if not recognised": {
			csr: capi.CertificateSigningRequestSpec{
				Request: pemWithGroup(""),
				Usages:  []capi.KeyUsage{capi.UsageKeyEncipherment, capi.UsageDigitalSignature},
			},
			expectedSignerName: capi.LegacyUnknownSignerName,
		},
		"does not default signerName if an explicit value is provided": {
			csr: capi.CertificateSigningRequestSpec{
				Request:    pemWithGroup(""),
				Usages:     []capi.KeyUsage{capi.UsageKeyEncipherment, capi.UsageDigitalSignature},
				SignerName: strPtr("example.com/my-custom-signer"),
			},
			expectedSignerName: "example.com/my-custom-signer",
		},
	}
	for name, test := range tests {
		t.Run(name, func(t *testing.T) {
			_, s, closeFn := framework.RunAMaster(nil)
			defer closeFn()
			client := clientset.NewForConfigOrDie(&restclient.Config{Host: s.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
			csrClient := client.CertificatesV1beta1().CertificateSigningRequests()
			csr := &capi.CertificateSigningRequest{
				ObjectMeta: metav1.ObjectMeta{Name: "testcsr"},
				Spec:       test.csr,
			}
			csr, err := csrClient.Create(context.TODO(), csr, metav1.CreateOptions{})
			if err != nil {
				t.Fatalf("failed to create CSR resource: %v", err)
			}
			if *csr.Spec.SignerName != test.expectedSignerName {
				t.Errorf("expected CSR signerName to be %q but it was %q", test.expectedSignerName, *csr.Spec.SignerName)
			}
		})
	}
}
func TestCSRSignerNameDefaulting ( t * testing . T ) { strPtr := func ( s string ) * string { return & s } tests := map [ string ] struct { csr capi . CertificateSigningRequestSpec expectedSignerName string } { " " : { csr : capi . CertificateSigningRequestSpec { Request : pemWithGroup ( " " ) , Usages : [ ] capi . KeyUsage { capi . UsageKeyEncipherment , capi . UsageDigitalSignature } , } , expectedSignerName : capi . LegacyUnknownSignerName , } , " " : { csr : capi . CertificateSigningRequestSpec { Request : pemWithGroup ( " " ) , Usages : [ ] capi . KeyUsage { capi . UsageKeyEncipherment , capi . UsageDigitalSignature } , SignerName : strPtr ( " " ) , } , expectedSignerName : " " , } , } for name , test := range tests { t . Run ( name , func ( t * testing . T ) { _ , s , closeFn := framework . RunAMaster ( nil ) defer closeFn ( ) client := clientset . NewForConfigOrDie ( & restclient . Config { Host : s . URL , ContentConfig : restclient . ContentConfig { GroupVersion : & schema . GroupVersion { Group : " " , Version : " " } } } ) csrClient := client . CertificatesV1beta1 ( ) . CertificateSigningRequests ( ) csr := & capi . CertificateSigningRequest { ObjectMeta : metav1 . ObjectMeta { Name : " " } , Spec : test . csr , } csr , err := csrClient . Create ( context . TODO ( ) , csr , metav1 . CreateOptions { } ) if err != nil { t . Fatalf ( " " , err ) } if * csr . Spec . SignerName != test . expectedSignerName { t . Errorf ( " " , test . expectedSignerName , * csr . Spec . SignerName ) } } ) } }
Verifies that the signerName field defaulting is wired up correctly.
Verifies that the signerName field defaulting is wired up correctly .