Start work on improving recordings.

This commit is contained in:
Storm Dragon
2026-05-23 23:33:30 -04:00
parent 08b484f106
commit 3e06de7501
8 changed files with 662 additions and 105 deletions
+90 -1
View File
@@ -129,6 +129,14 @@ type testClient struct {
id string
username string
permissions []string
pushed []pushedClient
}
type pushedClient struct {
kind string
id string
username string
permissions []string
}
func (c *testClient) Hall() *Hall { return nil }
@@ -144,11 +152,92 @@ func (c *testClient) PushConn(*Hall, string, conn.Up, []conn.UpTrack, string) er
}
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 {
func (c *testClient) PushClient(_ string, kind string, id string, username string, permissions []string, _ map[string]interface{}) error {
c.pushed = append(c.pushed, pushedClient{
kind: kind,
id: id,
username: username,
permissions: permissions,
})
return nil
}
func (c *testClient) Kick(string, *string, string) error { return nil }
func TestSystemClientIsNotAdvertisedToUsers(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, "system-hidden-test.json"),
[]byte(`{
"users": {
"user1": {"password": "secret", "permissions": "present"},
"user2": {"password": "secret", "permissions": "present"}
}
}`),
0600,
)
if err != nil {
t.Fatal(err)
}
user1 := &testClient{id: "user1-client"}
g, err := AddClient("system-hidden-test", user1, ClientCredentials{
Username: strPtr("user1"),
Password: "secret",
})
if err != nil {
t.Fatal(err)
}
user1.pushed = nil
recorder := &testClient{
id: "recorder-client",
username: "RECORDING",
permissions: []string{"system"},
}
_, err = AddClient("system-hidden-test", recorder, ClientCredentials{
System: true,
})
if err != nil {
t.Fatal(err)
}
if len(user1.pushed) != 0 {
t.Fatalf("user saw system recorder client: %#v", user1.pushed)
}
if count := g.ClientCount(); count != 1 {
t.Fatalf("client count with recorder = %d, expected 1", count)
}
user2 := &testClient{id: "user2-client"}
_, err = AddClient("system-hidden-test", user2, ClientCredentials{
Username: strPtr("user2"),
Password: "secret",
})
if err != nil {
t.Fatal(err)
}
for _, pushed := range user2.pushed {
if pushed.id == recorder.id {
t.Fatalf("joining user saw system recorder client: %#v", user2.pushed)
}
}
for _, pushed := range user1.pushed {
if pushed.id == recorder.id {
t.Fatalf("existing user saw system recorder client: %#v", user1.pushed)
}
}
}
func strPtr(s string) *string {
return &s
}
func TestLockedHallJoinMessage(t *testing.T) {
halls.halls = nil
oldDirectory := Directory