fix(doctor): address code review issues in --server health checks

- Use parameterized query for INFORMATION_SCHEMA lookup (SQL injection)
- Add isValidIdentifier() to validate database names before USE statement
- Add password support via BEADS_DOLT_PASSWORD env var
- Remove unused variable declaration
- Add unit tests for identifier validation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beads/crew/emma
2026-01-23 20:35:57 -08:00
committed by Steve Yegge
parent 66d994264b
commit 3bcbca41fe
2 changed files with 85 additions and 9 deletions

View File

@@ -0,0 +1,32 @@
package doctor
import "testing"
func TestIsValidIdentifier(t *testing.T) {
tests := []struct {
input string
want bool
}{
{"beads", true},
{"beads_db", true},
{"Beads123", true},
{"_private", true},
{"123start", false}, // Can't start with number
{"", false}, // Empty string
{"db-name", false}, // Hyphen not allowed
{"db.name", false}, // Dot not allowed
{"db name", false}, // Space not allowed
{"db;drop", false}, // Semicolon not allowed
{"db'inject", false}, // Quote not allowed
{"beads_test_db", true}, // Multiple underscores ok
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := isValidIdentifier(tt.input)
if got != tt.want {
t.Errorf("isValidIdentifier(%q) = %v, want %v", tt.input, got, tt.want)
}
})
}
}