Debian Codegraph @

v3/lints/rfc/lint_rsa_allowed_ku_ee_test.go

raw symbols SCIP
1 package rfc
2
3 /*
4 * ZLint Copyright 2024 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 "github.com/zmap/zlint/v3/lint"
21 "github.com/zmap/zlint/v3/test"
22 )
23
24 func TestNewRsaAllowedKUEe(t *testing.T) {
25 testCases := []struct {
26 name string
27 filename string
28 expectedStatus lint.LintStatus
29 expectedDetails string
30 }{
31 {
32 name: "Certificate with EC key",
33 filename: "ecdsaP384.pem",
34 expectedStatus: lint.NA,
35 expectedDetails: "",
36 },
37 {
38 name: "Subscriber certificate with RSA key and key usages digitalSignature and nonRepudiation",
39 filename: "eeWithRSAAllowedKeyUsage.pem",
40 expectedStatus: lint.Pass,
41 expectedDetails: "",
42 },
43 {
44 name: "CA certificate with RSA key and key usages digitalSignature, certificateSign, and crlSign",
45 filename: "caBasicConstCrit.pem",
46 expectedStatus: lint.NA,
47 expectedDetails: "",
48 },
49 {
50 name: "Subscriber certificate with RSA key and key usages digitalSignature and nonRepudiation older than",
51 filename: "eeWithRSAAllowedKeyUsageOld.pem",
52 expectedStatus: lint.NE,
53 expectedDetails: "",
54 },
55 {
56 name: "Subscriber certificate with RSA key and key usage keyAgreement",
57 filename: "eeWithRSADisallowedKeyUsage.pem",
58 expectedStatus: lint.Error,
59 expectedDetails: "Subscriber certificate with an RSA key contains invalid key usage(s): KeyUsageKeyAgreement",
60 },
61 }
62
63 for _, tc := range testCases {
64 result := test.TestLint("e_rsa_allowed_ku_ee", tc.filename)
65 if result.Status != tc.expectedStatus {
66 t.Errorf("expected result %v. actual result was %v",
67 tc.expectedStatus, result.Status)
68 }
69 if result.Details != tc.expectedDetails {
70 t.Errorf("expected details %q. actual result was %q",
71 tc.expectedDetails, result.Details)
72 }
73 }
74 }