Copilot commented on code in PR #13712:
URL: https://github.com/apache/trafficserver/pull/13712#discussion_r4074991513


##########
tests/gold_tests/tls/tls_dual_cert_default_client.py:
##########
@@ -0,0 +1,55 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information regarding
+#  copyright ownership.  The ASF licenses this file to you under
+#  the Apache License, Version 2.0 (the "License"); you may not use
+#  this file except in compliance with the License.  You may obtain
+#  a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+"""Probe default and named certificate selection with restricted signature 
algorithms."""
+
+import re
+import subprocess
+import sys
+
+
+def main(port: int) -> None:
+    cases = 0
+    for version in ('tls1_2', 'tls1_3'):
+        for servername, common_name in ((None, 'foo.com'), ('unknown.example', 
'foo.com'), ('one.com', 'group.com')):
+            for sigalg, signature in (('rsa_pss_rsae_sha256', 
r'(RSA-PSS|rsa_pss_)'), ('ecdsa_secp256r1_sha256',
+                                                                               
        r'(ECDSA|ecdsa_)')):
+                command = [
+                    'openssl',
+                    's_client',
+                    '-brief',
+                    '-connect',
+                    f'127.0.0.1:{port}',
+                    f'-{version}',
+                    '-sigalgs',
+                    sigalg,
+                ]
+                command += ['-servername', servername] if servername else 
['-noservername']
+                if version == 'tls1_2':
+                    auth = 'RSA' if sigalg.startswith('rsa_') else 'ECDSA'
+                    command += ['-cipher', f'ECDHE-{auth}-AES128-GCM-SHA256']
+                result = subprocess.run(command, input='', 
capture_output=True, text=True, timeout=10)
+                output = result.stdout + result.stderr
+                label = f'{version}, SNI={servername}, sigalg={sigalg}'
+                if (result.returncode != 0 or re.search(rf'Signature type: 
{signature}', output) is None or

Review Comment:
   `openssl s_client -brief` output commonly uses `Peer signature type:` (and 
may vary across OpenSSL versions/case), so matching only `Signature type:` 
risks false failures. Make the signature-type regex tolerant (e.g., accept both 
`Peer signature type:` and `Signature type:`, and/or use case-insensitive 
matching) so the test validates the behavior instead of a specific string 
formatting.



##########
tests/gold_tests/tls/tls_dual_cert_default_client.py:
##########
@@ -0,0 +1,55 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information regarding
+#  copyright ownership.  The ASF licenses this file to you under
+#  the Apache License, Version 2.0 (the "License"); you may not use
+#  this file except in compliance with the License.  You may obtain
+#  a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+"""Probe default and named certificate selection with restricted signature 
algorithms."""
+
+import re
+import subprocess
+import sys
+
+
+def main(port: int) -> None:
+    cases = 0
+    for version in ('tls1_2', 'tls1_3'):
+        for servername, common_name in ((None, 'foo.com'), ('unknown.example', 
'foo.com'), ('one.com', 'group.com')):
+            for sigalg, signature in (('rsa_pss_rsae_sha256', 
r'(RSA-PSS|rsa_pss_)'), ('ecdsa_secp256r1_sha256',
+                                                                               
        r'(ECDSA|ecdsa_)')):
+                command = [
+                    'openssl',
+                    's_client',
+                    '-brief',
+                    '-connect',
+                    f'127.0.0.1:{port}',
+                    f'-{version}',
+                    '-sigalgs',
+                    sigalg,
+                ]
+                command += ['-servername', servername] if servername else 
['-noservername']
+                if version == 'tls1_2':
+                    auth = 'RSA' if sigalg.startswith('rsa_') else 'ECDSA'
+                    command += ['-cipher', f'ECDHE-{auth}-AES128-GCM-SHA256']
+                result = subprocess.run(command, input='', 
capture_output=True, text=True, timeout=10)

Review Comment:
   A 10-second timeout can be flaky on slower/loaded CI hosts, especially since 
this runs multiple `s_client` invocations in a loop. Consider increasing the 
timeout (or making it configurable via an env var/arg) to reduce spurious 
failures unrelated to certificate selection.



##########
tests/gold_tests/tls/tls_dual_cert_default.test.py:
##########
@@ -0,0 +1,41 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information regarding
+#  copyright ownership.  The ASF licenses this file to you under
+#  the Apache License, Version 2.0 (the "License"); you may not use
+#  this file except in compliance with the License.  You may obtain
+#  a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+"""Select default RSA and EC certificates independently of their order."""
+
+import os
+import shlex
+import sys
+
+Test.Summary = __doc__
+Test.SkipUnless(Condition.HasOpenSSLVersion('1.1.1'))
+
+for order in ('rsa_ec', 'ec_rsa'):
+    tr = 
Test.ATSReplayTest(replay_file=f'replay/dual_cert_default_{order}.replay.yaml')
+    ts = tr.Processes[f'ts_{order}']
+    for name in ('signed-foo', 'signed-foo-ec', 'signed-san', 'signed-san-ec'):
+        ts.addSSLfile(f'ssl/{name}.pem')
+        ts.addSSLfile(f'ssl/{name}.key')
+    ts.Disk.records_config.update(
+        {
+            'proxy.config.ssl.server.cert.path': ts.Variables.SSLDir,
+            'proxy.config.ssl.server.private_key.path': ts.Variables.SSLDir,
+        })
+    # Proxy Verifier checks the HTTP exchange. Use s_client afterward to 
constrain
+    # signature algorithms, which the replay client cannot configure.
+    helper = shlex.quote(os.path.join(Test.TestDirectory, 
'tls_dual_cert_default_client.py'))
+    tr.Processes.Default.Command += f' && {shlex.quote(sys.executable)} 
{helper} {ts.Variables.ssl_port}'
+    tr.Processes.Default.Streams.All += Testers.ContainsExpression(
+        'PASS: 12 certificate selections', f'Both key types work with 
certificate order {order}')

Review Comment:
   The test hard-codes the total case count (`12`), which will break if the 
helper’s matrix changes (e.g., adding a TLS version, SNI variant, or 
algorithm). Prefer asserting on a stable marker (like `PASS:` lines for each 
case) or have the helper print a sentinel string that doesn’t embed a computed 
count.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to