github.com/zmap/zlint@v1.1.0/lints/lint_subject_printable_string_badalpha_test.go (about) 1 package lints 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestSubjectPrintableStringBadAlpha(t *testing.T) { 9 testCases := []struct { 10 name string 11 filename string 12 expected LintResult 13 }{ 14 { 15 name: "valid subj. PrintableStrings", 16 // A RawSubject containing 8 PrintableString attributes all adhering to 17 // the expected character set. 18 filename: "subjectCommonNameLengthGood.pem", 19 expected: LintResult{ 20 Status: Pass, 21 }, 22 }, 23 { 24 name: "valid subject with single quote", 25 // A RawSubject containing 8 PrintableString attributes all adhering to 26 // the expected character set. 27 filename: "subjectWithSingleQuote.pem", 28 expected: LintResult{ 29 Status: Pass, 30 }, 31 }, 32 { 33 name: "invalid subj. CN PrintableString", 34 // A RawSubject containing a single PrintableString attribute (OID 35 // 2.5.4.3, subject common name) with an illegal character (`*`). 36 filename: "subjectCommonNamePrintableStringBadAlpha.pem", 37 expected: LintResult{ 38 Status: Error, 39 Details: "RawSubject attr oid 2.5.4.3 encoded PrintableString contained illegal characters", 40 }, 41 }, 42 } 43 44 for _, tc := range testCases { 45 t.Run(tc.name, func(t *testing.T) { 46 inputPath := fmt.Sprintf("%s%s", testCaseDir, tc.filename) 47 result := Lints["e_subject_printable_string_badalpha"].Execute(ReadCertificate(inputPath)) 48 if result.Status != tc.expected.Status { 49 t.Errorf("expected result status %v was %v", tc.expected.Status, result.Status) 50 } 51 if result.Details != tc.expected.Details { 52 t.Errorf("expected result details %q was %q", tc.expected.Details, result.Details) 53 } 54 }) 55 } 56 }