Implement some MFA endpoints for APIv4 (#5864)

Этот коммит содержится в:
Joram Wilander
2017-03-27 09:21:48 -04:00
коммит произвёл GitHub
родитель a0d5c01dfd
Коммит 58397f853a
7 изменённых файлов: 238 добавлений и 21 удалений

Просмотреть файл

@@ -1009,6 +1009,86 @@ func TestGetUsersNotInChannel(t *testing.T) {
CheckNotImplementedStatus(t, resp)
}*/
func TestCheckUserMfa(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client
required, resp := Client.CheckUserMfa(th.BasicUser.Email)
CheckNoError(t, resp)
if required {
t.Fatal("should be false - mfa not active")
}
_, resp = Client.CheckUserMfa("")
CheckBadRequestStatus(t, resp)
Client.Logout()
required, resp = Client.CheckUserMfa(th.BasicUser.Email)
CheckNoError(t, resp)
if required {
t.Fatal("should be false - mfa not active")
}
isLicensed := utils.IsLicensed
license := utils.License
enableMfa := *utils.Cfg.ServiceSettings.EnableMultifactorAuthentication
defer func() {
utils.IsLicensed = isLicensed
utils.License = license
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = enableMfa
}()
utils.IsLicensed = true
utils.License = &model.License{Features: &model.Features{}}
utils.License.Features.SetDefaults()
*utils.License.Features.MFA = true
*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication = true
th.LoginBasic()
required, resp = Client.CheckUserMfa(th.BasicUser.Email)
CheckNoError(t, resp)
if required {
t.Fatal("should be false - mfa not active")
}
Client.Logout()
required, resp = Client.CheckUserMfa(th.BasicUser.Email)
CheckNoError(t, resp)
if required {
t.Fatal("should be false - mfa not active")
}
}
func TestGenerateMfaSecret(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client
_, resp := Client.GenerateMfaSecret(th.BasicUser.Id)
CheckNotImplementedStatus(t, resp)
_, resp = Client.GenerateMfaSecret("junk")
CheckBadRequestStatus(t, resp)
_, resp = Client.GenerateMfaSecret(model.NewId())
CheckForbiddenStatus(t, resp)
Client.Logout()
_, resp = Client.GenerateMfaSecret(th.BasicUser.Id)
CheckUnauthorizedStatus(t, resp)
_, resp = th.SystemAdminClient.GenerateMfaSecret(th.BasicUser.Id)
CheckNotImplementedStatus(t, resp)
}
func TestUpdateUserPassword(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()