MCPcopy Create free account
hub / github.com/rilldata/rill / TestValidateQueryAttributes

Function TestValidateQueryAttributes

runtime/parser/parse_metrics_view_test.go:326–491  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

324}
325
326func TestValidateQueryAttributes(t *testing.T) {
327 tests := []struct {
328 name string
329 attrs map[string]string
330 wantErr bool
331 errMsg string
332 }{
333 {
334 name: "valid simple attributes",
335 attrs: map[string]string{"partner_id": "acme_corp", "region": "us-west"},
336 wantErr: false,
337 },
338 {
339 name: "valid with underscores and hyphens",
340 attrs: map[string]string{"partner_id": "value1", "user-role": "admin", "app.env": "prod"},
341 wantErr: false,
342 },
343 {
344 name: "valid with dots in key",
345 attrs: map[string]string{"app.environment": "production"},
346 wantErr: false,
347 },
348 {
349 name: "valid with template",
350 attrs: map[string]string{"partner_id": "{{ .user.partner_id }}"},
351 wantErr: false,
352 },
353 {
354 name: "empty attributes map",
355 attrs: map[string]string{},
356 wantErr: false,
357 },
358 {
359 name: "nil attributes map",
360 attrs: nil,
361 wantErr: false,
362 },
363 {
364 name: "empty key",
365 attrs: map[string]string{"": "value"},
366 wantErr: true,
367 },
368 {
369 name: "invalid key with spaces",
370 attrs: map[string]string{"partner id": "value"},
371 wantErr: true,
372 errMsg: "contains invalid characters",
373 },
374 {
375 name: "invalid key with special chars",
376 attrs: map[string]string{"partner@id": "value"},
377 wantErr: true,
378 errMsg: "contains invalid characters",
379 },
380 {
381 name: "invalid key with SQL injection",
382 attrs: map[string]string{"partner'; DROP TABLE users--": "value"},
383 wantErr: true,

Callers

nothing calls this directly

Calls 4

validateQueryAttributesFunction · 0.85
ContainsMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected