seafile: fix error when not configured for 2fa (#5665)

This commit is contained in:
Fred 2021-10-19 20:53:35 +01:00 committed by GitHub
parent eb0c8284f1
commit b085aa1a3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -310,7 +310,8 @@ func Config(ctx context.Context, name string, m configmap.Mapper, config fs.Conf
is2faEnabled, _ := m.Get(config2FA) is2faEnabled, _ := m.Get(config2FA)
if is2faEnabled != "true" { if is2faEnabled != "true" {
return nil, errors.New("two-factor authentication is not enabled on this account") // no need to do anything here
return nil, nil
} }
username, _ := m.Get(configUser) username, _ := m.Get(configUser)

View File

@ -136,6 +136,7 @@ func Test2FAStateMachine(t *testing.T) {
expectErrorMessage string expectErrorMessage string
expectResult string expectResult string
expectFail bool expectFail bool
expectNil bool
}{ }{
{ {
name: "no url", name: "no url",
@ -143,18 +144,18 @@ func Test2FAStateMachine(t *testing.T) {
input: fs.ConfigIn{State: ""}, input: fs.ConfigIn{State: ""},
expectFail: true, expectFail: true,
}, },
{
name: "2fa not set",
mapper: configmap.Simple{"url": "http://localhost/"},
input: fs.ConfigIn{State: ""},
expectFail: true,
},
{ {
name: "unknown state", name: "unknown state",
mapper: configmap.Simple{"url": "http://localhost/", "2fa": "true", "user": "username"}, mapper: configmap.Simple{"url": "http://localhost/", "2fa": "true", "user": "username"},
input: fs.ConfigIn{State: "unknown"}, input: fs.ConfigIn{State: "unknown"},
expectFail: true, expectFail: true,
}, },
{
name: "2fa not set",
mapper: configmap.Simple{"url": "http://localhost/"},
input: fs.ConfigIn{State: ""},
expectNil: true,
},
{ {
name: "no password in config", name: "no password in config",
mapper: configmap.Simple{"url": "http://localhost/", "2fa": "true", "user": "username"}, mapper: configmap.Simple{"url": "http://localhost/", "2fa": "true", "user": "username"},
@ -215,6 +216,10 @@ func Test2FAStateMachine(t *testing.T) {
t.Log(err) t.Log(err)
return return
} }
if fixture.expectNil {
require.Nil(t, output)
return
}
assert.Equal(t, fixture.expectState, output.State) assert.Equal(t, fixture.expectState, output.State)
assert.Equal(t, fixture.expectErrorMessage, output.Error) assert.Equal(t, fixture.expectErrorMessage, output.Error)
assert.Equal(t, fixture.expectResult, output.Result) assert.Equal(t, fixture.expectResult, output.Result)