package clientapi_test import ( "net/http" "testing" "github.com/dariuszjaniak/warp/server/internal/clientapi" ) // TestLoginCarriesDiscovery covers the shortcut the spec allows: a client // that only knew the server name learns its API URL from the login response // instead of fetching /.well-known separately. func TestLoginCarriesDiscovery(t *testing.T) { ts := newTestServer(t, func(o *clientapi.Options) { o.ClientBaseURL = "https://matrix.warp.example" }) ts.register("alice", "superuser") rec := ts.do(request{method: http.MethodPost, path: loginPath, body: map[string]any{ "type": "m.login.password", "identifier": map[string]any{"type": "m.id.user", "user": "alice"}, "password": "superuser", }}) expectStatus(t, rec, http.StatusOK) wellKnown, ok := jsonBody(t, rec)["well_known"].(map[string]any) if !ok { t.Fatalf("login response carries no well_known: %s", rec.Body.String()) } homeserver, _ := wellKnown["m.homeserver"].(map[string]any) if homeserver["base_url"] != "https://matrix.warp.example" { t.Errorf("base_url = %v", homeserver["base_url"]) } } // TestLoginOmitsDiscoveryWhenUnconfigured keeps the response from carrying // an empty object a client would have to guess at. func TestLoginOmitsDiscoveryWhenUnconfigured(t *testing.T) { ts := newTestServer(t, nil) ts.register("alice", "superuser") rec := ts.do(request{method: http.MethodPost, path: loginPath, body: map[string]any{ "type": "m.login.password", "identifier": map[string]any{"type": "m.id.user", "user": "alice"}, "password": "superuser", }}) expectStatus(t, rec, http.StatusOK) if _, present := jsonBody(t, rec)["well_known"]; present { t.Error("well_known must be omitted when no client base URL is configured") } }