diff options
author | Rick Batka <rick.batka@gmail.com> | 2017-10-16 23:50:31 -0400 |
---|---|---|
committer | Chris <ccbrown112@gmail.com> | 2017-10-16 20:50:31 -0700 |
commit | 89dc3cb126ba46b486997c433adfdf34982fcc81 (patch) | |
tree | 57ed40c1c193aeec17cea8ab7f7e52d63e44fad4 /api4/user_test.go | |
parent | a649602fc373615665ae2eaec95a4e9063eb699d (diff) | |
download | chat-89dc3cb126ba46b486997c433adfdf34982fcc81.tar.gz chat-89dc3cb126ba46b486997c433adfdf34982fcc81.tar.bz2 chat-89dc3cb126ba46b486997c433adfdf34982fcc81.zip |
[PLT-7396] Add the ability to revoke user sessions in System Console > Users #7493 (#7623)
* add endpoint and tests for revoking all sessions for a user
* fix failing test build
Diffstat (limited to 'api4/user_test.go')
-rw-r--r-- | api4/user_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/api4/user_test.go b/api4/user_test.go index 0913819cc..3a1579e14 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -1971,6 +1971,51 @@ func TestRevokeSessions(t *testing.T) { CheckNoError(t, resp) } +func TestRevokeAllSessions(t *testing.T) { + th := Setup().InitBasic() + defer th.TearDown() + Client := th.Client + + user := th.BasicUser + Client.Login(user.Email, user.Password) + + _, resp := Client.RevokeAllSessions(th.BasicUser2.Id) + CheckForbiddenStatus(t, resp) + + th.InitSystemAdmin() + + _, resp = Client.RevokeAllSessions("junk" + user.Id) + CheckBadRequestStatus(t, resp) + + status, resp := Client.RevokeAllSessions(user.Id) + if status == false { + t.Fatal("user all sessions revoke unsuccessful") + } + CheckNoError(t, resp) + + Client.Logout() + _, resp = Client.RevokeAllSessions(user.Id) + CheckUnauthorizedStatus(t, resp) + + Client.Login(user.Email, user.Password) + + sessions, _ := Client.GetSessions(user.Id, "") + if len(sessions) < 1 { + t.Fatal("session should exist") + } + + _, resp = Client.RevokeAllSessions(user.Id) + CheckNoError(t, resp) + + sessions, _ = th.SystemAdminClient.GetSessions(user.Id, "") + if len(sessions) != 0 { + t.Fatal("no sessions should exist for user") + } + + _, resp = Client.RevokeAllSessions(user.Id) + CheckUnauthorizedStatus(t, resp) +} + func TestAttachDeviceId(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() |