TestSQLAnalyzer_UpdateStatements tests analysis of UPDATE statements
(t *testing.T)
| 523 | |
| 524 | // TestSQLAnalyzer_UpdateStatements tests analysis of UPDATE statements |
| 525 | func TestSQLAnalyzer_UpdateStatements(t *testing.T) { |
| 526 | tests := []struct { |
| 527 | name string |
| 528 | sql string |
| 529 | expectedMinSecScore int |
| 530 | }{ |
| 531 | { |
| 532 | name: "UPDATE with WHERE", |
| 533 | sql: "UPDATE users SET active = true WHERE id = 1", |
| 534 | expectedMinSecScore: 70, |
| 535 | }, |
| 536 | { |
| 537 | name: "UPDATE with complex WHERE", |
| 538 | sql: "UPDATE users SET status = 'active' WHERE created_at < '2023-01-01' AND verified = true", |
| 539 | expectedMinSecScore: 70, |
| 540 | }, |
| 541 | } |
| 542 | |
| 543 | for _, tt := range tests { |
| 544 | t.Run(tt.name, func(t *testing.T) { |
| 545 | tkz := tokenizer.GetTokenizer() |
| 546 | defer tokenizer.PutTokenizer(tkz) |
| 547 | |
| 548 | tokens, err := tkz.Tokenize([]byte(tt.sql)) |
| 549 | if err != nil { |
| 550 | t.Fatalf("Tokenization failed: %v", err) |
| 551 | } |
| 552 | |
| 553 | p := parser.NewParser() |
| 554 | astObj := ast.NewAST() |
| 555 | defer ast.ReleaseAST(astObj) |
| 556 | |
| 557 | result, err := p.ParseFromModelTokens(tokens) |
| 558 | if err != nil { |
| 559 | t.Skipf("Parsing failed (expected for incomplete parser support): %v", err) |
| 560 | return |
| 561 | } |
| 562 | astObj.Statements = result.Statements |
| 563 | |
| 564 | analyzer := NewSQLAnalyzer() |
| 565 | report, err := analyzer.Analyze(astObj) |
| 566 | if err != nil { |
| 567 | t.Fatalf("Analysis failed: %v", err) |
| 568 | } |
| 569 | |
| 570 | // Basic validations |
| 571 | if report == nil { |
| 572 | t.Fatal("Expected report but got nil") |
| 573 | } |
| 574 | |
| 575 | // Check security score is reasonable |
| 576 | if report.SecurityScore < tt.expectedMinSecScore { |
| 577 | t.Errorf("Security score too low: expected >= %d, got %d", |
| 578 | tt.expectedMinSecScore, report.SecurityScore) |
| 579 | } |
| 580 | }) |
| 581 | } |
| 582 | } |
nothing calls this directly
no test coverage detected