Skip to content

Commit f5b48c2

Browse files
committed
Merge branch 'develop' into release-0.29
2 parents 71e9dee + ff95b5e commit f5b48c2

File tree

5 files changed

+82
-3
lines changed

5 files changed

+82
-3
lines changed

go/channelling/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Config struct {
3434
RoomTypes map[*regexp.Regexp]string `json:"-"` // Map of regular expression -> room type
3535
RoomNameCaseSensitive bool // Whether the room names are case sensitive.
3636
LockedRoomJoinableWithPIN bool // Whether locked rooms should be joinable by providing the PIN the room was locked with
37+
PublicRoomNames *regexp.Regexp `json:"-"` // Regular expression that specifies room paths that may be created/joined without a user account.
3738
}
3839

3940
func (config *Config) WithModule(m string) bool {

go/channelling/room_manager.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,17 @@ func (rooms *roomManager) Get(roomID string) (room RoomWorker, ok bool) {
209209
return
210210
}
211211

212+
func (rooms *roomManager) isPublicRoom(roomName string) bool {
213+
return rooms.PublicRoomNames != nil &&
214+
rooms.PublicRoomNames.MatchString(roomName)
215+
}
216+
212217
func (rooms *roomManager) GetOrCreate(roomID, roomName, roomType string, credentials *DataRoomCredentials, sessionAuthenticated bool) (RoomWorker, error) {
218+
isPublic := false
213219
if rooms.AuthorizeRoomJoin && rooms.UsersEnabled && !sessionAuthenticated {
214-
return nil, NewDataError("room_join_requires_account", "Room join requires a user account")
220+
if isPublic = rooms.isPublicRoom(roomName); !isPublic {
221+
return nil, NewDataError("room_join_requires_account", "Room join requires a user account")
222+
}
215223
}
216224

217225
if room, ok := rooms.Get(roomID); ok {
@@ -231,8 +239,13 @@ func (rooms *roomManager) GetOrCreate(roomID, roomName, roomType string, credent
231239
}
232240

233241
if rooms.UsersEnabled && rooms.AuthorizeRoomCreation && !sessionAuthenticated {
234-
rooms.Unlock()
235-
return nil, NewDataError("room_join_requires_account", "Room creation requires a user account")
242+
// Only need to check for public room if not checked above.
243+
if !isPublic {
244+
if isPublic = rooms.isPublicRoom(roomName); !isPublic {
245+
rooms.Unlock()
246+
return nil, NewDataError("room_join_requires_account", "Room creation requires a user account")
247+
}
248+
}
236249
}
237250

238251
room := NewRoomWorker(rooms, roomID, roomName, roomType, credentials)

go/channelling/room_manager_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package channelling
2323

2424
import (
25+
"regexp"
2526
"testing"
2627

2728
"github.com/strukturag/spreed-webrtc/go/channelling"
@@ -74,6 +75,55 @@ func Test_RoomManager_JoinRoom_ReturnsAnErrorForUnauthenticatedSessionsWhenJoinR
7475
assertDataError(t, err, "room_join_requires_account")
7576
}
7677

78+
func Test_RoomManager_JoinPublicRoom_ForUnauthenticatedSessionsWhenCreationRequiresAnAccount(t *testing.T) {
79+
roomManager, config := NewTestRoomManager()
80+
config.UsersEnabled = true
81+
config.AuthorizeRoomCreation = true
82+
83+
unauthenticatedSession := &Session{}
84+
_, err := roomManager.JoinRoom(channelling.RoomTypeRoom+":public", "public", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
85+
assertDataError(t, err, "room_join_requires_account")
86+
87+
config.PublicRoomNames = regexp.MustCompile("^public$")
88+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":public", "public", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
89+
if err != nil {
90+
t.Fatalf("Unexpected error %v joining public room", err)
91+
}
92+
93+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":private", "private", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
94+
assertDataError(t, err, "room_join_requires_account")
95+
}
96+
97+
func Test_RoomManager_JoinPublicRoom_ForUnauthenticatedSessionsWhenJoinRequiresAnAccount(t *testing.T) {
98+
roomManager, config := NewTestRoomManager()
99+
config.UsersEnabled = true
100+
config.AuthorizeRoomJoin = true
101+
102+
authenticatedSession := &Session{userid: "9870457"}
103+
_, err := roomManager.JoinRoom(channelling.RoomTypeRoom+":public", "public", channelling.RoomTypeRoom, nil, authenticatedSession, true, nil)
104+
if err != nil {
105+
t.Fatalf("Unexpected error %v joining room while authenticated", err)
106+
}
107+
108+
unauthenticatedSession := &Session{}
109+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":public", "public", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
110+
assertDataError(t, err, "room_join_requires_account")
111+
112+
config.PublicRoomNames = regexp.MustCompile("^public$")
113+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":public", "public", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
114+
if err != nil {
115+
t.Fatalf("Unexpected error %v joining public room", err)
116+
}
117+
118+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":private", "private", channelling.RoomTypeRoom, nil, authenticatedSession, true, nil)
119+
if err != nil {
120+
t.Fatalf("Unexpected error %v joining room while authenticated", err)
121+
}
122+
123+
_, err = roomManager.JoinRoom(channelling.RoomTypeRoom+":private", "private", channelling.RoomTypeRoom, nil, unauthenticatedSession, false, nil)
124+
assertDataError(t, err, "room_join_requires_account")
125+
}
126+
77127
func Test_RoomManager_UpdateRoom_ReturnsAnErrorIfNoRoomHasBeenJoined(t *testing.T) {
78128
roomManager, _ := NewTestRoomManager()
79129
_, err := roomManager.UpdateRoom(&Session{}, nil)

go/channelling/server/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ func NewConfig(container phoenix.Container, tokens bool) (*channelling.Config, e
119119
}
120120
}
121121

122+
publicRoomNamesString := container.GetStringDefault("app", "publicRooms", "")
123+
var publicRoomNames *regexp.Regexp
124+
if publicRoomNamesString != "" {
125+
var err error
126+
if publicRoomNames, err = regexp.Compile(publicRoomNamesString); err != nil {
127+
return nil, fmt.Errorf("Invalid regular expression '%s': %s", publicRoomNamesString, err)
128+
}
129+
log.Printf("Allowed public rooms: %s\n", publicRoomNamesString)
130+
}
131+
122132
return &channelling.Config{
123133
Title: container.GetStringDefault("app", "title", "Spreed WebRTC"),
124134
Ver: ver,
@@ -148,6 +158,7 @@ func NewConfig(container phoenix.Container, tokens bool) (*channelling.Config, e
148158
RoomTypes: roomTypes,
149159
RoomNameCaseSensitive: container.GetBoolDefault("app", "caseSensitiveRooms", false),
150160
LockedRoomJoinableWithPIN: container.GetBoolDefault("app", "lockedRoomJoinableWithPIN", true),
161+
PublicRoomNames: publicRoomNames,
151162
}, nil
152163
}
153164

server.conf.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ encryptionSecret = tne-default-encryption-block-key
100100
; Whether locked rooms should be joinable by providing the PIN the room was
101101
; locked with. Optional, defaults to true.
102102
;lockedRoomJoinableWithPIN = true
103+
; Regular expression specifying room names that can be created / joined without
104+
; a valid user account (even if "authorizeRoomJoin" or "authorizeRoomCreation"
105+
; is enabled).
106+
;publicRooms =
103107
; Whether the pipelines API should be enabled. Optional, defaults to false.
104108
;pipelinesEnabled = false
105109
; Server token is a public random string which is used to enhance security of

0 commit comments

Comments
 (0)