]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add QnameQtypeHandler for matching QNAME, QTYPE pairs
authorŠtěpán Balážik <stepan@isc.org>
Thu, 25 Dec 2025 22:53:26 +0000 (23:53 +0100)
committerŠtěpán Balážik <stepan@isc.org>
Sat, 24 Jan 2026 12:04:09 +0000 (13:04 +0100)
This is a pattern in the resolver system test and also elsewhere.

bin/tests/system/isctest/asyncserver.py

index 3b4529ebe88a39ebc048cba38db44cda0ef6a1b4..15f181291eb2c4384aa001f1d86fe7b3713ae7f1 100644 (file)
@@ -642,6 +642,37 @@ class QnameHandler(ResponseHandler):
         return qctx.qname in self._qnames
 
 
+class QnameQtypeHandler(QnameHandler):
+    """
+    Handle queries for which both of the following conditions are true:
+
+    - the query's QNAME is present in `self.qnames`,
+    - the query's QTYPE is present in `self.qtypes`.
+    """
+
+    @property
+    @abc.abstractmethod
+    def qtypes(self) -> List[dns.rdatatype.RdataType]:
+        """
+        A list of QTYPEs handled by this class.
+        """
+        raise NotImplementedError
+
+    def __init__(self) -> None:
+        super().__init__()
+        self._qtypes: List[dns.rdatatype.RdataType] = self.qtypes
+
+    def __str__(self) -> str:
+        return f"{self.__class__.__name__}(QNAMEs: {', '.join(self.qnames)}; QTYPEs: {', '.join(map(str, self.qtypes))})"
+
+    def match(self, qctx: QueryContext) -> bool:
+        """
+        Handle queries whose QNAME and QTYPE match any of the QNAMEs and
+        QTYPEs handled by this class.
+        """
+        return qctx.qtype in self._qtypes and super().match(qctx)
+
+
 class DomainHandler(ResponseHandler):
     """
     Base class used for deriving custom domain handlers.