TestSQLAnalyzer_MixedStatements tests analysis with multiple statement types
(t *testing.T)
| 667 | |
| 668 | // TestSQLAnalyzer_MixedStatements tests analysis with multiple statement types |
| 669 | func TestSQLAnalyzer_MixedStatements(t *testing.T) { |
| 670 | tests := []struct { |
| 671 | name string |
| 672 | sql string |
| 673 | expectedStmtCount int |
| 674 | expectedMinScore int |
| 675 | }{ |
| 676 | { |
| 677 | name: "SELECT and INSERT", |
| 678 | sql: "SELECT * FROM users; INSERT INTO logs (message) VALUES ('test')", |
| 679 | expectedStmtCount: 2, |
| 680 | expectedMinScore: 60, |
| 681 | }, |
| 682 | } |
| 683 | |
| 684 | for _, tt := range tests { |
| 685 | t.Run(tt.name, func(t *testing.T) { |
| 686 | tkz := tokenizer.GetTokenizer() |
| 687 | defer tokenizer.PutTokenizer(tkz) |
| 688 | |
| 689 | tokens, err := tkz.Tokenize([]byte(tt.sql)) |
| 690 | if err != nil { |
| 691 | t.Fatalf("Tokenization failed: %v", err) |
| 692 | } |
| 693 | |
| 694 | p := parser.NewParser() |
| 695 | astObj := ast.NewAST() |
| 696 | defer ast.ReleaseAST(astObj) |
| 697 | |
| 698 | result, err := p.ParseFromModelTokens(tokens) |
| 699 | if err != nil { |
| 700 | t.Skipf("Parsing failed (parser doesn't support multiple statements yet): %v", err) |
| 701 | return |
| 702 | } |
| 703 | astObj.Statements = result.Statements |
| 704 | |
| 705 | analyzer := NewSQLAnalyzer() |
| 706 | report, err := analyzer.Analyze(astObj) |
| 707 | if err != nil { |
| 708 | t.Fatalf("Analysis failed: %v", err) |
| 709 | } |
| 710 | |
| 711 | if report.Query.StatementCount != tt.expectedStmtCount { |
| 712 | t.Errorf("Expected StatementCount=%d, got %d", |
| 713 | tt.expectedStmtCount, report.Query.StatementCount) |
| 714 | } |
| 715 | |
| 716 | if report.SecurityScore < tt.expectedMinScore { |
| 717 | t.Errorf("Security score too low: expected >= %d, got %d", |
| 718 | tt.expectedMinScore, report.SecurityScore) |
| 719 | } |
| 720 | }) |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | // TestSQLAnalyzer_SecurityScannerIntegration tests that the security scanner |
| 725 | // integration is working correctly to detect SQL injection patterns |
nothing calls this directly
no test coverage detected