Skip to content

Commit 1a628d1

Browse files
committed
Fix cqlshrc SSL boolean values not being parsed case-insensitively
Python's cqlsh writes True/False with capital letters. Our comparisons were case-sensitive so 'ssl = True' never enabled SSL from [connection], and 'validate = False' fell into the else branch and incorrectly set HostVerification=true instead of InsecureSkipVerify=true. Fix by using strings.ToLower before comparing boolean values in loadCQLSHRC.
1 parent 492cac1 commit 1a628d1

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

internal/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func loadCQLSHRC(path string, config *Config) error {
468468
logger.DebugfToFile("CQLSHRC", "Failed to parse port value: %s", value)
469469
}
470470
case "ssl":
471-
if value == "true" || value == "1" {
471+
if strings.ToLower(value) == "true" || value == "1" {
472472
if config.SSL == nil {
473473
config.SSL = &SSLConfig{}
474474
}
@@ -539,7 +539,7 @@ func loadCQLSHRC(path string, config *Config) error {
539539
config.SSL.CertPath = value
540540
logger.DebugfToFile("CQLSHRC", "Set cert path to: %s", value)
541541
case "validate":
542-
if value == "false" || value == "0" {
542+
if strings.ToLower(value) == "false" || value == "0" {
543543
config.SSL.InsecureSkipVerify = true
544544
config.SSL.HostVerification = false
545545
logger.DebugfToFile("CQLSHRC", "Set InsecureSkipVerify to true and HostVerification to false")

internal/config/config_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,48 @@ validate = false
103103
}
104104
}
105105

106+
// TestLoadCQLSHRCPythonBooleans verifies that Python-style True/False values
107+
// (as written by cqlsh) are handled case-insensitively.
108+
func TestLoadCQLSHRCPythonBooleans(t *testing.T) {
109+
tmpDir := t.TempDir()
110+
cqlshrcPath := filepath.Join(tmpDir, "cqlshrc")
111+
112+
// Python cqlsh writes True/False with capital letters
113+
cqlshrcContent := `[connection]
114+
hostname = pyhost.example.com
115+
port = 9042
116+
ssl = True
117+
118+
[ssl]
119+
certfile = ~/certs/ca.pem
120+
validate = False
121+
`
122+
if err := os.WriteFile(cqlshrcPath, []byte(cqlshrcContent), 0600); err != nil {
123+
t.Fatalf("Failed to create test cqlshrc file: %v", err)
124+
}
125+
126+
config := &Config{Host: "localhost", Port: 9042}
127+
if err := loadCQLSHRC(cqlshrcPath, config); err != nil {
128+
t.Fatalf("Failed to load cqlshrc: %v", err)
129+
}
130+
131+
if config.Host != "pyhost.example.com" {
132+
t.Errorf("Expected host 'pyhost.example.com', got '%s'", config.Host)
133+
}
134+
if config.SSL == nil {
135+
t.Fatal("Expected SSL config to be set")
136+
}
137+
if !config.SSL.Enabled {
138+
t.Error("Expected SSL to be enabled (ssl = True)")
139+
}
140+
if !config.SSL.InsecureSkipVerify {
141+
t.Error("Expected InsecureSkipVerify to be true (validate = False)")
142+
}
143+
if config.SSL.HostVerification {
144+
t.Error("Expected HostVerification to be false (validate = False)")
145+
}
146+
}
147+
106148
func TestLoadCredentialsFile(t *testing.T) {
107149
// Create a temporary credentials file
108150
tmpDir := t.TempDir()

0 commit comments

Comments
 (0)