askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
talkback_test.go · 1.4 KB · 46 lines
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "io" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestTalkbackProxy(t *testing.T) { |
| 11 | var sawPath, sawCookie, sawAuth string |
| 12 | tb := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 13 | sawPath, sawCookie, sawAuth = r.URL.Path, r.Header.Get("Cookie"), r.Header.Get("Authorization") |
| 14 | io.WriteString(w, "ok") |
| 15 | })) |
| 16 | defer tb.Close() |
| 17 | h, err := talkbackProxy(tb.URL) |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | do := func(method, path string) int { |
| 22 | r := httptest.NewRequest(method, path, nil) |
| 23 | r.Header.Set("Cookie", "nc_session=secret") |
| 24 | r.Header.Set("Authorization", "Bearer pass") |
| 25 | w := httptest.NewRecorder() |
| 26 | h.ServeHTTP(w, r) |
| 27 | return w.Code |
| 28 | } |
| 29 | if c := do("GET", "/talkback/api/voice/next?after=5"); c != 200 || sawPath != "/api/voice/next" { |
| 30 | t.Fatalf("next: %d %q", c, sawPath) |
| 31 | } |
| 32 | if sawCookie != "" || sawAuth != "Bearer pass" { |
| 33 | t.Fatalf("the cookie must stay, the passphrase must go on: cookie %q auth %q", sawCookie, sawAuth) |
| 34 | } |
| 35 | if c := do("GET", "/talkback/audio/voice-1790-abc123.wav"); c != 200 { |
| 36 | t.Fatalf("audio: %d", c) |
| 37 | } |
| 38 | for _, bad := range []string{"/talkback/api/voice", "/talkback/audio/../etc/passwd", "/talkback/admin", "/talkback/audio/x.wav"} { |
| 39 | if c := do("GET", bad); c != 404 { |
| 40 | t.Fatalf("%s: %d, want 404", bad, c) |
| 41 | } |
| 42 | } |
| 43 | if c := do("POST", "/talkback/api/voice"); c != 405 { |
| 44 | t.Fatalf("POST from outside: %d, want 405", c) |
| 45 | } |
| 46 | } |