@@ -1313,56 +1313,33 @@ func TestManagedPostgresAttachmentsPreserveNonNotFoundErrors(t *testing.T) {
13131313 }
13141314}
13151315
1316- // nonSensitiveClusterBody is a GetManagedPostgresCluster response body reused
1317- // across the logging and retry control tests below.
13181316const nonSensitiveClusterBody = `{"data":{"id":"mpg-123","name":"MARKER_NOT_SENSITIVE","status":"ready","region":"iad","plan":"basic","disk_size_gb":0,"cpus":0,"cpu_kind":"","memory_mb":0,"replicas":0,"pg_major_version":"","postgis_enabled":false,"endpoints":{"primary":{"direct":{"host":"","port":0},"pooler":{"host":"","port":0}}},"organization":{"name":"","slug":""},"created_at":"","attached_apps":[]}}`
13191317
1320- // TestManagedPostgresCredentialResponsesAreRedactedFromLogs proves the debug
1321- // logger never records a plaintext password for either credential-returning
1322- // method, while confirming an ordinary (non-sensitive) response is still
1323- // logged normally.
13241318func TestManagedPostgresCredentialResponsesAreRedactedFromLogs (t * testing.T ) {
13251319 tests := []struct {
1326- name string
1327- body string
1328- secret string
1329- sensitive bool
1330- // call returns the field of the decoded response that should equal
1331- // secret on success (password for the credential-returning methods,
1332- // name for the non-sensitive control), so a bug that drops or
1333- // corrupts the response is caught here too, not just in logging.
1334- call func (* Client ) (string , error )
1320+ name string
1321+ body string
1322+ secret string
1323+ call func (* Client ) (string , error )
13351324 }{
13361325 {
1337- name : "rotate password" ,
1338- body : `{"data":{"username":"appuser","password":"sekret-XYZ"}}` ,
1339- secret : "sekret-XYZ" ,
1340- sensitive : true ,
1326+ name : "rotate password" ,
1327+ body : `{"data":{"username":"appuser","password":"sekret-XYZ"}}` ,
1328+ secret : "sekret-XYZ" ,
13411329 call : func (c * Client ) (string , error ) {
13421330 creds , err := c .RotateManagedPostgresUserPassword (context .Background (), "mpg-123" , "appuser" , RotateManagedPostgresUserPasswordRequest {})
13431331 return creds .Password , err
13441332 },
13451333 },
13461334 {
1347- name : "get credentials" ,
1348- body : `{"data":{"username":"appuser","password":"sekret-ABC"}}` ,
1349- secret : "sekret-ABC" ,
1350- sensitive : true ,
1335+ name : "get credentials" ,
1336+ body : `{"data":{"username":"appuser","password":"sekret-ABC"}}` ,
1337+ secret : "sekret-ABC" ,
13511338 call : func (c * Client ) (string , error ) {
13521339 creds , err := c .GetManagedPostgresUserCredentials (context .Background (), "mpg-123" , "appuser" )
13531340 return creds .Password , err
13541341 },
13551342 },
1356- {
1357- name : "get cluster (non-sensitive control)" ,
1358- body : nonSensitiveClusterBody ,
1359- secret : "MARKER_NOT_SENSITIVE" ,
1360- sensitive : false ,
1361- call : func (c * Client ) (string , error ) {
1362- cluster , err := c .GetManagedPostgresCluster (context .Background (), "mpg-123" )
1363- return cluster .Name , err
1364- },
1365- },
13661343 }
13671344
13681345 for _ , tt := range tests {
@@ -1396,24 +1373,16 @@ func TestManagedPostgresCredentialResponsesAreRedactedFromLogs(t *testing.T) {
13961373 }
13971374 }
13981375
1399- if tt .sensitive {
1400- if secretLogged {
1401- t .Fatalf ("secret %q was logged, want redacted" , tt .secret )
1402- }
1403- if ! redactedLogged {
1404- t .Fatalf ("expected redaction message in logs, got: %v" , logger .lines )
1405- }
1406- } else if ! secretLogged {
1407- t .Fatalf ("non-sensitive marker %q not logged, got: %v" , tt .secret , logger .lines )
1376+ if secretLogged {
1377+ t .Fatalf ("secret %q was logged, want redacted" , tt .secret )
1378+ }
1379+ if ! redactedLogged {
1380+ t .Fatalf ("expected redaction message in logs, got: %v" , logger .lines )
14081381 }
14091382 })
14101383 }
14111384}
14121385
1413- // TestManagedPostgresRotatePasswordErrorBodyIsNotRedacted proves that
1414- // redaction only applies to successful (2xx) responses: an error body from a
1415- // sensitive endpoint carries no credentials and should stay visible in logs
1416- // so failures remain debuggable.
14171386func TestManagedPostgresRotatePasswordErrorBodyIsNotRedacted (t * testing.T ) {
14181387 logger := & fakeLogger {}
14191388 transport := & managedPostgresRoundTripper {
@@ -1453,9 +1422,7 @@ func TestManagedPostgresRotatePasswordErrorBodyIsNotRedacted(t *testing.T) {
14531422 }
14541423}
14551424
1456- // TestManagedPostgresRotatePasswordSkipsAutoRetry proves rotation opts out of
1457- // the shared transport's 502/503 retry (so a flaky gateway can't rotate the
1458- // password twice), while an ordinary GET still retries as before.
1425+ // Retrying a rotation can change the password twice.
14591426func TestManagedPostgresRotatePasswordSkipsAutoRetry (t * testing.T ) {
14601427 tests := []struct {
14611428 name string
0 commit comments