| 1 | package daemon |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "net/http" |
| 6 | "net/http/httptest" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestUnclaimedSubdomainsOfTheSiteDomainAreNotFound(t *testing.T) { |
| 12 | ctx := context.Background() |
| 13 | app, err := New(ctx, Config{DataDir: t.TempDir(), DefaultTenant: "main" , PublicURL: "https://relay.test" }) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | defer app.Close(ctx) |
| 18 | meta, err := app.Create(ctx, CreateOptions{Name: "main" , Owner: strings.Repeat("a" , 64), Template: "default" }) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | tenant, err := app.tenant(ctx, meta, "https://relay.test" ) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | for host, want := range map[string]int{"relay.test" : http.StatusOK, "bauhaus.relay.test" : http.StatusNotFound, "tiny.tailnet.example" : http.StatusOK, "127.0.0.1:7447" : http.StatusOK} { |
| 27 | req := httptest.NewRequest(http.MethodGet, "http://" +host+"/" , nil) |
| 28 | req.Host = host |
| 29 | res := httptest.NewRecorder() |
| 30 | tenant.ServeHTTP(res, req) |
| 31 | if res.Code != want { |
| 32 | t.Errorf("host %s: status %d, want %d" , host, res.Code, want) |
| 33 | } |
| 34 | } |
| 35 | } |