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
auth_test.go · 1.1 KB · 33 lines
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "net/http/httptest" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestWrongPasswordsAreLimitedPerAddress(t *testing.T) { |
| 9 | a := newAuthority("nc", "right") |
| 10 | r := httptest.NewRequest("POST", "/auth", nil) |
| 11 | r.RemoteAddr = "203.0.113.9:4000" |
| 12 | for i := 0; i < maxFails; i++ { |
| 13 | if ok, limited := a.checkCredsFrom(r, "nc", "wrong"); ok || limited { |
| 14 | t.Fatalf("attempt %d: ok=%v limited=%v", i, ok, limited) |
| 15 | } |
| 16 | } |
| 17 | if ok, limited := a.checkCredsFrom(r, "nc", "right"); ok || !limited { |
| 18 | t.Fatalf("after %d failures the right password should be refused too: ok=%v limited=%v", maxFails, ok, limited) |
| 19 | } |
| 20 | other := httptest.NewRequest("POST", "/auth", nil) |
| 21 | other.RemoteAddr = "198.51.100.7:5000" |
| 22 | if ok, _ := a.checkCredsFrom(other, "nc", "right"); !ok { |
| 23 | t.Fatal("another address must not be limited") |
| 24 | } |
| 25 | local := httptest.NewRequest("POST", "/auth", nil) |
| 26 | local.RemoteAddr = "127.0.0.1:6000" |
| 27 | for i := 0; i < maxFails+5; i++ { |
| 28 | a.checkCredsFrom(local, "nc", "wrong") |
| 29 | } |
| 30 | if ok, limited := a.checkCredsFrom(local, "nc", "right"); !ok || limited { |
| 31 | t.Fatal("the desk itself (loopback) is never limited") |
| 32 | } |
| 33 | } |