MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestResolvePostgresConnection

Function TestResolvePostgresConnection

controlplane/configstore/store_test.go:258–375  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func TestResolvePostgresConnection(t *testing.T) {
259 cs := &ConfigStore{
260 snapshot: &Snapshot{
261 Orgs: map[string]*OrgConfig{
262 "test-org-smoke-1778167994": {
263 Name: "test-org-smoke-1778167994",
264 DatabaseName: "test_org_smoke_1778167994",
265 },
266 "billing": {
267 Name: "billing",
268 DatabaseName: "billing_db",
269 },
270 },
271 DatabaseOrg: map[string]string{
272 "test_org_smoke_1778167994": "test-org-smoke-1778167994",
273 "billing_db": "billing",
274 },
275 HostnameAliasOrg: map[string]string{
276 "billing-alias": "billing",
277 },
278 OrgUserPassword: map[OrgUserKey]string{
279 {OrgID: "test-org-smoke-1778167994", Username: "root"}: mustHash(t, "secret"),
280 {OrgID: "billing", Username: "root"}: mustHash(t, "secret"),
281 },
282 OrgUserPassthrough: map[OrgUserKey]bool{
283 {OrgID: "test-org-smoke-1778167994", Username: "root"}: true,
284 },
285 },
286 }
287
288 t.Run("org resolved from SNI; ducklake catalog selected", func(t *testing.T) {
289 got := cs.ResolvePostgresConnection(
290 "ducklake",
291 "test-org-smoke-1778167994",
292 true,
293 "root",
294 "secret",
295 )
296 if !got.SNIResolved || got.OrgID != "test-org-smoke-1778167994" {
297 t.Fatalf("org = (resolved=%v, %q), want test org from SNI: %+v", got.SNIResolved, got.OrgID, got)
298 }
299 if !got.CatalogValid || got.EffectiveCatalog != "ducklake" {
300 t.Fatalf("catalog = (valid=%v, %q), want ducklake: %+v", got.CatalogValid, got.EffectiveCatalog, got)
301 }
302 if !got.Valid || !got.Passthrough {
303 t.Fatalf("unexpected auth result: %+v", got)
304 }
305 })
306
307 t.Run("iceberg is no longer a selectable catalog", func(t *testing.T) {
308 // Iceberg/Lakekeeper support was removed: an "iceberg" database request
309 // now fails the catalog check even with valid SNI+auth.
310 got := cs.ResolvePostgresConnection("iceberg", "test-org-smoke-1778167994", true, "root", "secret")
311 if got.CatalogValid {
312 t.Fatalf("iceberg must not be a selectable catalog: %+v", got)
313 }
314 if got.EffectiveCatalog != "" {
315 t.Fatalf("EffectiveCatalog = %q, want empty for rejected catalog", got.EffectiveCatalog)

Callers

nothing calls this directly

Calls 3

mustHashFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected