|
| 1 | +package query |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/alibaba/UnifiedModel/pkg/model" |
| 7 | +) |
| 8 | + |
| 9 | +// FuzzParse hardens the SPL parser, an untrusted-input surface. The invariant is |
| 10 | +// simple but important: Parse must never panic on arbitrary input — it may |
| 11 | +// return an error, but it must not crash the server. The seed corpus runs on |
| 12 | +// every `go test`; `go test -fuzz=FuzzParse` explores further. |
| 13 | +func FuzzParse(f *testing.F) { |
| 14 | + seeds := []string{ |
| 15 | + "", |
| 16 | + ".entity with(domain='devops', name='devops.service')", |
| 17 | + ".entity with(domain='a', name='b', query='x', topk=5, mode='vector')", |
| 18 | + ".umodel with(kind='entity_set') | project domain,name | sort domain | limit 10", |
| 19 | + ".entity_set with(domain='d', name='n', ids=['1']) | entity-call get_metrics('d','m','x', step='30s')", |
| 20 | + ".topo | graph-call getNeighborNodes('full', 2, [(:\"d@n\" {__entity_id__: '1'})]) | limit 5", |
| 21 | + ".topo | graph-call cypher(`MATCH (n) RETURN n LIMIT 1`)", |
| 22 | + "not a query", |
| 23 | + ".entity with(", |
| 24 | + ".entity with(domain='x'", |
| 25 | + ".topo | graph-call getNeighborNodes(", |
| 26 | + "| | |", |
| 27 | + ".entity with(domain='a', name='b') | project | sort | limit", |
| 28 | + } |
| 29 | + for _, s := range seeds { |
| 30 | + f.Add(s) |
| 31 | + } |
| 32 | + f.Fuzz(func(t *testing.T, query string) { |
| 33 | + // Must not panic. An error return is acceptable. |
| 34 | + _, _ = Parse(model.QueryRequest{Query: query}) |
| 35 | + }) |
| 36 | +} |
0 commit comments