github.com/zmap/zlint@v1.1.0/lints/lint_subject_contains_noninformational_value_test.go (about)

     1  package lints
     2  
     3  /*
     4   * ZLint Copyright 2018 Regents of the University of Michigan
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     7   * use this file except in compliance with the License. You may obtain a copy
     8   * of the License at http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    13   * implied. See the License for the specific language governing
    14   * permissions and limitations under the License.
    15   */
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  func TestSubjectInformational(t *testing.T) {
    22  	testCases := []struct {
    23  		name      string
    24  		inputPath string
    25  		result    LintStatus
    26  	}{
    27  		{
    28  			name:      "simple all legal",
    29  			inputPath: "../testlint/testCerts/legalChar.pem",
    30  			result:    Pass,
    31  		},
    32  		{
    33  			name:      "subject with metadata only",
    34  			inputPath: "../testlint/testCerts/illegalChar.pem",
    35  			result:    Error,
    36  		},
    37  	}
    38  
    39  	for _, tc := range testCases {
    40  		t.Run(tc.name, func(t *testing.T) {
    41  			out := Lints["e_subject_contains_noninformational_value"].Execute(ReadCertificate(tc.inputPath))
    42  			if out.Status != tc.result {
    43  				t.Errorf("%s: expected %s, got %s", tc.inputPath, tc.result, out.Status)
    44  			}
    45  		})
    46  	}
    47  }
    48  
    49  func TestCheckAlphaNumericOrUTF8Present(t *testing.T) {
    50  	testCases := []struct {
    51  		name   string
    52  		input  string
    53  		result bool
    54  	}{
    55  		{
    56  			name:   "ascii lowercase",
    57  			input:  "aa",
    58  			result: true,
    59  		},
    60  		{
    61  			name:   "ascii uppercase",
    62  			input:  "AA",
    63  			result: true,
    64  		},
    65  		{
    66  			name:   "ascii numbers",
    67  			input:  "123",
    68  			result: true,
    69  		},
    70  		{
    71  			name:   "ascii start with metadata",
    72  			input:  "-- abc3",
    73  			result: true,
    74  		},
    75  		{
    76  			name:   "ascii end with metadata",
    77  			input:  "abc3 ..",
    78  			result: true,
    79  		},
    80  		{
    81  			name:   "UTF8",
    82  			input:  "テスト",
    83  			result: true,
    84  		},
    85  		{
    86  			name:   "UTF8 start with metadata",
    87  			input:  "?? テスト",
    88  			result: true,
    89  		},
    90  		{
    91  			name:   "UTF8 end with metadata",
    92  			input:  "テスト ??",
    93  			result: true,
    94  		},
    95  		{
    96  			name:   "-",
    97  			input:  "-",
    98  			result: false,
    99  		},
   100  		{
   101  			name:   "**",
   102  			input:  "**",
   103  			result: false,
   104  		},
   105  		{
   106  			name:   "...",
   107  			input:  "...",
   108  			result: false,
   109  		},
   110  		{
   111  			name:   "- -",
   112  			input:  "- -",
   113  			result: false,
   114  		},
   115  		{
   116  			name:   " -",
   117  			input:  " -",
   118  			result: false,
   119  		},
   120  		{
   121  			name:   " ",
   122  			input:  " ",
   123  			result: false,
   124  		},
   125  	}
   126  
   127  	for _, tc := range testCases {
   128  		t.Run(tc.name, func(t *testing.T) {
   129  			result := checkAlphaNumericOrUTF8Present(tc.input)
   130  			if result != tc.result {
   131  				t.Errorf("expected check to be %v, got %v", tc.result, result)
   132  			}
   133  		})
   134  	}
   135  }