From f470bf1b53c7c108475dc12324159013b9b8e830 Mon Sep 17 00:00:00 2001 From: Christian Claus Date: Sun, 17 Jun 2018 14:27:40 +0200 Subject: [PATCH] Fix unit tests #7 --- app/security.go | 2 +- app/security_test.go | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/security.go b/app/security.go index 1dde838..7ddf291 100644 --- a/app/security.go +++ b/app/security.go @@ -40,7 +40,7 @@ func NewBasicAuthWebdavHandler(a *App) http.Handler { func authenticate(config *Config, username, password string) (*AuthInfo, error) { if !config.AuthenticationNeeded() { - return &AuthInfo{Username: "", Authenticated: true}, nil + return &AuthInfo{Username: "", Authenticated: false}, nil } if username == "" || password == "" { diff --git a/app/security_test.go b/app/security_test.go index c6765ab..847c24a 100644 --- a/app/security_test.go +++ b/app/security_test.go @@ -24,7 +24,11 @@ func TestAuthenticate(t *testing.T) { { "empty username", args{ - config: &Config{}, + config: &Config{Users: map[string]*UserInfo{ + "foo": { + Password: GenHash([]byte("password")), + }, + }}, username: "", password: "password", }, @@ -37,7 +41,11 @@ func TestAuthenticate(t *testing.T) { { "empty password", args{ - config: &Config{}, + config: &Config{Users: map[string]*UserInfo{ + "foo": { + Password: GenHash([]byte("password")), + }, + }}, username: "foo", password: "", }, @@ -47,6 +55,32 @@ func TestAuthenticate(t *testing.T) { }, true, }, + { + "empty username without users", + args{ + config: &Config{}, + username: "", + password: "password", + }, + &AuthInfo{ + Username: "", + Authenticated: false, + }, + false, + }, + { + "empty password without users", + args{ + config: &Config{}, + username: "foo", + password: "", + }, + &AuthInfo{ + Username: "", + Authenticated: false, + }, + false, + }, { "user not found", args{