[PLT-7793] Add /users/tokens/search endpoint (#8088)
* Add /users/tokens/search endpoint + tests * Fix check-style * Unnecessary deletion
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
1d9efd0e39
Коммит
b1d13a2d89
@@ -2469,6 +2469,52 @@ func TestGetUserAccessToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearchUserAccessToken(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
AdminClient := th.SystemAdminClient
|
||||
|
||||
testDescription := "test token"
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableUserAccessTokens = true })
|
||||
|
||||
th.App.UpdateUserRoles(th.BasicUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_USER_ACCESS_TOKEN_ROLE_ID, false)
|
||||
token, resp := Client.CreateUserAccessToken(th.BasicUser.Id, testDescription)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
_, resp = Client.SearchUserAccessTokens(&model.UserAccessTokenSearch{Term: token.Id})
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
rtokens, resp := AdminClient.SearchUserAccessTokens(&model.UserAccessTokenSearch{Term: th.BasicUser.Id})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(rtokens) != 1 {
|
||||
t.Fatal("should have 1 tokens")
|
||||
}
|
||||
|
||||
rtokens, resp = AdminClient.SearchUserAccessTokens(&model.UserAccessTokenSearch{Term: token.Id})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(rtokens) != 1 {
|
||||
t.Fatal("should have 1 tokens")
|
||||
}
|
||||
|
||||
rtokens, resp = AdminClient.SearchUserAccessTokens(&model.UserAccessTokenSearch{Term: th.BasicUser.Username})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(rtokens) != 1 {
|
||||
t.Fatal("should have 1 tokens")
|
||||
}
|
||||
|
||||
rtokens, resp = AdminClient.SearchUserAccessTokens(&model.UserAccessTokenSearch{Term: "not found"})
|
||||
CheckNoError(t, resp)
|
||||
|
||||
if len(rtokens) != 0 {
|
||||
t.Fatal("should have 0 tokens")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRevokeUserAccessToken(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user