oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1package callstest
2
3import (
4 "encoding/base64"
5 "encoding/json"
6 "strings"
7 "testing"
8)
9
10// relayVectorForTest is the base64 CARLOS_RELAY value for one region,
11// built from relay's own platform vector key and username suffix
12// (internal/calls/relay/relay_test.go) so a leak of either into a
13// rendered page would be unmistakable.
14func relayVectorForTest(t *testing.T) string {
15 t.Helper()
16 const vectorKey = "uMhwW4P/9O5dQUIs91t2CCHGhwJbeiM0xQMQ2G0CJLU="
17 regions := []map[string]any{{
18 "region": "eu-west-1",
19 "urls": []string{"stun:relay.eu-west-1.oncarlos.com:3478"},
20 "key": vectorKey,
21 "username_suffix": "abc:meet:0123456789abcdef:k1",
22 }}
23 b, err := json.Marshal(regions)
24 if err != nil {
25 t.Fatal(err)
26 }
27 return base64.StdEncoding.EncodeToString(b)
28}
29
30// TestRoomPageShowsFloorWithNoRelay: holding_test.go's
31// TestHoldingPageShowsTitleStandingAndFloor covers /join; room.html
32// renders the identical sentence and nothing proved it — there was no
33// room-page floor test before this one.
34func TestRoomPageShowsFloorWithNoRelay(t *testing.T) {
35 x, sqid, _ := memberWithMeeting(t)
36 c := x.browser(t)
37 c.signIn("paul@example.com")
38 body := c.get("/m/" + sqid).Body.String()
39 if !strings.Contains(body, "Calls outside your network may not connect yet.") {
40 t.Fatalf("room page lacks the floor sentence with no relay configured:\n%s", body)
41 }
42 // The same fact room.js reads, and the only thing that chooses
43 // between §5.5's two failed-tile sentences. Empty here.
44 if !strings.Contains(body, `data-relay=""`) {
45 t.Fatalf("room page does not render an empty data-relay with no relay configured:\n%s", body)
46 }
47}
48
49// TestSetRelayHidesTheFloorSentenceOnBothPages: the floor sentence,
50// present on both the holding and room pages with no relay, must
51// disappear from both once TestHandle.SetRelay configures one — the
52// "relay configured ⇒ sentence absent" direction that hardcoding Floor
53// to true would still have passed.
54func TestSetRelayHidesTheFloorSentenceOnBothPages(t *testing.T) {
55 x, sqid, _ := memberWithMeeting(t)
56 if err := x.ctl.SetRelay(relayVectorForTest(t)); err != nil {
57 t.Fatal(err)
58 }
59 c := x.browser(t)
60 c.signIn("paul@example.com")
61 if body := c.get("/m/" + sqid + "/join").Body.String(); strings.Contains(body, "Calls outside your network may not connect yet.") {
62 t.Fatalf("holding page still shows the floor sentence with a relay configured:\n%s", body)
63 }
64 body := c.get("/m/" + sqid).Body.String()
65 if strings.Contains(body, "Calls outside your network may not connect yet.") {
66 t.Fatalf("room page still shows the floor sentence with a relay configured:\n%s", body)
67 }
68 // §5.5's other half: room.js says "even through the relay" on a
69 // failed tile only when the server states there is one.
70 if !strings.Contains(body, `data-relay="1"`) {
71 t.Fatalf("room page does not render data-relay=\"1\" with a relay configured:\n%s", body)
72 }
73}
74