From f14e9ad48600b2bc7f2e72e7ad3d60ebbe40a4b5 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Sat, 14 Mar 2026 22:56:07 +0100 Subject: [PATCH 1/2] easy fix Signed-off-by: Alexander Cristurean --- .../policy/authorization/auth_policy.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/testsuite/kuadrant/policy/authorization/auth_policy.py b/testsuite/kuadrant/policy/authorization/auth_policy.py index c394b7dd..88b739aa 100644 --- a/testsuite/kuadrant/policy/authorization/auth_policy.py +++ b/testsuite/kuadrant/policy/authorization/auth_policy.py @@ -55,15 +55,28 @@ def strategy(self, strategy: Strategy) -> None: if self.spec_section is None: raise TypeError("Strategy can only be set on defaults or overrides") - self.spec_section["strategy"] = strategy.value + if isinstance(self.spec_section, str): + # String marker - create the section now + section = self.model.spec.setdefault(self.spec_section, {}) + else: + section = self.spec_section + + section["strategy"] = strategy.value self.spec_section = None @property def auth_section(self): + """Returns the rules section for adding auth configuration""" if self.spec_section is None: - self.spec_section = self.model.spec + # Implicit mode - use model.spec directly + spec_section = self.model.spec + elif isinstance(self.spec_section, str): + # String marker ("defaults" or "overrides") - create the section now + spec_section = self.model.spec.setdefault(self.spec_section, {}) + else: + # Already a dict (shouldn't happen with new code but keep for compatibility) + spec_section = self.spec_section - spec_section = self.spec_section self.spec_section = None return spec_section.setdefault("rules", {}) @@ -75,13 +88,17 @@ def responses(self) -> ResponseSection: @property def defaults(self): """Add new rule into the `defaults` AuthPolicy section""" - self.spec_section = self.model.spec.setdefault("defaults", {}) + # Don't create the dict yet - only mark which section to use + # The dict will be created when auth_section is called + self.spec_section = "defaults" return self @property def overrides(self): """Add new rule into the `overrides` AuthPolicy section""" - self.spec_section = self.model.spec.setdefault("overrides", {}) + # Don't create the dict yet - only mark which section to use + # The dict will be created when auth_section is called + self.spec_section = "overrides" return self @modify From 36f7ece55c0f17c8f175455e95a9cbc9837d4093 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Sun, 15 Mar 2026 00:00:19 +0100 Subject: [PATCH 2/2] fix: also added rlp. Signed-off-by: Alexander Cristurean --- testsuite/kuadrant/policy/rate_limit.py | 29 ++++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/testsuite/kuadrant/policy/rate_limit.py b/testsuite/kuadrant/policy/rate_limit.py index 11d14f1f..fe465261 100644 --- a/testsuite/kuadrant/policy/rate_limit.py +++ b/testsuite/kuadrant/policy/rate_limit.py @@ -67,9 +67,16 @@ def add_limit( limit["counters"] = [asdict(rule) for rule in counters] if self.spec_section is None: - self.spec_section = self.model.spec - - self.spec_section.setdefault("limits", {})[name] = limit + # Implicit mode - use model.spec directly + spec_section = self.model.spec + elif isinstance(self.spec_section, str): + # String marker ("defaults" or "overrides") - create the section now + spec_section = self.model.spec.setdefault(self.spec_section, {}) + else: + # Already a dict (shouldn't happen with new code but keep for compatibility) + spec_section = self.spec_section + + spec_section.setdefault("limits", {})[name] = limit self.spec_section = None @modify @@ -78,19 +85,29 @@ def strategy(self, strategy: Strategy) -> None: if self.spec_section is None: raise TypeError("Strategy can only be set on defaults or overrides") - self.spec_section["strategy"] = strategy.value + if isinstance(self.spec_section, str): + # String marker - create the section now + section = self.model.spec.setdefault(self.spec_section, {}) + else: + section = self.spec_section + + section["strategy"] = strategy.value self.spec_section = None @property def defaults(self): """Add new rule into the `defaults` RateLimitPolicy section""" - self.spec_section = self.model.spec.setdefault("defaults", {}) + # Don't create the dict yet - only mark which section to use + # The dict will be created when add_limit or strategy is called + self.spec_section = "defaults" return self @property def overrides(self): """Add new rule into the `overrides` RateLimitPolicy section""" - self.spec_section = self.model.spec.setdefault("overrides", {}) + # Don't create the dict yet - only mark which section to use + # The dict will be created when add_limit or strategy is called + self.spec_section = "overrides" return self def wait_for_ready(self):