lock and unlock should now broadcast to the hall. Users trying to enter if hall is locked should now get message indicating the hall is locked. Removed redundant start with options. Browser requests mic permissions, also there is a mute option in the ui itself, so this seemed superfluous
This commit is contained in:
+2
-2
@@ -549,7 +549,7 @@ func AddClient(hall string, c Client, creds ClientCredentials) (*Hall, error) {
|
||||
if g.locked != nil {
|
||||
m := *g.locked
|
||||
if m == "" {
|
||||
m = "this hall is locked"
|
||||
m = "Hall is locked."
|
||||
}
|
||||
return nil, UserError(m)
|
||||
}
|
||||
@@ -632,7 +632,7 @@ func autoLockKick(g *Hall) {
|
||||
}
|
||||
}
|
||||
if g.description.Autolock && g.locked == nil {
|
||||
m := "this hall is locked"
|
||||
m := "Hall is locked."
|
||||
g.locked = &m
|
||||
for _, c := range clients {
|
||||
c.Joined(g.Name(), "change")
|
||||
|
||||
@@ -4,10 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.stormux.org/storm/skald/conn"
|
||||
"github.com/pion/webrtc/v4"
|
||||
)
|
||||
|
||||
@@ -121,6 +125,81 @@ func TestChatHistory(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type testClient struct {
|
||||
id string
|
||||
username string
|
||||
permissions []string
|
||||
}
|
||||
|
||||
func (c *testClient) Hall() *Hall { return nil }
|
||||
func (c *testClient) Addr() net.Addr { return nil }
|
||||
func (c *testClient) Id() string { return c.id }
|
||||
func (c *testClient) Username() string { return c.username }
|
||||
func (c *testClient) SetUsername(username string) { c.username = username }
|
||||
func (c *testClient) Permissions() []string { return c.permissions }
|
||||
func (c *testClient) SetPermissions(permissions []string) { c.permissions = permissions }
|
||||
func (c *testClient) Data() map[string]interface{} { return nil }
|
||||
func (c *testClient) PushConn(*Hall, string, conn.Up, []conn.UpTrack, string) error {
|
||||
return nil
|
||||
}
|
||||
func (c *testClient) RequestConns(Client, *Hall, string) error { return nil }
|
||||
func (c *testClient) Joined(string, string) error { return nil }
|
||||
func (c *testClient) PushClient(string, string, string, string, []string, map[string]interface{}) error {
|
||||
return nil
|
||||
}
|
||||
func (c *testClient) Kick(string, *string, string) error { return nil }
|
||||
|
||||
func TestLockedHallJoinMessage(t *testing.T) {
|
||||
halls.halls = nil
|
||||
oldDirectory := Directory
|
||||
Directory = t.TempDir()
|
||||
t.Cleanup(func() {
|
||||
Directory = oldDirectory
|
||||
halls.halls = nil
|
||||
})
|
||||
|
||||
err := os.WriteFile(
|
||||
filepath.Join(Directory, "locked-message-test.json"),
|
||||
[]byte(`{
|
||||
"users": {
|
||||
"user1": {"password": "secret", "permissions": "present"},
|
||||
"admin": {"password": "secret", "permissions": "op"}
|
||||
}
|
||||
}`),
|
||||
0644,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("WriteFile: %v", err)
|
||||
}
|
||||
|
||||
g, err := Add("locked-message-test", nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Add: %v", err)
|
||||
}
|
||||
g.SetLocked(true, "")
|
||||
|
||||
username := "user1"
|
||||
_, err = AddClient(g.Name(), &testClient{id: "user1"}, ClientCredentials{
|
||||
Username: &username,
|
||||
Password: "secret",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("AddClient unexpectedly succeeded")
|
||||
}
|
||||
if got, want := err.Error(), "Hall is locked."; got != want {
|
||||
t.Fatalf("locked join message: got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
adminUsername := "admin"
|
||||
_, err = AddClient(g.Name(), &testClient{id: "admin"}, ClientCredentials{
|
||||
Username: &adminUsername,
|
||||
Password: "secret",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("operator join should bypass lock: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func permissionsEqual(a, b []string) bool {
|
||||
// nil case
|
||||
if len(a) == 0 && len(b) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user