github.com/zmap/zlint@v1.1.0/lints/base_test.go (about) 1 package lints 2 3 /* 4 * ZLint Copyright 2017 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 "time" 20 ) 21 22 func TestAllLintsHaveNameDescriptionSource(t *testing.T) { 23 for name, lint := range Lints { 24 if lint.Name == "" { 25 t.Errorf("lint %s has empty name", name) 26 } 27 if lint.Description == "" { 28 t.Errorf("lint %s has empty description", name) 29 } 30 if lint.Citation == "" { 31 t.Errorf("lint %s has empty citation", name) 32 } 33 } 34 } 35 36 func TestAllLintsHaveSource(t *testing.T) { 37 for name, lint := range Lints { 38 if lint.Source == UnknownLintSource { 39 t.Errorf("lint %s has unknown source", name) 40 } 41 } 42 } 43 44 func TestLintCheckEffective(t *testing.T) { 45 l := Lint{} 46 c := ReadCertificate("../testlint/testCerts/caBasicConstCrit.pem") 47 48 l.EffectiveDate = time.Time{} 49 if l.CheckEffective(c) != true { 50 t.Errorf("EffectiveDate of zero should always be true") 51 } 52 l.EffectiveDate = time.Unix(1, 0) 53 if l.CheckEffective(c) != true { 54 t.Errorf("EffectiveDate of 1970-01-01 should be true") 55 } 56 l.EffectiveDate = time.Unix(32503680000, 0) // 3000-01-01 57 if l.CheckEffective(c) != false { 58 t.Errorf("EffectiveDate of 3000 should be false") 59 } 60 } 61 62 func TestLintExecute(t *testing.T) { 63 c := ReadCertificate("../testlint/testCerts/goodRsaExp.pem") 64 lint := Lint{} 65 66 lint.Lint = &dsaParamsMissing{} 67 res := lint.Execute(c) 68 if res.Status != NA { 69 t.Errorf("Expected NA, got %s", res.Status) 70 } 71 72 lint.Lint = &rsaParsedTestsExpBounds{} 73 lint.EffectiveDate = time.Unix(32503680000, 0) 74 res = lint.Execute(c) 75 if res.Status != NE { 76 t.Errorf("Expected NE, got %s", res.Status) 77 } 78 }