oficina / meet Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build browser && darwin
2
3package callstest
4
5import (
6 "context"
7 "encoding/json"
8 "net/http"
9 "net/http/httptest"
10 "os"
11 "os/exec"
12 "path/filepath"
13 "testing"
14 "time"
15)
16
17// The iPhone UI talks to the same temporary server as the browser suite. Email
18// is captured locally. Nothing contacts production or sends actual mail.
19func TestIPhoneSafariAuthentication(t *testing.T) {
20 simulator := os.Getenv("CALLS_IOS_SIMULATOR")
21 if simulator == "" {
22 t.Skip("set CALLS_IOS_SIMULATOR to an available iPhone simulator UUID")
23 }
24 for _, guest := range []bool{false, true} {
25 name := "member"
26 if guest {
27 name = "guest"
28 }
29 t.Run(name, func(t *testing.T) {
30 rig := newBrowserRig(t)
31 room, token := rig.createMeeting(t)
32 target := "/m/" + room
33 if guest {
34 rig.ctl.SetAllowlist(memberA)
35 target = "/j/" + token
36 }
37 before := rig.mail.count()
38 control := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39 w.Header().Set("Content-Type", "application/json")
40 link := ""
41 if rig.mail.count() > before {
42 to, value := rig.mail.last()
43 if to == memberB {
44 link = value
45 }
46 }
47 json.NewEncoder(w).Encode(map[string]string{"link": link})
48 }))
49 defer control.Close()
50 root := repoRootForBrowser(t)
51 ctx, cancel := context.WithTimeout(t.Context(), 4*time.Minute)
52 defer cancel()
53 results := filepath.Join(root, "native/build/iphone-auth-"+name+"-"+time.Now().Format("150405")+".xcresult")
54 cmd := exec.CommandContext(ctx, "xcodebuild", "-project", filepath.Join(root, "native/ios/CallsPhone.xcodeproj"), "-scheme", "CallsPhone", "-destination", "platform=iOS Simulator,id="+simulator, "-derivedDataPath", filepath.Join(root, "native/build/ios-simulator"), "-resultBundlePath", results, "CODE_SIGNING_ALLOWED=NO", "-only-testing:CallsPhoneUITests/CallsPhoneUITests/testEmailBrowserHandoff", "test")
55 // A member signs in to the server, which the app is pointed at for
56 // this run with -CallsServer; a guest pastes the invitation into the
57 // guest screen.
58 guestFlag := "0"
59 if guest {
60 guestFlag = "1"
61 }
62 cmd.Env = append(os.Environ(), "TEST_RUNNER_CALLS_TEST_MEETING="+rig.origin+target, "TEST_RUNNER_CALLS_TEST_ORIGIN="+rig.origin, "TEST_RUNNER_CALLS_TEST_GUEST="+guestFlag, "TEST_RUNNER_CALLS_TEST_CONTROL="+control.URL, "TEST_RUNNER_CALLS_TEST_EMAIL="+memberB)
63 // Xcode's detailed trace contains only synthetic test identities and is
64 // retained locally for diagnosis, rather than flooding the normal gate log.
65 logPath := filepath.Join(root, "native/build/iphone-auth-"+name+".log")
66 log, err := os.Create(logPath)
67 if err != nil {
68 t.Fatal(err)
69 }
70 defer log.Close()
71 cmd.Stdout = log
72 cmd.Stderr = log
73 if err := cmd.Run(); err != nil {
74 t.Fatalf("iPhone Safari %s: %v (details: %s)", name, err, logPath)
75 }
76 t.Log("Safari email handoff passed on iPhone simulator:", name)
77 })
78 }
79}
80
81func TestIPhoneNativeMedia(t *testing.T) {
82 simulator := os.Getenv("CALLS_IOS_SIMULATOR")
83 if simulator == "" {
84 t.Skip("set CALLS_IOS_SIMULATOR to an available iPhone simulator UUID")
85 }
86 rig := newBrowserRig(t)
87 room, _ := rig.createMeeting(t)
88 rig.ctl.SetStreamTimings(time.Second, 3*time.Second)
89 cookiesA, _ := json.Marshal([]map[string]string{{"name": rig.cookieName, "value": rig.cookieA}})
90 cookiesB, _ := json.Marshal([]map[string]string{{"name": rig.cookieName, "value": rig.cookieB}})
91 fixture, _ := json.Marshal(map[string]string{"origin": rig.origin, "room": room, "cookiesA": string(cookiesA), "cookiesB": string(cookiesB)})
92 root := repoRootForBrowser(t)
93 ctx, cancel := context.WithTimeout(t.Context(), 4*time.Minute)
94 defer cancel()
95 cmd := exec.CommandContext(ctx, "xcodebuild", "-project", filepath.Join(root, "native/ios/CallsPhone.xcodeproj"), "-scheme", "CallsPhone", "-destination", "platform=iOS Simulator,id="+simulator, "-derivedDataPath", filepath.Join(root, "native/build/ios-simulator"), "CODE_SIGNING_ALLOWED=NO", "-only-testing:CallsPhoneTests/CallsPhoneTests/testNativeVideoAndRenewal", "test")
96 cmd.Env = append(os.Environ(), "TEST_RUNNER_CALLS_TEST_MEDIA="+string(fixture))
97 logPath := filepath.Join(root, "native/build/iphone-media.log")
98 log, err := os.Create(logPath)
99 if err != nil {
100 t.Fatal(err)
101 }
102 defer log.Close()
103 cmd.Stdout = log
104 cmd.Stderr = log
105 if err := cmd.Run(); err != nil {
106 t.Fatalf("iPhone native media: %v (details: %s)", err, logPath)
107 }
108 t.Log("Two iPhone-native WebRTC peers decoded video, kept their peers through stream renewals, and left cleanly")
109}
110