Debian Codegraph @

v3/lints/rfc/lint_rsa_allowed_ku_ca_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 TestRsaAllowedKUCa(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.NA,
41 expectedDetails: "",
42 },
43 {
44 name: "CA certificate with RSA key and key usages digitalSignature and nonRepudiation older than 2002",
45 filename: "caWithRSAAllowedKeyUsageOld.pem",
46 expectedStatus: lint.NE,
47 expectedDetails: "",
48 },
49 {
50 name: "CA certificate with RSA key and key usages digitalSignature, certificateSign, and crlSign",
51 filename: "caBasicConstCrit.pem",
52 expectedStatus: lint.Pass,
53 expectedDetails: "",
54 },
55 {
56 name: "CA certificate with RSA key and key usages certificateSign and keyAgreement",
57 filename: "caWithRSADisallowedKeyUsage.pem",
58 expectedStatus: lint.Error,
59 expectedDetails: "CA certificate with an RSA key contains invalid key usage(s): KeyUsageKeyAgreement",
60 },
61 {
62 name: "CA certificate with RSA key and key usages certificateSign and keyEncipherment",
63 filename: "caWithRSAAndEnciphermentKeyUsage.pem",
64 expectedStatus: lint.Pass,
65 expectedDetails: "",
66 },
67 }
68
69 for _, tc := range testCases {
70 result := test.TestLint("e_rsa_allowed_ku_ca", tc.filename)
71 if result.Status != tc.expectedStatus {
72 t.Errorf("expected result %v. actual result was %v",
73 tc.expectedStatus, result.Status)
74 }
75 if result.Details != tc.expectedDetails {
76 t.Errorf("expected details %q. actual result was %q",
77 tc.expectedDetails, result.Details)
78 }
79 }
80 }