Always use auth userid in ping requests.
Fixes issue introduced in 3a2adffab6
where some
ping requests were not evaluated correctly if a userid was given in the room
session data.
This commit is contained in:
parent
da5890a1c7
commit
52c1514978
|
@ -239,6 +239,10 @@ func (s *ClientSession) ParsedBackendUrl() *url.URL {
|
|||
return s.parsedBackendUrl
|
||||
}
|
||||
|
||||
func (s *ClientSession) AuthUserId() string {
|
||||
return s.userId
|
||||
}
|
||||
|
||||
func (s *ClientSession) UserId() string {
|
||||
userId := s.userId
|
||||
if userId == "" {
|
||||
|
@ -449,7 +453,7 @@ func (s *ClientSession) doUnsubscribeRoomNats(notify bool) {
|
|||
// Notify
|
||||
go func(sid string) {
|
||||
ctx := context.Background()
|
||||
request := NewBackendClientRoomRequest(room.Id(), s.UserId(), sid)
|
||||
request := NewBackendClientRoomRequest(room.Id(), s.userId, sid)
|
||||
request.Room.Action = "leave"
|
||||
var response map[string]interface{}
|
||||
if err := s.hub.backend.PerformJSONRequest(ctx, s.ParsedBackendUrl(), request, &response); err != nil {
|
||||
|
|
27
hub_test.go
27
hub_test.go
|
@ -299,6 +299,31 @@ func processSessionRequest(t *testing.T, w http.ResponseWriter, r *http.Request,
|
|||
return response
|
||||
}
|
||||
|
||||
func processPingRequest(t *testing.T, w http.ResponseWriter, r *http.Request, request *BackendClientRequest) *BackendClientResponse {
|
||||
if request.Type != "ping" || request.Ping == nil {
|
||||
t.Fatalf("Expected an ping backend request, got %+v", request)
|
||||
}
|
||||
|
||||
if request.Ping.RoomId == "test-room-with-sessiondata" {
|
||||
if entries := request.Ping.Entries; len(entries) != 1 {
|
||||
t.Errorf("Expected one entry, got %+v", entries)
|
||||
} else {
|
||||
if entries[0].UserId != "" {
|
||||
t.Errorf("Expected empty userid, got %+v", entries[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response := &BackendClientResponse{
|
||||
Type: "ping",
|
||||
Ping: &BackendClientRingResponse{
|
||||
Version: BackendVersion,
|
||||
RoomId: request.Ping.RoomId,
|
||||
},
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
func registerBackendHandler(t *testing.T, router *mux.Router) {
|
||||
registerBackendHandlerUrl(t, router, "/")
|
||||
}
|
||||
|
@ -312,6 +337,8 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
return processRoomRequest(t, w, r, request)
|
||||
case "session":
|
||||
return processSessionRequest(t, w, r, request)
|
||||
case "ping":
|
||||
return processPingRequest(t, w, r, request)
|
||||
default:
|
||||
t.Fatalf("Unsupported request received: %+v", request)
|
||||
return nil
|
||||
|
|
15
room.go
15
room.go
|
@ -638,7 +638,7 @@ func (r *Room) publishSessionFlagsChanged(session *VirtualSession) {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Room) publishActiveSessions() {
|
||||
func (r *Room) publishActiveSessions() (int, *sync.WaitGroup) {
|
||||
r.mu.RLock()
|
||||
defer r.mu.RUnlock()
|
||||
|
||||
|
@ -651,13 +651,16 @@ func (r *Room) publishActiveSessions() {
|
|||
}
|
||||
|
||||
var sid string
|
||||
var uid string
|
||||
switch sess := session.(type) {
|
||||
case *ClientSession:
|
||||
// Use Nextcloud session id
|
||||
// Use Nextcloud session id and user id
|
||||
sid = sess.RoomSessionId()
|
||||
uid = sess.AuthUserId()
|
||||
case *VirtualSession:
|
||||
// Use our internal generated session id (will be added to Nextcloud).
|
||||
sid = sess.PublicId()
|
||||
uid = sess.UserId()
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
@ -676,14 +679,17 @@ func (r *Room) publishActiveSessions() {
|
|||
|
||||
entries[u] = append(e, BackendPingEntry{
|
||||
SessionId: sid,
|
||||
UserId: session.UserId(),
|
||||
UserId: uid,
|
||||
})
|
||||
}
|
||||
var wg sync.WaitGroup
|
||||
if len(urls) == 0 {
|
||||
return
|
||||
return 0, &wg
|
||||
}
|
||||
for u, e := range entries {
|
||||
wg.Add(1)
|
||||
go func(url *url.URL, entries []BackendPingEntry) {
|
||||
defer wg.Done()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), r.hub.backendTimeout)
|
||||
defer cancel()
|
||||
|
||||
|
@ -694,6 +700,7 @@ func (r *Room) publishActiveSessions() {
|
|||
}
|
||||
}(urls[u], e)
|
||||
}
|
||||
return len(entries), &wg
|
||||
}
|
||||
|
||||
func (r *Room) publishRoomMessage(message *BackendRoomMessageRequest) {
|
||||
|
|
11
room_test.go
11
room_test.go
|
@ -407,4 +407,15 @@ func TestRoom_RoomSessionData(t *testing.T) {
|
|||
if userid := session.UserId(); userid != expected {
|
||||
t.Errorf("Expected userid %s, got %s", expected, userid)
|
||||
}
|
||||
|
||||
room := hub.getRoom(roomId)
|
||||
if room == nil {
|
||||
t.Fatalf("Room not found")
|
||||
}
|
||||
|
||||
entries, wg := room.publishActiveSessions()
|
||||
if entries != 1 {
|
||||
t.Errorf("expected 1 entries, got %d", entries)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue