unitysvc-core 0.3.8__tar.gz → 0.3.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {unitysvc_core-0.3.8/src/unitysvc_core.egg-info → unitysvc_core-0.3.9}/PKG-INFO +5 -5
  2. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/README.md +4 -4
  3. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/pyproject.toml +1 -1
  4. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/channel.py +6 -33
  5. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/offering_v1.json +1 -17
  6. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9/src/unitysvc_core.egg-info}/PKG-INFO +5 -5
  7. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_request_rules.py +10 -26
  8. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_validate_service.py +6 -11
  9. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/LICENSE +0 -0
  10. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/setup.cfg +0 -0
  11. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/__init__.py +0 -0
  12. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/grants.py +0 -0
  13. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/__init__.py +0 -0
  14. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/base.py +0 -0
  15. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/documents.py +0 -0
  16. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/listing_data.py +0 -0
  17. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/listing_v1.py +0 -0
  18. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/offering_data.py +0 -0
  19. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/offering_v1.py +0 -0
  20. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/pricing.py +0 -0
  21. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/promotion_data.py +0 -0
  22. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/provider_data.py +0 -0
  23. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/provider_v1.py +0 -0
  24. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/service.py +0 -0
  25. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/service_group_data.py +0 -0
  26. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/validators.py +0 -0
  27. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/parameter_usage.py +0 -0
  28. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/py.typed +0 -0
  29. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/base.json +0 -0
  30. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/listing_v1.json +0 -0
  31. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/promotion_v1.json +0 -0
  32. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/provider_v1.json +0 -0
  33. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/service_group_v1.json +0 -0
  34. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/utils.py +0 -0
  35. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/validator.py +0 -0
  36. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/SOURCES.txt +0 -0
  37. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/dependency_links.txt +0 -0
  38. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/requires.txt +0 -0
  39. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/top_level.txt +0 -0
  40. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_access_interface_routing.py +0 -0
  41. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_canonical_interfaces.py +0 -0
  42. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_channel.py +0 -0
  43. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_effective_price.py +0 -0
  44. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_external_apps.py +0 -0
  45. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_grants.py +0 -0
  46. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_hidden_path_skip.py +0 -0
  47. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_listing_audience.py +0 -0
  48. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_offering_data.py +0 -0
  49. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_parameter_usage.py +0 -0
  50. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_pricing.py +0 -0
  51. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_provider_account_rate_limits.py +0 -0
  52. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_service_group.py +0 -0
  53. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_service_status.py +0 -0
  54. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_utils.py +0 -0
  55. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_validator.py +0 -0
  56. {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.8
3
+ Version: 0.3.9
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -280,16 +280,16 @@ An `http` channel may list up to 32 `request_rules` (unitysvc/unitysvc#2947, uni
280
280
  ```json
281
281
  "request_rules": [
282
282
  {"name": "github-ping", "when": "header[\"x-github-event\"] == \"ping\"", "respond": {"status": 200}},
283
- {"name": "own-echo", "when": "secret_equals(\"DISCORD_WEBHOOK_ID\", body.user_id)",
284
- "customer_secrets": ["DISCORD_WEBHOOK_ID"], "respond": {"status": 204}}
283
+ {"name": "own-echo", "when": "body.user_id == \"${ customer_secrets.DISCORD_WEBHOOK_ID ?? }\"", "respond": {"status": 204}},
284
+ {"name": "filter", "when": "body.count >= {{ params.MIN_COUNT }}", "respond": {"status": 204}}
285
285
  ]
286
286
  ```
287
287
 
288
- `when` is a Lua expression that the gateway compiles and evaluates against the request; its environment (the request's `body`, `header`, `query`, `method`, the enrollment's `params`, the approved helpers) and its limits are the gateway's, documented there. Core does not parse it. It checks only that it is non-empty, at most 1024 bytes, and free of template references (`${ … }`, `{{ … }}`): values reach a condition as arguments, never by substitution into its source. A condition reads a customer secret only through `secret_equals(NAME, value)`, and only a secret the rule declares in `customer_secrets` (1–8 `UPPER_SNAKE_CASE` names); a rule's secret is always optional for the customer. A Lua syntax error is reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
288
+ `when` is a Lua expression that the gateway compiles and evaluates against the request. Its environment (the request's `body`, `header`, `query` and `method`, the approved functions), its template references (`${ customer_secrets.NAME ?? }`, `${ secrets.NAME }`, `{{ params.NAME }}`, `{{ enrollment.code }}`, bound as values and never spliced into the source; a secret may only be compared whole with `==` / `~=`) and its limits are the gateway's, documented in apisix-gateways' README. Core does not parse it: it checks only that it is non-empty and at most 1024 bytes. Lua syntax errors and invalid references are reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
289
289
 
290
290
  `respond` takes a `status` (200–599), an optional `body` (an object or array is sent as JSON; a string needs `content_type`), and optional `headers` (not the gateway-managed or hop-by-hop ones).
291
291
 
292
- 0.3.7 accepted a different, two-operator condition grammar; 0.3.8 replaces it. No published service used it.
292
+ Versions: 0.3.7 accepted a two-operator grammar; 0.3.8 refused template references and added `customer_secrets`; 0.3.9 follows the gateway as merged (template references in `when`, no `customer_secrets`). No published service used 0.3.7 or 0.3.8 rules.
293
293
 
294
294
  ### External apps and product links
295
295
 
@@ -245,16 +245,16 @@ An `http` channel may list up to 32 `request_rules` (unitysvc/unitysvc#2947, uni
245
245
  ```json
246
246
  "request_rules": [
247
247
  {"name": "github-ping", "when": "header[\"x-github-event\"] == \"ping\"", "respond": {"status": 200}},
248
- {"name": "own-echo", "when": "secret_equals(\"DISCORD_WEBHOOK_ID\", body.user_id)",
249
- "customer_secrets": ["DISCORD_WEBHOOK_ID"], "respond": {"status": 204}}
248
+ {"name": "own-echo", "when": "body.user_id == \"${ customer_secrets.DISCORD_WEBHOOK_ID ?? }\"", "respond": {"status": 204}},
249
+ {"name": "filter", "when": "body.count >= {{ params.MIN_COUNT }}", "respond": {"status": 204}}
250
250
  ]
251
251
  ```
252
252
 
253
- `when` is a Lua expression that the gateway compiles and evaluates against the request; its environment (the request's `body`, `header`, `query`, `method`, the enrollment's `params`, the approved helpers) and its limits are the gateway's, documented there. Core does not parse it. It checks only that it is non-empty, at most 1024 bytes, and free of template references (`${ … }`, `{{ … }}`): values reach a condition as arguments, never by substitution into its source. A condition reads a customer secret only through `secret_equals(NAME, value)`, and only a secret the rule declares in `customer_secrets` (1–8 `UPPER_SNAKE_CASE` names); a rule's secret is always optional for the customer. A Lua syntax error is reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
253
+ `when` is a Lua expression that the gateway compiles and evaluates against the request. Its environment (the request's `body`, `header`, `query` and `method`, the approved functions), its template references (`${ customer_secrets.NAME ?? }`, `${ secrets.NAME }`, `{{ params.NAME }}`, `{{ enrollment.code }}`, bound as values and never spliced into the source; a secret may only be compared whole with `==` / `~=`) and its limits are the gateway's, documented in apisix-gateways' README. Core does not parse it: it checks only that it is non-empty and at most 1024 bytes. Lua syntax errors and invalid references are reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
254
254
 
255
255
  `respond` takes a `status` (200–599), an optional `body` (an object or array is sent as JSON; a string needs `content_type`), and optional `headers` (not the gateway-managed or hop-by-hop ones).
256
256
 
257
- 0.3.7 accepted a different, two-operator condition grammar; 0.3.8 replaces it. No published service used it.
257
+ Versions: 0.3.7 accepted a two-operator grammar; 0.3.8 refused template references and added `customer_secrets`; 0.3.9 follows the gateway as merged (template references in `when`, no `customer_secrets`). No published service used 0.3.7 or 0.3.8 rules.
258
258
 
259
259
  ### External apps and product links
260
260
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "unitysvc-core"
7
- version = "0.3.8"
7
+ version = "0.3.9"
8
8
  description = "Shared data models and validation helpers for UnitySVC packages"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Bo Peng", email = "bo.peng@unitysvc.com" }]
@@ -107,8 +107,6 @@ _CONTENT_TYPE_RE = re.compile(r"^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]*/[A-Za-z0-9][A-
107
107
  _MAX_RULE_BODY_BYTES = 8192
108
108
  MAX_RULES = 32
109
109
  MAX_CONDITION_BYTES = 1024
110
- _MAX_RULE_SECRETS = 8
111
- _SECRET_NAME_RE = re.compile(r"[A-Z_][A-Z0-9_]*")
112
110
  _MAX_RULE_HEADERS = 16
113
111
 
114
112
 
@@ -159,14 +157,12 @@ class RequestRule(BaseModel):
159
157
  """A condition the gateway checks before dispatch, and the response it answers with when it holds.
160
158
 
161
159
  ``when`` is a Lua expression the gateway compiles and evaluates against the
162
- request (unitysvc/apisix-gateways#94); its language, the values it can read
163
- and its limits are the gateway's. Core does not parse it: it checks only
164
- that it is a bounded string carrying no template syntax, since values
165
- reach a condition as arguments, never by substitution into its source.
166
-
167
- A condition reads a customer secret only through the gateway's
168
- ``secret_equals(NAME, value)`` helper, and only a secret it declares in
169
- ``customer_secrets``; the platform resolves exactly those names for the rule.
160
+ request (unitysvc/apisix-gateways#94, #96); its language, the values it can
161
+ read and its limits are the gateway's, and core does not parse it. Template
162
+ references (``${ customer_secrets.NAME ?? }``, ``${ secrets.NAME }``,
163
+ ``{{ params.NAME }}``, ``{{ enrollment.code }}``) are bound by the gateway as
164
+ invocation arguments, never spliced into the source; a secret may only be
165
+ compared whole (``==`` / ``~=``).
170
166
  """
171
167
 
172
168
  model_config = ConfigDict(extra="forbid")
@@ -181,11 +177,6 @@ class RequestRule(BaseModel):
181
177
  description='A Lua expression evaluated by the gateway, e.g. header["x-github-event"] == "ping"; '
182
178
  "absent means every request",
183
179
  )
184
- customer_secrets: list[str] | None = Field(
185
- default=None,
186
- description="Customer secrets the condition compares with secret_equals(NAME, value); "
187
- "a rule's secret is always optional for the customer",
188
- )
189
180
  respond: RuleResponse
190
181
 
191
182
  @field_validator("when")
@@ -197,26 +188,8 @@ class RequestRule(BaseModel):
197
188
  raise ValueError("a condition must not be empty; omit `when` to answer every request")
198
189
  if len(value.encode()) > MAX_CONDITION_BYTES:
199
190
  raise ValueError(f"a condition is longer than {MAX_CONDITION_BYTES} bytes (UTF-8)")
200
- if "${" in value or "{{" in value:
201
- raise ValueError(
202
- "a condition takes no template references: read params as params.NAME, and compare a "
203
- 'customer secret with secret_equals("NAME", value) after declaring it in customer_secrets'
204
- )
205
191
  return value
206
192
 
207
- @field_validator("customer_secrets")
208
- @classmethod
209
- def _check_secret_names(cls, names: list[str] | None) -> list[str] | None:
210
- if names is None:
211
- return names
212
- if not names or len(names) > _MAX_RULE_SECRETS:
213
- raise ValueError(f"customer_secrets lists 1 to {_MAX_RULE_SECRETS} names; omit it when there are none")
214
- if bad := [name for name in names if not _SECRET_NAME_RE.fullmatch(name)]:
215
- raise ValueError(f"customer secret names are UPPER_SNAKE_CASE: {', '.join(bad)}")
216
- if len(set(names)) != len(names):
217
- raise ValueError("customer_secrets lists a name twice")
218
- return names
219
-
220
193
 
221
194
  class _Server(BaseModel):
222
195
  """Fields every server has, whatever its protocol."""
@@ -2361,24 +2361,8 @@
2361
2361
  },
2362
2362
  "RequestRule": {
2363
2363
  "additionalProperties": false,
2364
- "description": "A condition the gateway checks before dispatch, and the response it answers with when it holds.\n\n``when`` is a Lua expression the gateway compiles and evaluates against the\nrequest (unitysvc/apisix-gateways#94); its language, the values it can read\nand its limits are the gateway's. Core does not parse it: it checks only\nthat it is a bounded string carrying no template syntax, since values\nreach a condition as arguments, never by substitution into its source.\n\nA condition reads a customer secret only through the gateway's\n``secret_equals(NAME, value)`` helper, and only a secret it declares in\n``customer_secrets``; the platform resolves exactly those names for the rule.",
2364
+ "description": "A condition the gateway checks before dispatch, and the response it answers with when it holds.\n\n``when`` is a Lua expression the gateway compiles and evaluates against the\nrequest (unitysvc/apisix-gateways#94, #96); its language, the values it can\nread and its limits are the gateway's, and core does not parse it. Template\nreferences (``${ customer_secrets.NAME ?? }``, ``${ secrets.NAME }``,\n``{{ params.NAME }}``, ``{{ enrollment.code }}``) are bound by the gateway as\ninvocation arguments, never spliced into the source; a secret may only be\ncompared whole (``==`` / ``~=``).",
2365
2365
  "properties": {
2366
- "customer_secrets": {
2367
- "anyOf": [
2368
- {
2369
- "items": {
2370
- "type": "string"
2371
- },
2372
- "type": "array"
2373
- },
2374
- {
2375
- "type": "null"
2376
- }
2377
- ],
2378
- "default": null,
2379
- "description": "Customer secrets the condition compares with secret_equals(NAME, value); a rule's secret is always optional for the customer",
2380
- "title": "Customer Secrets"
2381
- },
2382
2366
  "name": {
2383
2367
  "anyOf": [
2384
2368
  {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: unitysvc-core
3
- Version: 0.3.8
3
+ Version: 0.3.9
4
4
  Summary: Shared data models and validation helpers for UnitySVC packages
5
5
  Author-email: Bo Peng <bo.peng@unitysvc.com>
6
6
  Maintainer-email: Bo Peng <bo.peng@unitysvc.com>
@@ -280,16 +280,16 @@ An `http` channel may list up to 32 `request_rules` (unitysvc/unitysvc#2947, uni
280
280
  ```json
281
281
  "request_rules": [
282
282
  {"name": "github-ping", "when": "header[\"x-github-event\"] == \"ping\"", "respond": {"status": 200}},
283
- {"name": "own-echo", "when": "secret_equals(\"DISCORD_WEBHOOK_ID\", body.user_id)",
284
- "customer_secrets": ["DISCORD_WEBHOOK_ID"], "respond": {"status": 204}}
283
+ {"name": "own-echo", "when": "body.user_id == \"${ customer_secrets.DISCORD_WEBHOOK_ID ?? }\"", "respond": {"status": 204}},
284
+ {"name": "filter", "when": "body.count >= {{ params.MIN_COUNT }}", "respond": {"status": 204}}
285
285
  ]
286
286
  ```
287
287
 
288
- `when` is a Lua expression that the gateway compiles and evaluates against the request; its environment (the request's `body`, `header`, `query`, `method`, the enrollment's `params`, the approved helpers) and its limits are the gateway's, documented there. Core does not parse it. It checks only that it is non-empty, at most 1024 bytes, and free of template references (`${ … }`, `{{ … }}`): values reach a condition as arguments, never by substitution into its source. A condition reads a customer secret only through `secret_equals(NAME, value)`, and only a secret the rule declares in `customer_secrets` (1–8 `UPPER_SNAKE_CASE` names); a rule's secret is always optional for the customer. A Lua syntax error is reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
288
+ `when` is a Lua expression that the gateway compiles and evaluates against the request. Its environment (the request's `body`, `header`, `query` and `method`, the approved functions), its template references (`${ customer_secrets.NAME ?? }`, `${ secrets.NAME }`, `{{ params.NAME }}`, `{{ enrollment.code }}`, bound as values and never spliced into the source; a secret may only be compared whole with `==` / `~=`) and its limits are the gateway's, documented in apisix-gateways' README. Core does not parse it: it checks only that it is non-empty and at most 1024 bytes. Lua syntax errors and invalid references are reported by the gateway (the channel answers 503) and by a gateway-run test (`services run-tests`), not by `specs validate`.
289
289
 
290
290
  `respond` takes a `status` (200–599), an optional `body` (an object or array is sent as JSON; a string needs `content_type`), and optional `headers` (not the gateway-managed or hop-by-hop ones).
291
291
 
292
- 0.3.7 accepted a different, two-operator condition grammar; 0.3.8 replaces it. No published service used it.
292
+ Versions: 0.3.7 accepted a two-operator grammar; 0.3.8 refused template references and added `customer_secrets`; 0.3.9 follows the gateway as merged (template references in `when`, no `customer_secrets`). No published service used 0.3.7 or 0.3.8 rules.
293
293
 
294
294
  ### External apps and product links
295
295
 
@@ -53,32 +53,17 @@ class TestCondition:
53
53
  "when",
54
54
  [
55
55
  "body.id == '${ customer_secrets.HOOK ?? }'",
56
- "body.id == '${ secrets.TOKEN }'",
57
- "body.name == '{{ params.marker }}'",
56
+ 'header["x-token"] ~= "${ secrets.TOKEN }"',
57
+ "body.count >= {{ params.MIN_COUNT }} and not {{ params.DISABLED }}",
58
+ 'query["code"] == "{{ enrollment.code }}"',
58
59
  ],
59
60
  )
60
- def test_template_references_are_refused(self, when: str) -> None:
61
- with pytest.raises(ValidationError, match="takes no template references"):
62
- self._rule(when=when)
63
-
64
- def test_declared_customer_secrets(self) -> None:
65
- rule = self._rule(when='secret_equals("HOOK_ID", body.user_id)', customer_secrets=["HOOK_ID"])
66
- assert rule.customer_secrets == ["HOOK_ID"]
61
+ def test_template_references_are_left_to_the_gateway(self, when: str) -> None:
62
+ assert self._rule(when=when).when == when
67
63
 
68
- @pytest.mark.parametrize(
69
- ("names", "message"),
70
- [
71
- ([], "1 to 8 names"),
72
- ([f"S{i}" for i in range(9)], "1 to 8 names"),
73
- (["hook_id"], "UPPER_SNAKE_CASE"),
74
- (["HOOK-ID"], "UPPER_SNAKE_CASE"),
75
- (["HOOK_ID\n"], "UPPER_SNAKE_CASE"),
76
- (["A", "A"], "twice"),
77
- ],
78
- )
79
- def test_bad_customer_secret_lists(self, names: list[str], message: str) -> None:
80
- with pytest.raises(ValidationError, match=message):
81
- self._rule(when="true", customer_secrets=names)
64
+ def test_customer_secrets_is_not_a_rule_field(self) -> None:
65
+ with pytest.raises(ValidationError, match="customer_secrets"):
66
+ self._rule(when="true", customer_secrets=["HOOK_ID"])
82
67
 
83
68
 
84
69
  class TestChannelField:
@@ -96,8 +81,7 @@ class TestChannelField:
96
81
  def test_round_trip(self) -> None:
97
82
  rule = {
98
83
  "name": "echo",
99
- "when": 'secret_equals("DISCORD_WEBHOOK_ID", body.user_id)',
100
- "customer_secrets": ["DISCORD_WEBHOOK_ID"],
84
+ "when": 'body.user_id == "${ customer_secrets.DISCORD_WEBHOOK_ID ?? }"',
101
85
  "respond": {"status": 204},
102
86
  }
103
87
  dumped = _rules_channel(rule).model_dump(exclude_none=True)
@@ -105,7 +89,7 @@ class TestChannelField:
105
89
 
106
90
  def test_bad_condition_names_its_rule(self) -> None:
107
91
  with pytest.raises(ValidationError, match=r"request_rules\.0\.when"):
108
- _rules_channel({"when": "body.a == '{{ params.a }}'", "respond": {"status": 204}})
92
+ _rules_channel({"when": " ", "respond": {"status": 204}})
109
93
 
110
94
  @pytest.mark.parametrize(
111
95
  "config",
@@ -116,24 +116,21 @@ def test_services_validate_in_parallel_with_one_validator(validator: DataValidat
116
116
 
117
117
 
118
118
  def test_a_request_rule_condition_is_checked(validator: DataValidator) -> None:
119
- """``specs validate`` accepts a Lua condition unparsed and reports a template
120
- reference with the rule it is in (unitysvc/unitysvc#2947, apisix-gateways#94)."""
119
+ """``specs validate`` accepts a Lua condition, template references included,
120
+ unparsed, and reports an empty one with the rule it is in
121
+ (unitysvc/unitysvc#2947, apisix-gateways#96)."""
121
122
  files = _files(SERVICES[0])
122
123
  offering = files["offering"]
123
124
  channel = next(iter(offering["upstream_access_config"].values()))
124
125
  channel["request_rules"] = [
125
126
  {"when": 'header["x-github-event"] == "ping" or (body.n or 0) > 3', "respond": {"status": 200}},
126
- {
127
- "when": 'secret_equals("HOOK_ID", body.user_id)',
128
- "customer_secrets": ["HOOK_ID"],
129
- "respond": {"status": 204},
130
- },
127
+ {"when": 'body.user_id == "${ customer_secrets.HOOK_ID ?? }"', "respond": {"status": 204}},
131
128
  ]
132
129
  assert validator.validate_service(offering=offering)["offering"] == []
133
130
 
134
- channel["request_rules"] = [{"when": "body.id == '${ customer_secrets.HOOK ?? }'", "respond": {"status": 204}}]
131
+ channel["request_rules"] = [{"when": " ", "respond": {"status": 204}}]
135
132
  errors = validator.validate_service(offering=offering)["offering"]
136
- assert any("request_rules" in e and "takes no template references" in e for e in errors)
133
+ assert any("request_rules" in e and "must not be empty" in e for e in errors)
137
134
 
138
135
 
139
136
  @pytest.mark.parametrize(
@@ -141,9 +138,7 @@ def test_a_request_rule_condition_is_checked(validator: DataValidator) -> None:
141
138
  [
142
139
  {"respond": {"status": 200, "headers": {"Content-Length\n": "100"}}},
143
140
  {"respond": {"status": 200, "body": "ok", "content_type": "text/plain\r\n; charset=utf-8"}},
144
- {"when": "body.id == '{{ params.HOOK }}'", "respond": {"status": 204}},
145
141
  {"when": " ", "respond": {"status": 204}},
146
- {"when": "x", "customer_secrets": ["lower_case"], "respond": {"status": 204}},
147
142
  ],
148
143
  )
149
144
  def test_request_rule_boundary_errors_reach_service_validation(validator: DataValidator, rule: dict) -> None:
File without changes
File without changes