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) {
if !config.AuthenticationNeeded() {
return &AuthInfo{Username: "", Authenticated: true}, nil
return &AuthInfo{Username: "", Authenticated: false}, nil
}
if username == "" || password == "" {

View file

@ -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{