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.
- {unitysvc_core-0.3.8/src/unitysvc_core.egg-info → unitysvc_core-0.3.9}/PKG-INFO +5 -5
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/README.md +4 -4
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/pyproject.toml +1 -1
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/channel.py +6 -33
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/offering_v1.json +1 -17
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9/src/unitysvc_core.egg-info}/PKG-INFO +5 -5
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_request_rules.py +10 -26
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_validate_service.py +6 -11
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/LICENSE +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/setup.cfg +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/__init__.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/grants.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/__init__.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/base.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/documents.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/listing_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/listing_v1.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/offering_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/offering_v1.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/pricing.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/promotion_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/provider_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/provider_v1.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/service.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/service_group_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/models/validators.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/parameter_usage.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/py.typed +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/base.json +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/listing_v1.json +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/promotion_v1.json +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/provider_v1.json +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/schema/service_group_v1.json +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/utils.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core/validator.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/SOURCES.txt +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/dependency_links.txt +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/requires.txt +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/src/unitysvc_core.egg-info/top_level.txt +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_access_interface_routing.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_canonical_interfaces.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_channel.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_effective_price.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_external_apps.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_grants.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_hidden_path_skip.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_listing_audience.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_offering_data.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_parameter_usage.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_pricing.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_provider_account_rate_limits.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_service_group.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_service_status.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_utils.py +0 -0
- {unitysvc_core-0.3.8 → unitysvc_core-0.3.9}/tests/test_validator.py +0 -0
- {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.
|
|
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": "
|
|
284
|
-
|
|
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
|
|
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
|
|
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": "
|
|
249
|
-
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
163
|
-
and its limits are the gateway's
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
|
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.
|
|
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": "
|
|
284
|
-
|
|
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
|
|
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
|
|
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
|
-
"
|
|
57
|
-
"body.
|
|
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
|
|
61
|
-
|
|
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
|
-
|
|
69
|
-
(
|
|
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": '
|
|
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": "
|
|
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
|
|
120
|
-
|
|
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": "
|
|
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 "
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|