From d867de4d045f95aca6bd7383e09f3281799aa7cc Mon Sep 17 00:00:00 2001 From: SuperQ Date: Thu, 15 Jun 2023 13:51:37 +0200 Subject: [PATCH] Allow empty passwords Empty passwords are allowed for UNIX socket connections and when using TLS auth. Fixes: https://github.com/prometheus/mysqld_exporter/issues/686 Signed-off-by: SuperQ --- config/config.go | 3 --- config/config_test.go | 14 ++++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/config/config.go b/config/config.go index f31ef8f..713835c 100644 --- a/config/config.go +++ b/config/config.go @@ -167,9 +167,6 @@ func (m MySqlConfig) validateConfig() error { if m.User == "" { return fmt.Errorf("no user specified in section or parent") } - if m.Password == "" { - return fmt.Errorf("no password specified in section or parent") - } return nil } diff --git a/config/config_test.go b/config/config_test.go index 3d90e93..a282efc 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -130,12 +130,14 @@ func TestValidateConfig(t *testing.T) { Config: &Config{}, } os.Clearenv() - err := c.ReloadConfig("testdata/missing_password.cnf", "localhost:3306", "", true, log.NewNopLogger()) - convey.So( - err, - convey.ShouldResemble, - fmt.Errorf("no configuration found"), - ) + if err := c.ReloadConfig("testdata/missing_password.cnf", "localhost:3306", "", true, log.NewNopLogger()); err != nil { + t.Error(err) + } + + cfg := c.GetConfig() + section := cfg.Sections["client"] + convey.So(section.User, convey.ShouldEqual, "abc") + convey.So(section.Password, convey.ShouldEqual, "") }) }