Skip to content

Commit 238bc8b

Browse files
committed
chore(tests): Add more tests around enrollment pattern id vs enrollment pattern name usage
1 parent a8ae44b commit 238bc8b

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

internal/command/command_test.go

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ func TestSign(t *testing.T) {
476476
Name: *v1.NewNullableString(&enrollmentPatternName),
477477
},
478478
},
479+
479480
// Request
480481
config: &SignConfig{
481482
EnrollmentPatternName: enrollmentPatternName,
@@ -494,9 +495,31 @@ func TestSign(t *testing.T) {
494495
},
495496
expectedSignError: nil,
496497
},
497-
"success-annotation-config-override": {
498+
"success-no-meta-enrollment-pattern-id-overwrites-pattern-name": {
499+
enrollmentPatterns: []v1.EnrollmentPatternsEnrollmentPatternResponse{}, // This would fail if enrollment pattern name was used
498500
// Request
499501
config: &SignConfig{
502+
EnrollmentPatternId: 12345,
503+
EnrollmentPatternName: enrollmentPatternName,
504+
CertificateAuthorityLogicalName: certificateAuthorityLogicalName,
505+
CertificateAuthorityHostname: certificateAuthorityHostname,
506+
Meta: nil,
507+
Annotations: nil,
508+
},
509+
510+
// Expected
511+
expectedEnrollArgs: &EnrollmentCSRRequest{
512+
EnrollmentPatternId: 12345,
513+
CertificateAuthority: fmt.Sprintf("%s\\%s", certificateAuthorityHostname, certificateAuthorityLogicalName),
514+
SANs: map[string][]string{},
515+
Metadata: map[string]interface{}{},
516+
},
517+
expectedSignError: nil,
518+
},
519+
"success-annotation-config-override-pattern-id": {
520+
// Request
521+
config: &SignConfig{
522+
EnrollmentPatternId: 67890,
500523
CertificateTemplate: certificateTemplateName,
501524
CertificateAuthorityLogicalName: certificateAuthorityLogicalName,
502525
CertificateAuthorityHostname: certificateAuthorityHostname,
@@ -505,13 +528,46 @@ func TestSign(t *testing.T) {
505528
"command-issuer.keyfactor.com/certificateTemplate": "template-override",
506529
"command-issuer.keyfactor.com/certificateAuthorityLogicalName": "logicalname-override",
507530
"command-issuer.keyfactor.com/certificateAuthorityHostname": "hostname-override",
508-
"command-issuer.keyfactor.com/enrollmentPatternName": "enrollment-pattern-override",
509531
"command-issuer.keyfactor.com/enrollmentPatternId": "12345",
510532
},
511533
},
512534

513535
// Expected
514536
expectedEnrollArgs: &EnrollmentCSRRequest{
537+
EnrollmentPatternId: 12345,
538+
Template: "template-override",
539+
CertificateAuthority: fmt.Sprintf("%s\\%s", "hostname-override", "logicalname-override"),
540+
SANs: map[string][]string{},
541+
Metadata: map[string]interface{}{},
542+
},
543+
expectedSignError: nil,
544+
},
545+
"success-annotation-config-override-pattern-name": {
546+
enrollmentPatterns: []v1.EnrollmentPatternsEnrollmentPatternResponse{
547+
v1.EnrollmentPatternsEnrollmentPatternResponse{
548+
Id: ptr(int32(12345)),
549+
Name: *v1.NewNullableString(ptr("enrollment-pattern-override")),
550+
},
551+
},
552+
553+
// Request
554+
config: &SignConfig{
555+
EnrollmentPatternName: enrollmentPatternName,
556+
CertificateTemplate: certificateTemplateName,
557+
CertificateAuthorityLogicalName: certificateAuthorityLogicalName,
558+
CertificateAuthorityHostname: certificateAuthorityHostname,
559+
Meta: nil,
560+
Annotations: map[string]string{
561+
"command-issuer.keyfactor.com/certificateTemplate": "template-override",
562+
"command-issuer.keyfactor.com/certificateAuthorityLogicalName": "logicalname-override",
563+
"command-issuer.keyfactor.com/certificateAuthorityHostname": "hostname-override",
564+
"command-issuer.keyfactor.com/enrollmentPatternName": "enrollment-pattern-override",
565+
},
566+
},
567+
568+
// Expected
569+
expectedEnrollArgs: &EnrollmentCSRRequest{
570+
EnrollmentPatternId: 12345,
515571
Template: "template-override",
516572
CertificateAuthority: fmt.Sprintf("%s\\%s", "hostname-override", "logicalname-override"),
517573
SANs: map[string][]string{},

0 commit comments

Comments
 (0)