Fix unit tests #7
This commit is contained in:
parent
a387121726
commit
f470bf1b53
2 changed files with 37 additions and 3 deletions
|
@ -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 == "" {
|
||||||
|
|
|
@ -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{
|
||||||
|
|
Loading…
Reference in a new issue