epita-rules: Checks that CVE- flag are UCQ, and number of choices

Fixes: #26
This commit is contained in:
nemunaire 2022-07-12 10:17:38 +02:00
parent 8aba067d05
commit db9d7edf6b
2 changed files with 16 additions and 0 deletions

View File

@ -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
}

View File

@ -6,5 +6,6 @@ import (
func RegisterChecksHooks(h *sync.CheckHooks) {
h.RegisterFlagKeyHook(EPITACheckKeyFlag)
h.RegisterFlagKeyWithChoicesHook(EPITACheckKeyFlagWithChoices)
h.RegisterFileHook(EPITACheckFile)
}