Fix unit tests #7

This commit is contained in:
Christian Claus 2018-06-17 14:27:40 +02:00
parent a387121726
commit f470bf1b53
2 changed files with 37 additions and 3 deletions

View file

@ -40,7 +40,7 @@ func NewBasicAuthWebdavHandler(a *App) http.Handler {
func authenticate(config *Config, username, password string) (*AuthInfo, error) { func authenticate(config *Config, username, password string) (*AuthInfo, error) {
if !config.AuthenticationNeeded() { if !config.AuthenticationNeeded() {
return &AuthInfo{Username: "", Authenticated: true}, nil return &AuthInfo{Username: "", Authenticated: false}, nil
} }
if username == "" || password == "" { if username == "" || password == "" {

View file

@ -24,7 +24,11 @@ func TestAuthenticate(t *testing.T) {
{ {
"empty username", "empty username",
args{ args{
config: &Config{}, config: &Config{Users: map[string]*UserInfo{
"foo": {
Password: GenHash([]byte("password")),
},
}},
username: "", username: "",
password: "password", password: "password",
}, },
@ -37,7 +41,11 @@ func TestAuthenticate(t *testing.T) {
{ {
"empty password", "empty password",
args{ args{
config: &Config{}, config: &Config{Users: map[string]*UserInfo{
"foo": {
Password: GenHash([]byte("password")),
},
}},
username: "foo", username: "foo",
password: "", password: "",
}, },
@ -47,6 +55,32 @@ func TestAuthenticate(t *testing.T) {
}, },
true, 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", "user not found",
args{ args{