diff --git a/notify/email/email_test.go b/notify/email/email_test.go index a57faf2d..dbae14ad 100644 --- a/notify/email/email_test.go +++ b/notify/email/email_test.go @@ -513,6 +513,16 @@ func TestEmailNotifyWithAuthentication(t *testing.T) { errMsg: "Invalid username or password", retry: true, }, + { + title: "wrong credentials (missing password file)", + updateCfg: func(cfg *config.EmailConfig) { + cfg.AuthUsername = c.Username + cfg.AuthPasswordFile = "/does/not/exist" + }, + + errMsg: "could not read", + retry: true, + }, { title: "no credentials", errMsg: "authentication Required", @@ -633,59 +643,3 @@ func TestEmailNoUsernameStillOk(t *testing.T) { require.NoError(t, err) require.Nil(t, a) } - -func TestEmailGetPassword(t *testing.T) { - passwordFile, err := os.CreateTemp("", "smtp-password") - require.NoError(t, err, "creating temp file failed") - _, err = passwordFile.WriteString("secret") - require.NoError(t, err, "writing to temp file failed") - - for _, tc := range []struct { - title string - updateCfg func(*config.EmailConfig) - - errMsg string - }{ - { - title: "password from field", - updateCfg: func(cfg *config.EmailConfig) { - cfg.AuthPassword = "secret" - cfg.AuthPasswordFile = "" - }, - }, - { - title: "password from file field", - updateCfg: func(cfg *config.EmailConfig) { - cfg.AuthPassword = "" - cfg.AuthPasswordFile = passwordFile.Name() - }, - }, - { - title: "password file path incorrect", - updateCfg: func(cfg *config.EmailConfig) { - cfg.AuthPassword = "" - cfg.AuthPasswordFile = "/does/not/exist" - }, - errMsg: "could not read", - }, - } { - tc := tc - t.Run(tc.title, func(t *testing.T) { - email := &Email{ - conf: &config.EmailConfig{}, - } - - tc.updateCfg(email.conf) - - password, err := email.getPassword() - if len(tc.errMsg) > 0 { - require.Error(t, err) - require.Contains(t, err.Error(), tc.errMsg) - require.Equal(t, "", password) - } else { - require.Nil(t, err) - require.Equal(t, "secret", password) - } - }) - } -}