Skip to content

Commit

Permalink
feat: remove session
Browse files Browse the repository at this point in the history
  • Loading branch information
andygeiss committed Jan 21, 2025
1 parent dd7194f commit b6c0661
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions security/server_sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ func (a *ServerSessions) Get(sessionID string) (*ServerSession, bool) {
info, ok := a.sessions[sessionID]
return &info, ok
}

// Remove removes the session for the given sessionID.
func (a *ServerSessions) Remove(sessionID string) {
a.mutex.Lock()
defer a.mutex.Unlock()
delete(a.sessions, sessionID)
}
8 changes: 8 additions & 0 deletions security/server_sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ func TestServerSessions_Get(t *testing.T) {
assert.That(t, "session must be found", found, true)
assert.That(t, "session is correct", *current, session)
}

func TestServerSessions_Remove(t *testing.T) {
sessions := security.NewServerSessions()
id := sessions.Update(security.ServerSession{AvatarURL: "avatar_url", Name: "name"})
sessions.Remove(id)
_, found := sessions.Get(id)
assert.That(t, "session must not be found", found, false)
}

0 comments on commit b6c0661

Please sign in to comment.