epita-rules: Checks that CVE- flag are UCQ, and number of choices
Fixes: #26
This commit is contained in:
parent
8aba067d05
commit
db9d7edf6b
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
|
@ -18,5 +19,19 @@ func EPITACheckKeyFlag(flag *fic.FlagKey, raw string) (errs []error) {
|
|||
errs = append(errs, fmt.Errorf("Label should not end with punct (%q). Reword your label as a description of the expected flag, `:` are automatically appended.", flag.Label[len(flag.Label)-1]))
|
||||
}
|
||||
|
||||
if strings.HasPrefix(strings.ToLower(raw), "cve-") && flag.Type != "ucq" {
|
||||
errs = append(errs, fmt.Errorf("CVE numbers are required to be UCQ with choice_cost"))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func EPITACheckKeyFlagWithChoices(flag *fic.FlagKey, raw string, choices []*fic.FlagChoice) (errs []error) {
|
||||
if len(choices) < 10 && flag.ChoicesCost == 0 {
|
||||
errs = append(errs, fmt.Errorf("requires at least 10 choices to avoid brute-force"))
|
||||
} else if len(choices) < 6 && flag.ChoicesCost > 0 {
|
||||
errs = append(errs, fmt.Errorf("requires at least 10 choices to avoid brute-force"))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@ import (
|
|||
|
||||
func RegisterChecksHooks(h *sync.CheckHooks) {
|
||||
h.RegisterFlagKeyHook(EPITACheckKeyFlag)
|
||||
h.RegisterFlagKeyWithChoicesHook(EPITACheckKeyFlagWithChoices)
|
||||
h.RegisterFileHook(EPITACheckFile)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue