forked from zmap/zlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for linting profiles (zmap#595)
* adding support for linting profiles * at least tests running * Update v3/lint/profile.go Absolutely Co-authored-by: Daniel McCarney <[email protected]> * Update v3/newProfile.sh * adding godoc to AllProfiles * util: gtld_map autopull updates for 2022-10-06T19:22:06 UTC * Trigger GHA * fixing linter Co-authored-by: Daniel McCarney <[email protected]> Co-authored-by: GitHub <[email protected]>
- Loading branch information
1 parent
c627333
commit 6292ca4
Showing
10 changed files
with
279 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
[AppleRootStorePolicyConfig] | ||
|
||
[CABFBaselineRequirementsConfig] | ||
|
||
[CABFEVGuidelinesConfig] | ||
|
||
[CommunityConfig] | ||
|
||
[MozillaRootStorePolicyConfig] | ||
|
||
[RFC5280Config] | ||
|
||
[RFC5480Config] | ||
|
||
[RFC5891Config] | ||
|
||
[e_rsa_fermat_factorization] | ||
Rounds = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* ZLint Copyright 2021 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package lint | ||
|
||
type Profile struct { | ||
// Name is a lowercase underscore-separated string describing what a given | ||
// profile aggregates. | ||
Name string `json:"name"` | ||
|
||
// A human-readable description of what the Profile checks. Usually copied | ||
// directly from the CA/B Baseline Requirements, RFC 5280, or other published | ||
// document. | ||
Description string `json:"description,omitempty"` | ||
|
||
// The source of the check, e.g. "BRs: 6.1.6" or "RFC 5280: 4.1.2.6". | ||
Citation string `json:"citation,omitempty"` | ||
|
||
// Programmatic source of the check, BRs, RFC5280, or ZLint | ||
Source LintSource `json:"source,omitempty"` | ||
|
||
// The names of the lints that compromise this profile. These names | ||
// MUST be the exact same found within Lint.Name. | ||
LintNames []string `json:"lints"` | ||
} | ||
|
||
var profiles = map[string]Profile{} | ||
|
||
// RegisterProfile registered the provided profile into the global profile mapping. | ||
func RegisterProfile(profile Profile) { | ||
profiles[profile.Name] = profile | ||
} | ||
|
||
// GetProfile returns the Profile for which the provided name matches Profile.Name. | ||
// If no such Profile exists then the `ok` returns false, else true. | ||
func GetProfile(name string) (profile Profile, ok bool) { | ||
profile, ok = profiles[name] | ||
return profile, ok | ||
} | ||
|
||
// AllProfiles returns a slice of all Profiles currently registered globally. | ||
func AllProfiles() []Profile { | ||
p := make([]Profile, 0) | ||
for _, profile := range profiles { | ||
p = append(p, profile) | ||
} | ||
return p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Script to create new profile from template | ||
|
||
USAGE="Usage: $0 <ARG1> | ||
ARG1: file_name" | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "No arguments provided..." | ||
echo "$USAGE" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -d profiles ] | ||
then | ||
echo "Directory 'profiles' does not exist. Can't make new file." | ||
exit 1 | ||
fi | ||
|
||
|
||
if [ -e profiles/profile_$1.go ] | ||
then | ||
echo "File already exists. Can't make new file." | ||
exit 1 | ||
fi | ||
|
||
PROFILE=$1 | ||
|
||
sed -e "s/PROFILE/${PROFILE}/" profileTemplate > profiles/profile_${PROFILE}.go | ||
|
||
echo "Created file profiles/lint_${PROFILE}.go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* ZLint Copyright 2021 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package profiles | ||
|
||
import "github.com/zmap/zlint/v3/lint" | ||
|
||
func init() { | ||
lint.RegisterProfile(lint.Profile{ | ||
Name: "PROFILE", | ||
Description: "Fill this in...", | ||
Citation: "Fill this in...", | ||
Source: lint.UnknownLintSource, | ||
LintNames: []string{}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* ZLint Copyright 2021 Regents of the University of Michigan | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
* implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package profiles | ||
|
||
import ( | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/zmap/zlint/v3/lint" | ||
_ "github.com/zmap/zlint/v3/lints/apple" | ||
_ "github.com/zmap/zlint/v3/lints/cabf_br" | ||
_ "github.com/zmap/zlint/v3/lints/cabf_ev" | ||
_ "github.com/zmap/zlint/v3/lints/community" | ||
_ "github.com/zmap/zlint/v3/lints/etsi" | ||
_ "github.com/zmap/zlint/v3/lints/mozilla" | ||
_ "github.com/zmap/zlint/v3/lints/rfc" | ||
) | ||
|
||
// We would like to make sure that there is a generic test that makes sure | ||
// that all profiles actually refer to registered lints. | ||
func TestLintsInAllProfilesExist(t *testing.T) { | ||
for _, profile := range lint.AllProfiles() { | ||
for _, l := range profile.LintNames { | ||
if lint.GlobalRegistry().ByName(l) == nil { | ||
t.Errorf("Profile '%s' declares lint '%s' which does not exist", profile.Name, l) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// In order to run TestLintsInAllProfilesExist we need to import all lint source packages in order | ||
// to run their init functions. This test makes sure that if anyone adds a new | ||
// lint source in the future that we don't miss importing it into this test file. | ||
func TestNotMissingAnyLintSources(t *testing.T) { | ||
expected := map[string]bool{ | ||
"apple": true, | ||
"cabf_br": true, | ||
"cabf_ev": true, | ||
"community": true, | ||
"etsi": true, | ||
"mozilla": true, | ||
"rfc": true, | ||
} | ||
dir, err := ioutil.ReadDir("../lints") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, info := range dir { | ||
if !info.IsDir() { | ||
continue | ||
} | ||
if _, ok := expected[info.Name()]; !ok { | ||
t.Errorf("We need to import each lint source in order to ensure that all lint names referred to by "+ | ||
"declared profiles actually exist. However, we found the directory lints/%s which is not a lint "+ | ||
"source that this test is aware of. Please add the following import to the top if this test file: "+ | ||
"_ \"github.com/zmap/zlint/v3/lints/%s\"", info.Name(), info.Name()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package profiles | ||
|
||
// This file exists purely to avoid the following error until we have at least one profile | ||
// | ||
// no non-test Go files in /home/runner/work/zlint/zlint/v3/profiles |