| 1 | package relay |
| 2 | |
| 3 | import ( |
| 4 | "crypto/sha256" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // The env-safety assertion this test used to make inline (appconfig. |
| 9 | // ValidVarValue(val)) moved to config_appconfig_test.go, package |
| 10 | // relay_test, once Task 12 gave internal/appconfig a real import of |
| 11 | // internal/relay (configack.go): an INTERNAL test file here (package |
| 12 | // relay, this file) importing appconfig would close relay -> appconfig -> |
| 13 | // relay, which go vet refuses. An external test package can import both |
| 14 | // without cycling, because it isn't part of either package's own build. |
| 15 | func TestBuildConfigMatchesContract(t *testing.T) { |
| 16 | m := sha256.Sum256([]byte("carlos-relay-test-master")) |
| 17 | r := &Record{Enabled: true, Incarnation: "0123456789abcdef", Regions: []string{"eu-west-1"}} |
| 18 | urls := func(region string) []string { |
| 19 | h := "relay." + region + ".oncarlos.com:3478" |
| 20 | return []string{"stun:" + h, "turn:" + h + "?transport=udp", "turn:" + h + "?transport=tcp"} |
| 21 | } |
| 22 | val, suffixes, err := BuildConfig("abc", "meet", r, []RegionMaster{{Region: "eu-west-1", Kid: "k1", Master: m[:]}}, urls) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | entries, err := ParseConfig(val) |
| 27 | if err != nil || len(entries) != 1 { |
| 28 | t.Fatalf("parse = %+v %v", entries, err) |
| 29 | } |
| 30 | e := entries[0] |
| 31 | if e.Key != "uMhwW4P/9O5dQUIs91t2CCHGhwJbeiM0xQMQ2G0CJLU=" || e.UsernameSuffix != "abc:meet:0123456789abcdef:k1" || suffixes["eu-west-1"] != e.UsernameSuffix { |
| 32 | t.Fatalf("entry = %+v", e) |
| 33 | } |
| 34 | if len(e.URLs) != 3 || e.URLs[0] != "stun:relay.eu-west-1.oncarlos.com:3478" { |
| 35 | t.Fatalf("urls = %v", e.URLs) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | func TestBuildConfigRefusesMissingMaster(t *testing.T) { |
| 40 | r := &Record{Enabled: true, Incarnation: "0123456789abcdef", Regions: []string{"eu-west-1", "us-east-1"}} |
| 41 | if _, _, err := BuildConfig("abc", "meet", r, []RegionMaster{{Region: "eu-west-1", Kid: "k1", Master: make([]byte, 32)}}, func(string) []string { return nil }); err == nil { |
| 42 | t.Fatal("missing us-east-1 master accepted") |
| 43 | } |
| 44 | } |
| 45 | |