|
9 | 9 | import pytest |
10 | 10 | from test_service import NOW, call, register |
11 | 11 |
|
12 | | -from msg.core.codec import canonical, wire |
| 12 | +from msg.core.codec import b64, canonical, wire |
| 13 | +from msg.core.requests import request_for |
| 14 | +from msg.transports.dictionary import build_dictionary |
13 | 15 | from msg.transports.http import create_app |
14 | 16 |
|
15 | 17 |
|
@@ -217,11 +219,43 @@ async def test_home_summary_uses_existing_read_authority_and_remains_public(inst |
217 | 219 | app, _ = installed |
218 | 220 | assert all(operation.name != 'discovery.home' for operation in app.registry.operations()) |
219 | 221 | key, uid, cert = await register(app, 'home-summary-reader') |
220 | | - anonymous = await call(app, 'discovery.read_query', {'home_summary': True}) |
| 222 | + anonymous = await call(app, 'discovery.read_query', {'home_summary': True}, contract_version=4) |
221 | 223 | assert anonymous.status == 'ok' and 'posts' in anonymous.data |
222 | 224 | authenticated = await call( |
223 | | - app, 'discovery.read_query', {'home_summary': True}, key=key, subject=uid, certs=(cert,) |
| 225 | + app, |
| 226 | + 'discovery.read_query', |
| 227 | + {'home_summary': True}, |
| 228 | + key=key, |
| 229 | + subject=uid, |
| 230 | + certs=(cert,), |
| 231 | + contract_version=4, |
224 | 232 | ) |
225 | 233 | assert authenticated.error.code == 'public_home_summary_only' |
226 | | - mixed = await call(app, 'discovery.read_query', {'home_summary': True, 'parent': '/main'}) |
227 | | - assert mixed.error.code == 'invalid_home_summary' |
| 234 | + mixed = await call( |
| 235 | + app, 'discovery.read_query', {'home_summary': True, 'parent': '/main'}, contract_version=4 |
| 236 | + ) |
| 237 | + assert mixed.error.code == 'schema_validation' |
| 238 | + for args in ({}, {'home_summary': False}): |
| 239 | + invalid = await call(app, 'discovery.read_query', args, contract_version=4) |
| 240 | + assert invalid.error.code == 'schema_validation' |
| 241 | + legacy = await call(app, 'discovery.read_query', {'home_summary': True}) |
| 242 | + assert legacy.error.code == 'schema_validation' |
| 243 | + dictionary = build_dictionary(app.registry) |
| 244 | + direct_path = next( |
| 245 | + row['example'] |
| 246 | + for row in dictionary.document['operations'] |
| 247 | + if row['name'] == 'discovery.read_query' and row['version'] == 4 |
| 248 | + ) |
| 249 | + wrong_version = request_for( |
| 250 | + 'discovery.read_query', {'home_summary': True}, app.settings.service_url |
| 251 | + ) |
| 252 | + async with httpx.AsyncClient( |
| 253 | + transport=httpx.ASGITransport(app=create_app(app)), base_url=app.settings.service_url |
| 254 | + ) as http: |
| 255 | + direct = await http.get(direct_path) |
| 256 | + assert direct.status_code == 200 and 'posts' in direct.json()['data'] |
| 257 | + mismatched = await http.get( |
| 258 | + direct_path, headers={'X-Msg-Request': b64(canonical(wrong_version))} |
| 259 | + ) |
| 260 | + assert mismatched.status_code == 400 |
| 261 | + assert mismatched.json()['error']['code'] == 'representation_mismatch' |
0 commit comments