MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/cloud-sql-proxy / TestPostgresIAMDBAuthn

Function TestPostgresIAMDBAuthn

tests/postgres_test.go:246–300  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

244}
245
246func TestPostgresIAMDBAuthn(t *testing.T) {
247 if testing.Short() {
248 t.Skip("skipping Postgres integration tests")
249 }
250 if os.Getenv("SKIP_FUSE_E2E_TESTS") == "true" {
251 t.Skip("skipping Postgres FUSE integration tests because SKIP_FUSE_E2E_TESTS is set")
252 }
253 requirePostgresVars(t)
254 if *postgresIAMUser == "" {
255 t.Fatal("'postgres_user_iam' not set")
256 }
257
258 defaultDSN := fmt.Sprintf("host=localhost user=%s database=%s sslmode=disable",
259 *postgresIAMUser, *postgresDB)
260 impersonatedIAMUser := strings.ReplaceAll(*impersonatedUser, ".gserviceaccount.com", "")
261
262 tcs := []struct {
263 desc string
264 dsn string
265 args []string
266 }{
267 {
268 desc: "using default flag",
269 args: []string{"--auto-iam-authn", *postgresConnName},
270 dsn: defaultDSN,
271 },
272 {
273 desc: "using query param",
274 args: []string{fmt.Sprintf("%s?auto-iam-authn=true", *postgresConnName)},
275 dsn: defaultDSN,
276 },
277 {
278 desc: "using impersonation",
279 args: []string{
280 "--auto-iam-authn",
281 "--impersonate-service-account", *impersonatedUser,
282 *postgresConnName},
283 dsn: fmt.Sprintf("host=localhost user=%s database=%s sslmode=disable",
284 impersonatedIAMUser, *postgresDB),
285 },
286 {
287 desc: "using impersonation with query param",
288 args: []string{
289 "--impersonate-service-account", *impersonatedUser,
290 fmt.Sprintf("%s?auto-iam-authn=true", *postgresConnName)},
291 dsn: fmt.Sprintf("host=localhost user=%s password=password database=%s sslmode=disable",
292 impersonatedIAMUser, *postgresDB),
293 },
294 }
295 for _, tc := range tcs {
296 t.Run(tc.desc, func(t *testing.T) {
297 proxyConnTest(t, AddIPTypeFlag(tc.args), "pgx", tc.dsn)
298 })
299 }
300}
301
302func TestPostgresCustomerCAS(t *testing.T) {
303 if testing.Short() {

Callers

nothing calls this directly

Calls 3

requirePostgresVarsFunction · 0.85
proxyConnTestFunction · 0.85
AddIPTypeFlagFunction · 0.85

Tested by

no test coverage detected