diff options
author | Peter De Wachter <pdewacht@gmail.com> | 2019-01-01 21:53:52 +0100 |
---|---|---|
committer | fguillot <fred@miniflux.net> | 2019-01-07 18:25:59 -0800 |
commit | 6f5ef1055337bc1abfc8c59bc89cd9934def80a6 (patch) | |
tree | 09b6dc649f760d0b01af5b755b6550501cc093b7 /ui | |
parent | 28ba09e952e9875ad701e51bf524bbe7589efb25 (diff) |
Only attempt to change password if the confirmation field is filled in
Firefox autocompletes the password field (but not the password
confirmation field) for me. This makes it annoying to use the settings
page, because miniflux thinks I'm trying to change my password and
complains that the fields don't match.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/form/settings.go | 7 | ||||
-rw-r--r-- | ui/form/settings_test.go | 60 |
2 files changed, 66 insertions, 1 deletions
diff --git a/ui/form/settings.go b/ui/form/settings.go index 97c8f6e..0377f5f 100644 --- a/ui/form/settings.go +++ b/ui/form/settings.go @@ -43,7 +43,12 @@ func (s *SettingsForm) Validate() error { return errors.NewLocalizedError("error.settings_mandatory_fields") } - if s.Password != "" { + if s.Confirmation == "" { + // Firefox insists on auto-completing the password field. + // If the confirmation field is blank, the user probably + // didn't intend to change their password. + s.Password = "" + } else if s.Password != "" { if s.Password != s.Confirmation { return errors.NewLocalizedError("error.different_passwords") } diff --git a/ui/form/settings_test.go b/ui/form/settings_test.go new file mode 100644 index 0000000..245ce76 --- /dev/null +++ b/ui/form/settings_test.go @@ -0,0 +1,60 @@ +package form // import "miniflux.app/ui/form" + +import ( + "testing" +) + +func TestValid(t *testing.T) { + settings := &SettingsForm{ + Username: "user", + Password: "hunter2", + Confirmation: "hunter2", + Theme: "default", + Language: "en_US", + Timezone: "UTC", + EntryDirection: "asc", + } + + err := settings.Validate() + if err != nil { + t.Error(err) + } +} + +func TestConfirmationEmpty(t *testing.T) { + settings := &SettingsForm{ + Username: "user", + Password: "hunter2", + Confirmation: "", + Theme: "default", + Language: "en_US", + Timezone: "UTC", + EntryDirection: "asc", + } + + err := settings.Validate() + if err != nil { + t.Error(err) + } + + if settings.Password != "" { + t.Error("Password should have been cleared") + } +} + +func TestConfirmationIncorrect(t *testing.T) { + settings := &SettingsForm{ + Username: "user", + Password: "hunter2", + Confirmation: "unter2", + Theme: "default", + Language: "en_US", + Timezone: "UTC", + EntryDirection: "asc", + } + + err := settings.Validate() + if err == nil { + t.Error("Validate should return an error") + } +} |