ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
db: report hidden asset count in malformed-ip warning suffix
BaaRaic84f124cb496
diff --git a/db/companies.go b/db/companies.goindex 57a6815..ad5d239 100644--- a/db/companies.go+++ b/db/companies.go@@ -633,14 +633,20 @@ LIMIT $1`, malformedIPAssetsSampled)if total == 0 {return "", nil}+ return malformedIPAssetWarningText(total, samples), nil+}++// malformedIPAssetWarningText words the warning for total offending assets, of+// which only samples are named; the ones left out are counted in the suffix.+func malformedIPAssetWarningText(total int, samples []string) string {warning := fmt.Sprintf("%d assets have an ip field that is not a valid IP; skipped for IP/CIDR scope matching (these assets will not be attributed to a company by subnet rules): %s",total, strings.Join(samples, ", "),)if total > len(samples) {- warning += fmt.Sprintf(" and %d more", total)+ warning += fmt.Sprintf(" and %d more", total-len(samples))}- return warning, nil+ return warning}// UpdateScope replaces all scope rules for a company and reattributes.diff --git a/db/companies_test.go b/db/companies_test.goindex 465966d..25ee77a 100644--- a/db/companies_test.go+++ b/db/companies_test.go@@ -458,3 +458,21 @@ func TestListCompanies(t *testing.T) {t.Error("ListCompanies: created company not found")}}++func TestMalformedIPAssetWarningTextCountsOmitted(t *testing.T) {+ samples := []string{"#1 a", "#2 b", "#3 c", "#4 d", "#5 e"}+ // The suffix must count the assets left out, not repeat the total, otherwise+ // the operator is told about more bad rows than exist.+ got := malformedIPAssetWarningText(8, samples)+ if !strings.HasPrefix(got, "8 assets have an ip field") {+ t.Fatalf("the warning should lead with the total of 8, got %q", got)+ }+ if !strings.HasSuffix(got, ": #1 a, #2 b, #3 c, #4 d, #5 e and 3 more") {+ t.Fatalf("8 assets with 5 named should note the 3 omitted, got %q", got)+ }+ // When every offending asset is named there is nothing to add.+ got = malformedIPAssetWarningText(5, samples)+ if !strings.HasSuffix(got, ": #1 a, #2 b, #3 c, #4 d, #5 e") {+ t.Fatalf("5 assets with 5 named should have no suffix, got %q", got)+ }+}