High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
test(activity): the source census also flags a bare literal assigned to .Source or used as a switch case on .Source
Luigi Agosti9490079a8759
diff --git a/internal/activity/sources_census_test.go b/internal/activity/sources_census_test.goindex 5976beb6..ecc388a4 100644--- a/internal/activity/sources_census_test.go+++ b/internal/activity/sources_census_test.go@@ -81,6 +81,20 @@ func bareSourceLiteralSites(t *testing.T, files []srccensus.SourceFile) []stringif isSourceSelector(node.Y) {flag(node.X, ".Source comparison operand")}+ case *ast.AssignStmt:+ for i, lhs := range node.Lhs {+ if isSourceSelector(lhs) && i < len(node.Rhs) {+ flag(node.Rhs[i], ".Source assignment value")+ }+ }+ case *ast.SwitchStmt:+ if node.Tag != nil && isSourceSelector(node.Tag) {+ for _, stmt := range node.Body.List {+ for _, expr := range stmt.(*ast.CaseClause).List {+ flag(expr, "switch on .Source case")+ }+ }+ }case *ast.BasicLit:if inActivityPkg {flag(node, "bare literal in package activity")@@ -115,6 +129,17 @@ func TestSourceCensusFlagsAPlantedComparison(t *testing.T) {}}+func TestSourceCensusFlagsAPlantedAssignmentAndSwitchCase(t *testing.T) {+ for name, text := range map[string]string{+ "assignment": "package server\nfunc f(evt *struct{ Source string }) { evt.Source = \"client\" }\n",+ "switch": "package server\nfunc f(evt struct{ Source string }) bool {\n\tswitch evt.Source {\n\tcase \"dashboard\":\n\t\treturn true\n\t}\n\treturn false\n}\n",+ } {+ if len(bareSourceLiteralSites(t, []srccensus.SourceFile{{Name: "internal/server/evil.go", Text: text}})) == 0 {+ t.Errorf("a bare source literal in a .Source %s passed the census", name)+ }+ }+}+// The exemption bites in both directions: a config-section literal is not forced onto// the activity source consts, even in a Source-shaped composite literal.func TestSourceCensusExcludesConfigByPath(t *testing.T) {