Commit 4b1a085e59 for bind

commit 4b1a085e59c1fc7dcbdc4d6b764840ea472ecdd8
Author: Michal Nowak <mnowak@isc.org>
Date:   Fri Oct 9 15:16:12 2026 +0000

    Look up EDNS options with Message.extended_errors() and get_options()

    dnspython 2.7.0 added Message.get_options(), which returns the EDNS
    options of a given type, and Message.extended_errors(), which returns
    the EDE options.  Use them instead of filtering message.options by
    option type by hand in the EDE checks and the COOKIE-handling servers.

    Assisted-by: Claude:claude-opus-5-5

diff --git a/bin/tests/system/cookie/cookie_ans.py b/bin/tests/system/cookie/cookie_ans.py
index 27eba55a05..8dd064491a 100644
--- a/bin/tests/system/cookie/cookie_ans.py
+++ b/bin/tests/system/cookie/cookie_ans.py
@@ -42,14 +42,12 @@ KEYRING = dns.tsigkeyring.from_text(


 def add_cookie(qctx: QueryContext) -> None:
-    for o in qctx.query.options:
-        if o.otype == dns.edns.OptionType.COOKIE:
-            cookie = o
-            if len(cookie.server) == 0:
-                cookie.server = cookie.client
-
-            qctx.response.use_edns(options=[cookie])
-            return
+    for cookie in qctx.query.get_options(dns.edns.OptionType.COOKIE):
+        if len(cookie.server) == 0:
+            cookie.server = cookie.client
+
+        qctx.response.use_edns(options=[cookie])
+        return


 def tld(qctx: QueryContext) -> dns.name.Name:
diff --git a/bin/tests/system/isctest/check.py b/bin/tests/system/isctest/check.py
index 4eca6929c5..1cbac1a4be 100644
--- a/bin/tests/system/isctest/check.py
+++ b/bin/tests/system/isctest/check.py
@@ -9,15 +9,13 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.

-from typing import cast

 import difflib
 import os
 import shutil

-from dns.edns import EDECode, EDEOption
+from dns.edns import EDECode

-import dns.edns
 import dns.flags
 import dns.message
 import dns.rcode
@@ -91,27 +89,11 @@ def notcflag(message: dns.message.Message) -> None:
     assert (message.flags & dns.flags.TC) == 0, str(message)


-def _extract_ede_options(
-    message: dns.message.Message,
-) -> list[EDEOption]:
-    """
-    Extract EDE options from the DNS message.
-    """
-    return cast(
-        list[EDEOption],
-        [
-            option
-            for option in message.options
-            if option.otype == dns.edns.OptionType.EDE
-        ],
-    )
-
-
 def noede(message: dns.message.Message) -> None:
     """
     Check that message contains no EDE option.
     """
-    ede_options = _extract_ede_options(message)
+    ede_options = message.extended_errors()
     assert not ede_options, f"unexpected EDE options {ede_options} in {message}"


@@ -119,7 +101,7 @@ def ede(message: dns.message.Message, code: EDECode, text: str | None = None) ->
     """
     Check if message contains expected EDE code (and its text).
     """
-    msg_opts = _extract_ede_options(message)
+    msg_opts = message.extended_errors()
     matching_opts = [opt for opt in msg_opts if opt.code == code]

     assert matching_opts, f"missing EDE code {code} in {message}"
diff --git a/bin/tests/system/nta/tests_nta.py b/bin/tests/system/nta/tests_nta.py
index d59337ef69..04fd67d910 100644
--- a/bin/tests/system/nta/tests_nta.py
+++ b/bin/tests/system/nta/tests_nta.py
@@ -14,8 +14,6 @@ from re import compile as Re
 import os
 import time

-import dns.edns
-
 import isctest

 # Extended DNS Error INFO-CODE disclosing that a Negative Trust Anchor was
@@ -28,9 +26,7 @@ def active(blob):


 def has_ede(res, code):
-    return any(
-        opt.otype == dns.edns.OptionType.EDE and opt.code == code for opt in res.options
-    )
+    return any(opt.code == code for opt in res.extended_errors())


 # global start-time variable
diff --git a/bin/tests/system/resend_loop/ans3/ans.py b/bin/tests/system/resend_loop/ans3/ans.py
index 822ed8a33b..9c74787228 100644
--- a/bin/tests/system/resend_loop/ans3/ans.py
+++ b/bin/tests/system/resend_loop/ans3/ans.py
@@ -75,10 +75,9 @@ class WithCookie(Matcher):
         return self._matched_cookie

     def match(self, qctx: QueryContext) -> bool:
-        for option in qctx.query.options:
-            if isinstance(option, dns.edns.CookieOption):
-                self._matched_cookie = option
-                return True
+        for cookie in qctx.query.get_options(dns.edns.OptionType.COOKIE):
+            self._matched_cookie = cookie
+            return True
         return False

     def __str__(self) -> str:
diff --git a/bin/tests/system/serve_stale/tests_serve_stale_tcp.py b/bin/tests/system/serve_stale/tests_serve_stale_tcp.py
index 8b8da53cd1..e6c937149d 100644
--- a/bin/tests/system/serve_stale/tests_serve_stale_tcp.py
+++ b/bin/tests/system/serve_stale/tests_serve_stale_tcp.py
@@ -88,9 +88,7 @@ def test_servfail_with_ede22():
     isctest.check.servfail(res)
     isctest.check.ede(res, dns.edns.EDECode.NO_REACHABLE_AUTHORITY)
     assert not any(
-        opt.otype == dns.edns.OptionType.EDE
-        and opt.code == dns.edns.EDECode.STALE_ANSWER
-        for opt in res.options
+        opt.code == dns.edns.EDECode.STALE_ANSWER for opt in res.extended_errors()
     ), "unexpected stale-answer EDE in SERVFAIL response"
     assert len(res.answer) == 0