Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWyHq-0044H2-5Y for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 14:18:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uWyHo-001rBx-7g for pgsql-hackers@arkaria.postgresql.org; Wed, 02 Jul 2025 14:18:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uWyHn-001rBJ-QC for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 14:18:08 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uWyHm-005AJ0-2J for pgsql-hackers@lists.postgresql.org; Wed, 02 Jul 2025 14:18:07 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-ade76b8356cso854499866b.2 for ; Wed, 02 Jul 2025 07:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751465885; x=1752070685; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Jifp5m4DFxHwy9byDfuAPD9FnAnAtNbgRQ6ChdHo4tI=; b=Tve/pyGwV2RQytlVfMMRkRGDy9BcR/lx3cRIBRMRfhappstFdHhMtV6XmJEFRXGNnK RtsyPjjvI5gn9G0ksP2wrQslBzpWi9QrSLJb3u4aUjsFOPGSbcUv9jOd0z5Erf8QqeY1 SI2LnfjHb8WFQcm4/DkOhqHCN6CZRll9DuaXVYRIGdb68GyP7E0vZjbpjCU1wJLox0PA EQMqGn4eFjDuYZEj/0XqllghbOLJ5lxR8cXYlqk8lnIeMPwokaYTGl3h8Onc0eJhrKUX k1W40RUANpWHnzhtc3S8vp1+PhfI/L1o3st5hqpVB2jZrrAnVJtyjinlrlsEfJAAAlkZ aHjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751465885; x=1752070685; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Jifp5m4DFxHwy9byDfuAPD9FnAnAtNbgRQ6ChdHo4tI=; b=Iiy2XSDQwDSqZcYzCBWTNc4V4CBg8Nyj/p8dmzSJmmrG6JjKoCGRDKx/9XnPkkkxlk KXhD5EdTZgYTJS3mNpCee4pDV/t8LwisppPbsT/ZoHAURMXWGreTzMeIA3vrxhOL8im0 gJF6B5B+STgXWxX8XdUIopXjKLS8uV3W4AwKSXAKNDGiLAunYBweRPe4eMgpK2MepcHv qnJqxpdTfDYTaoVNxsKV88gUPXuHbyrf7vpvSP/eXNA6o3Cse7yy1OAq43iwdknhRs9g fIYCPavBau6hfcA8E89mI3wKg3OpI8I5jy63TjbqRTI1cbVcKM7X3lHi6f5X8UEVgrpP qABQ== X-Forwarded-Encrypted: i=1; AJvYcCWUDltYqLmgVDA2Rng9ACVGYAfFiLYdGpPF/6Sjo4avIEA2ULFTgTV7L7Si6K9Y/okfCzR1hyxTzyxczYUS@lists.postgresql.org X-Gm-Message-State: AOJu0YxrF1Gr3ZzGMAUigV9eUH6MOFBKPNKGOPrwvKo32x5UCP41klSn DPUXrY48829KM77oZf6128oYQHKHblmn2yCanKSxC3BS0R5ZuCHMX5lhSy1+d/SNuFYj+nMaXi/ vPiJ5pEJF46QG665bObXzJCrxwe1uua0= X-Gm-Gg: ASbGncu4b8t8tH0l1WaP91M4zNG87zrkpxG+kuY6hEu1DDDY19miXwPo+JTWgFtc8C0 9vF/mpSkLKMOsygQIY3E7oiS8V+D+n0f6iYGe7mm8gshW1uGz/WEPkl5kPfpJOjaUaF0C3BlHcl vVKA/Q3rgYtKm/rlbgPjn0VcOmWuBn7AHCUv1HoqVG/BFPjgvwbS0jum2Um/9TKxtncbWxntUqo 4MjyEbDtSt5nPU= X-Google-Smtp-Source: AGHT+IGtOKmMRpc09JXwlnCooKiM+plwnd7v8D6iFhPprdE5fXxjhfR01X+x8Ep7zqdQi5vm3VrU1Cg++7s/WxWaPmM= X-Received: by 2002:a17:907:eaa:b0:ae3:d100:a756 with SMTP id a640c23a62f3a-ae3d100a945mr33855966b.56.1751465884861; Wed, 02 Jul 2025 07:18:04 -0700 (PDT) MIME-Version: 1.0 References: <0231C713-50C8-4BE5-B7C8-106F57A79655@yesql.se> <87wm8q3crt.fsf@wibble.ilmari.org> In-Reply-To: <87wm8q3crt.fsf@wibble.ilmari.org> From: Jianghua Yang Date: Wed, 2 Jul 2025 07:17:28 -0700 X-Gm-Features: Ac12FXxBTC_sua2XBXSwR9_BWk5j97qomVa_9l-r2mOWEj0gErpeYbK9tNRBBkc Message-ID: Subject: Re: [PATCH] initdb: Treat empty -U argument as unset username To: =?UTF-8?Q?Dagfinn_Ilmari_Manns=C3=A5ker?= Cc: daniel@yesql.se, Robert Treat , "David G. Johnston" , pgsql-hackers@lists.postgresql.org Content-Type: multipart/mixed; boundary="000000000000e78d0d0638f2edef" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e78d0d0638f2edef Content-Type: multipart/alternative; boundary="000000000000e78d0b0638f2eded" --000000000000e78d0b0638f2eded Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the feedback! I've updated the test to use `command_fails_like()` instead of `command_fails()`, so it now asserts that the error message matches the expected stderr output. I also changed the test invocation to use the `-U =3D> ''` syntax for consistency, as seen in the adjacent `--username` test. Let me know if any further adjustments are needed. Best regards, Jianghua Yang Dagfinn Ilmari Manns=C3=A5ker =E4=BA=8E2025=E5=B9=B47= =E6=9C=882=E6=97=A5=E5=91=A8=E4=B8=89 07:09=E5=86=99=E9=81=93=EF=BC=9A > Jianghua Yang writes: > > > - A regression test is added to `src/bin/initdb/t/001_initdb.pl` to > verify > > that the case `initdb -U ''` fails as expected. > [ ... ] > > diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/ > 001_initdb.pl > > index 15dd10ce40a..67eb53064f6 100644 > > --- a/src/bin/initdb/t/001_initdb.pl > > +++ b/src/bin/initdb/t/001_initdb.pl > > @@ -37,6 +37,10 @@ command_fails( > > command_fails([ 'initdb', '--username' =3D> 'pg_test', $datadir ], > > 'role names cannot begin with "pg_"'); > > > > +command_fails( > > + [ 'initdb', '-U', '', $datadir ], > > + 'empty username not allowed'); > > + > > This only tests that it fails, not that it fails as expected. It should > use command_fails_like() to check that stderr contains the expected > error. Also, it shoud use =3D> between the -U option and its argument, a= s > seen in the above test with --username. > > - ilmari > --000000000000e78d0b0638f2eded Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks for the feedback!

I've updated the test = to use `command_fails_like()` instead of `command_fails()`, so it now asser= ts that the error message matches the expected stderr output.=C2=A0
I a= lso changed the test invocation to use the `-U =3D> ''` syntax f= or consistency, as seen in the adjacent `--username` test.
=C2=A0 =C2=A0=

Let me know if any further adjustments are needed.

Best rega= rds, =C2=A0
Jianghua Yang

Dagfinn Ilmari Mann= s=C3=A5ker <ilmari@ilmari.org&g= t; =E4=BA=8E2025=E5=B9=B47=E6=9C=882=E6=97=A5=E5=91=A8=E4=B8=89 07:09=E5=86= =99=E9=81=93=EF=BC=9A
Jianghua Yang <yjhjstz@gmail.com> writes:

> - A regression test is added to `src/bin/initdb/t/001_initdb.pl` to ver= ify
> that the case `initdb -U ''` fails as expected.
[ ... ]
> diff --git a/src/bin/initdb/t/001_initdb.pl b/src/bin/initdb/t/001_initdb.p= l
> index 15dd10ce40a..67eb53064f6 100644
> --- a/src/bin/initdb/t/001_initdb.pl
> +++ b/src/bin/initdb/t/001_initdb.pl
> @@ -37,6 +37,10 @@ command_fails(
>=C2=A0 command_fails([ 'initdb', '--username' =3D> &= #39;pg_test', $datadir ],
>=C2=A0 =C2=A0 =C2=A0 =C2=A0'role names cannot begin with "pg_&= quot;');
>=C2=A0
> +command_fails(
> +=C2=A0 =C2=A0 =C2=A0[ 'initdb', '-U', '', $da= tadir ],
> +=C2=A0 =C2=A0 =C2=A0'empty username not allowed');
> +

This only tests that it fails, not that it fails as expected.=C2=A0 It shou= ld
use command_fails_like() to check that stderr contains the expected
error.=C2=A0 Also, it shoud use =3D> between the -U option and its argum= ent, as
seen in the above test with --username.

- ilmari
--000000000000e78d0b0638f2eded-- --000000000000e78d0d0638f2edef Content-Type: application/octet-stream; name="0001-initdb-Reject-empty-string-for-U-username-option-v3.patch" Content-Disposition: attachment; filename="0001-initdb-Reject-empty-string-for-U-username-option-v3.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_mcm1jigq0 RnJvbSA1OGNiYmYxODEyMDIyZWFkMmJkYWI0YTMxM2IyMzA2MjRmOTdlN2IwIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBKaWFuZ2h1YSBZYW5nIDx5amhqc3R6QGdtYWlsLmNvbT4KRGF0 ZTogV2VkLCAyIEp1bCAyMDI1IDA2OjQ4OjQ4IC0wNzAwClN1YmplY3Q6IFtQQVRDSF0gaW5pdGRi OiBSZWplY3QgZW1wdHkgc3RyaW5nIGZvciAtVS8tLXVzZXJuYW1lIG9wdGlvbiB2MwoKUHJldmlv dXNseSwgcGFzc2luZyBhbiBlbXB0eSBzdHJpbmcgdG8gdGhlIC1VIG9yIC0tdXNlcm5hbWUgb3B0 aW9uCihlLmcuLCBgaW5pdGRiIC1VICcnYCkgd291bGQgY2F1c2UgY29uZnVzaW5nIGVycm9ycyBk dXJpbmcgYm9vd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