test_keyring.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import time
  16. from mock import Mock
  17. import attr
  18. import canonicaljson
  19. import signedjson.key
  20. import signedjson.sign
  21. from nacl.signing import SigningKey
  22. from signedjson.key import encode_verify_key_base64, get_verify_key
  23. from twisted.internet import defer
  24. from twisted.internet.defer import Deferred, ensureDeferred
  25. from synapse.api.errors import SynapseError
  26. from synapse.crypto import keyring
  27. from synapse.crypto.keyring import (
  28. PerspectivesKeyFetcher,
  29. ServerKeyFetcher,
  30. StoreKeyFetcher,
  31. )
  32. from synapse.logging.context import (
  33. LoggingContext,
  34. current_context,
  35. make_deferred_yieldable,
  36. )
  37. from synapse.storage.keys import FetchKeyResult
  38. from tests import unittest
  39. from tests.test_utils import make_awaitable
  40. from tests.unittest import logcontext_clean
  41. class MockPerspectiveServer:
  42. def __init__(self):
  43. self.server_name = "mock_server"
  44. self.key = signedjson.key.generate_signing_key(0)
  45. def get_verify_keys(self):
  46. vk = signedjson.key.get_verify_key(self.key)
  47. return {"%s:%s" % (vk.alg, vk.version): encode_verify_key_base64(vk)}
  48. def get_signed_key(self, server_name, verify_key):
  49. key_id = "%s:%s" % (verify_key.alg, verify_key.version)
  50. res = {
  51. "server_name": server_name,
  52. "old_verify_keys": {},
  53. "valid_until_ts": time.time() * 1000 + 3600,
  54. "verify_keys": {key_id: {"key": encode_verify_key_base64(verify_key)}},
  55. }
  56. self.sign_response(res)
  57. return res
  58. def sign_response(self, res):
  59. signedjson.sign.sign_json(res, self.server_name, self.key)
  60. @attr.s(slots=True)
  61. class FakeRequest:
  62. id = attr.ib()
  63. @logcontext_clean
  64. class KeyringTestCase(unittest.HomeserverTestCase):
  65. def check_context(self, val, expected):
  66. self.assertEquals(getattr(current_context(), "request", None), expected)
  67. return val
  68. def test_verify_json_objects_for_server_awaits_previous_requests(self):
  69. mock_fetcher = Mock()
  70. mock_fetcher.get_keys = Mock()
  71. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher,))
  72. # a signed object that we are going to try to validate
  73. key1 = signedjson.key.generate_signing_key(1)
  74. json1 = {}
  75. signedjson.sign.sign_json(json1, "server10", key1)
  76. # start off a first set of lookups. We make the mock fetcher block until this
  77. # deferred completes.
  78. first_lookup_deferred = Deferred()
  79. async def first_lookup_fetch(keys_to_fetch):
  80. self.assertEquals(current_context().request.id, "context_11")
  81. self.assertEqual(keys_to_fetch, {"server10": {get_key_id(key1): 0}})
  82. await make_deferred_yieldable(first_lookup_deferred)
  83. return {
  84. "server10": {
  85. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 100)
  86. }
  87. }
  88. mock_fetcher.get_keys.side_effect = first_lookup_fetch
  89. async def first_lookup():
  90. with LoggingContext("context_11", request=FakeRequest("context_11")):
  91. res_deferreds = kr.verify_json_objects_for_server(
  92. [("server10", json1, 0, "test10"), ("server11", {}, 0, "test11")]
  93. )
  94. # the unsigned json should be rejected pretty quickly
  95. self.assertTrue(res_deferreds[1].called)
  96. try:
  97. await res_deferreds[1]
  98. self.assertFalse("unsigned json didn't cause a failure")
  99. except SynapseError:
  100. pass
  101. self.assertFalse(res_deferreds[0].called)
  102. res_deferreds[0].addBoth(self.check_context, None)
  103. await make_deferred_yieldable(res_deferreds[0])
  104. d0 = ensureDeferred(first_lookup())
  105. mock_fetcher.get_keys.assert_called_once()
  106. # a second request for a server with outstanding requests
  107. # should block rather than start a second call
  108. async def second_lookup_fetch(keys_to_fetch):
  109. self.assertEquals(current_context().request.id, "context_12")
  110. return {
  111. "server10": {
  112. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 100)
  113. }
  114. }
  115. mock_fetcher.get_keys.reset_mock()
  116. mock_fetcher.get_keys.side_effect = second_lookup_fetch
  117. second_lookup_state = [0]
  118. async def second_lookup():
  119. with LoggingContext("context_12", request=FakeRequest("context_12")):
  120. res_deferreds_2 = kr.verify_json_objects_for_server(
  121. [("server10", json1, 0, "test")]
  122. )
  123. res_deferreds_2[0].addBoth(self.check_context, None)
  124. second_lookup_state[0] = 1
  125. await make_deferred_yieldable(res_deferreds_2[0])
  126. second_lookup_state[0] = 2
  127. d2 = ensureDeferred(second_lookup())
  128. self.pump()
  129. # the second request should be pending, but the fetcher should not yet have been
  130. # called
  131. self.assertEqual(second_lookup_state[0], 1)
  132. mock_fetcher.get_keys.assert_not_called()
  133. # complete the first request
  134. first_lookup_deferred.callback(None)
  135. # and now both verifications should succeed.
  136. self.get_success(d0)
  137. self.get_success(d2)
  138. def test_verify_json_for_server(self):
  139. kr = keyring.Keyring(self.hs)
  140. key1 = signedjson.key.generate_signing_key(1)
  141. r = self.hs.get_datastore().store_server_verify_keys(
  142. "server9",
  143. time.time() * 1000,
  144. [("server9", get_key_id(key1), FetchKeyResult(get_verify_key(key1), 1000))],
  145. )
  146. self.get_success(r)
  147. json1 = {}
  148. signedjson.sign.sign_json(json1, "server9", key1)
  149. # should fail immediately on an unsigned object
  150. d = _verify_json_for_server(kr, "server9", {}, 0, "test unsigned")
  151. self.get_failure(d, SynapseError)
  152. # should succeed on a signed object
  153. d = _verify_json_for_server(kr, "server9", json1, 500, "test signed")
  154. # self.assertFalse(d.called)
  155. self.get_success(d)
  156. def test_verify_json_for_server_with_null_valid_until_ms(self):
  157. """Tests that we correctly handle key requests for keys we've stored
  158. with a null `ts_valid_until_ms`
  159. """
  160. mock_fetcher = Mock()
  161. mock_fetcher.get_keys = Mock(return_value=make_awaitable({}))
  162. kr = keyring.Keyring(
  163. self.hs, key_fetchers=(StoreKeyFetcher(self.hs), mock_fetcher)
  164. )
  165. key1 = signedjson.key.generate_signing_key(1)
  166. r = self.hs.get_datastore().store_server_verify_keys(
  167. "server9",
  168. time.time() * 1000,
  169. [("server9", get_key_id(key1), FetchKeyResult(get_verify_key(key1), None))],
  170. )
  171. self.get_success(r)
  172. json1 = {}
  173. signedjson.sign.sign_json(json1, "server9", key1)
  174. # should fail immediately on an unsigned object
  175. d = _verify_json_for_server(kr, "server9", {}, 0, "test unsigned")
  176. self.get_failure(d, SynapseError)
  177. # should fail on a signed object with a non-zero minimum_valid_until_ms,
  178. # as it tries to refetch the keys and fails.
  179. d = _verify_json_for_server(
  180. kr, "server9", json1, 500, "test signed non-zero min"
  181. )
  182. self.get_failure(d, SynapseError)
  183. # We expect the keyring tried to refetch the key once.
  184. mock_fetcher.get_keys.assert_called_once_with(
  185. {"server9": {get_key_id(key1): 500}}
  186. )
  187. # should succeed on a signed object with a 0 minimum_valid_until_ms
  188. d = _verify_json_for_server(
  189. kr, "server9", json1, 0, "test signed with zero min"
  190. )
  191. self.get_success(d)
  192. def test_verify_json_dedupes_key_requests(self):
  193. """Two requests for the same key should be deduped."""
  194. key1 = signedjson.key.generate_signing_key(1)
  195. async def get_keys(keys_to_fetch):
  196. # there should only be one request object (with the max validity)
  197. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  198. return {
  199. "server1": {
  200. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 1200)
  201. }
  202. }
  203. mock_fetcher = Mock()
  204. mock_fetcher.get_keys = Mock(side_effect=get_keys)
  205. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher,))
  206. json1 = {}
  207. signedjson.sign.sign_json(json1, "server1", key1)
  208. # the first request should succeed; the second should fail because the key
  209. # has expired
  210. results = kr.verify_json_objects_for_server(
  211. [("server1", json1, 500, "test1"), ("server1", json1, 1500, "test2")]
  212. )
  213. self.assertEqual(len(results), 2)
  214. self.get_success(results[0])
  215. e = self.get_failure(results[1], SynapseError).value
  216. self.assertEqual(e.errcode, "M_UNAUTHORIZED")
  217. self.assertEqual(e.code, 401)
  218. # there should have been a single call to the fetcher
  219. mock_fetcher.get_keys.assert_called_once()
  220. def test_verify_json_falls_back_to_other_fetchers(self):
  221. """If the first fetcher cannot provide a recent enough key, we fall back"""
  222. key1 = signedjson.key.generate_signing_key(1)
  223. async def get_keys1(keys_to_fetch):
  224. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  225. return {
  226. "server1": {get_key_id(key1): FetchKeyResult(get_verify_key(key1), 800)}
  227. }
  228. async def get_keys2(keys_to_fetch):
  229. self.assertEqual(keys_to_fetch, {"server1": {get_key_id(key1): 1500}})
  230. return {
  231. "server1": {
  232. get_key_id(key1): FetchKeyResult(get_verify_key(key1), 1200)
  233. }
  234. }
  235. mock_fetcher1 = Mock()
  236. mock_fetcher1.get_keys = Mock(side_effect=get_keys1)
  237. mock_fetcher2 = Mock()
  238. mock_fetcher2.get_keys = Mock(side_effect=get_keys2)
  239. kr = keyring.Keyring(self.hs, key_fetchers=(mock_fetcher1, mock_fetcher2))
  240. json1 = {}
  241. signedjson.sign.sign_json(json1, "server1", key1)
  242. results = kr.verify_json_objects_for_server(
  243. [("server1", json1, 1200, "test1"), ("server1", json1, 1500, "test2")]
  244. )
  245. self.assertEqual(len(results), 2)
  246. self.get_success(results[0])
  247. e = self.get_failure(results[1], SynapseError).value
  248. self.assertEqual(e.errcode, "M_UNAUTHORIZED")
  249. self.assertEqual(e.code, 401)
  250. # there should have been a single call to each fetcher
  251. mock_fetcher1.get_keys.assert_called_once()
  252. mock_fetcher2.get_keys.assert_called_once()
  253. @logcontext_clean
  254. class ServerKeyFetcherTestCase(unittest.HomeserverTestCase):
  255. def make_homeserver(self, reactor, clock):
  256. self.http_client = Mock()
  257. hs = self.setup_test_homeserver(federation_http_client=self.http_client)
  258. return hs
  259. def test_get_keys_from_server(self):
  260. # arbitrarily advance the clock a bit
  261. self.reactor.advance(100)
  262. SERVER_NAME = "server2"
  263. fetcher = ServerKeyFetcher(self.hs)
  264. testkey = signedjson.key.generate_signing_key("ver1")
  265. testverifykey = signedjson.key.get_verify_key(testkey)
  266. testverifykey_id = "ed25519:ver1"
  267. VALID_UNTIL_TS = 200 * 1000
  268. # valid response
  269. response = {
  270. "server_name": SERVER_NAME,
  271. "old_verify_keys": {},
  272. "valid_until_ts": VALID_UNTIL_TS,
  273. "verify_keys": {
  274. testverifykey_id: {
  275. "key": signedjson.key.encode_verify_key_base64(testverifykey)
  276. }
  277. },
  278. }
  279. signedjson.sign.sign_json(response, SERVER_NAME, testkey)
  280. async def get_json(destination, path, **kwargs):
  281. self.assertEqual(destination, SERVER_NAME)
  282. self.assertEqual(path, "/_matrix/key/v2/server/key1")
  283. return response
  284. self.http_client.get_json.side_effect = get_json
  285. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  286. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  287. k = keys[SERVER_NAME][testverifykey_id]
  288. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  289. self.assertEqual(k.verify_key, testverifykey)
  290. self.assertEqual(k.verify_key.alg, "ed25519")
  291. self.assertEqual(k.verify_key.version, "ver1")
  292. # check that the perspectives store is correctly updated
  293. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  294. key_json = self.get_success(
  295. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  296. )
  297. res = key_json[lookup_triplet]
  298. self.assertEqual(len(res), 1)
  299. res = res[0]
  300. self.assertEqual(res["key_id"], testverifykey_id)
  301. self.assertEqual(res["from_server"], SERVER_NAME)
  302. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  303. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  304. # we expect it to be encoded as canonical json *before* it hits the db
  305. self.assertEqual(
  306. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  307. )
  308. # change the server name: the result should be ignored
  309. response["server_name"] = "OTHER_SERVER"
  310. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  311. self.assertEqual(keys, {})
  312. class PerspectivesKeyFetcherTestCase(unittest.HomeserverTestCase):
  313. def make_homeserver(self, reactor, clock):
  314. self.mock_perspective_server = MockPerspectiveServer()
  315. self.http_client = Mock()
  316. config = self.default_config()
  317. config["trusted_key_servers"] = [
  318. {
  319. "server_name": self.mock_perspective_server.server_name,
  320. "verify_keys": self.mock_perspective_server.get_verify_keys(),
  321. }
  322. ]
  323. return self.setup_test_homeserver(
  324. federation_http_client=self.http_client, config=config
  325. )
  326. def build_perspectives_response(
  327. self,
  328. server_name: str,
  329. signing_key: SigningKey,
  330. valid_until_ts: int,
  331. ) -> dict:
  332. """
  333. Build a valid perspectives server response to a request for the given key
  334. """
  335. verify_key = signedjson.key.get_verify_key(signing_key)
  336. verifykey_id = "%s:%s" % (verify_key.alg, verify_key.version)
  337. response = {
  338. "server_name": server_name,
  339. "old_verify_keys": {},
  340. "valid_until_ts": valid_until_ts,
  341. "verify_keys": {
  342. verifykey_id: {
  343. "key": signedjson.key.encode_verify_key_base64(verify_key)
  344. }
  345. },
  346. }
  347. # the response must be signed by both the origin server and the perspectives
  348. # server.
  349. signedjson.sign.sign_json(response, server_name, signing_key)
  350. self.mock_perspective_server.sign_response(response)
  351. return response
  352. def expect_outgoing_key_query(
  353. self, expected_server_name: str, expected_key_id: str, response: dict
  354. ) -> None:
  355. """
  356. Tell the mock http client to expect a perspectives-server key query
  357. """
  358. async def post_json(destination, path, data, **kwargs):
  359. self.assertEqual(destination, self.mock_perspective_server.server_name)
  360. self.assertEqual(path, "/_matrix/key/v2/query")
  361. # check that the request is for the expected key
  362. q = data["server_keys"]
  363. self.assertEqual(list(q[expected_server_name].keys()), [expected_key_id])
  364. return {"server_keys": [response]}
  365. self.http_client.post_json.side_effect = post_json
  366. def test_get_keys_from_perspectives(self):
  367. # arbitrarily advance the clock a bit
  368. self.reactor.advance(100)
  369. fetcher = PerspectivesKeyFetcher(self.hs)
  370. SERVER_NAME = "server2"
  371. testkey = signedjson.key.generate_signing_key("ver1")
  372. testverifykey = signedjson.key.get_verify_key(testkey)
  373. testverifykey_id = "ed25519:ver1"
  374. VALID_UNTIL_TS = 200 * 1000
  375. response = self.build_perspectives_response(
  376. SERVER_NAME,
  377. testkey,
  378. VALID_UNTIL_TS,
  379. )
  380. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  381. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  382. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  383. self.assertIn(SERVER_NAME, keys)
  384. k = keys[SERVER_NAME][testverifykey_id]
  385. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  386. self.assertEqual(k.verify_key, testverifykey)
  387. self.assertEqual(k.verify_key.alg, "ed25519")
  388. self.assertEqual(k.verify_key.version, "ver1")
  389. # check that the perspectives store is correctly updated
  390. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  391. key_json = self.get_success(
  392. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  393. )
  394. res = key_json[lookup_triplet]
  395. self.assertEqual(len(res), 1)
  396. res = res[0]
  397. self.assertEqual(res["key_id"], testverifykey_id)
  398. self.assertEqual(res["from_server"], self.mock_perspective_server.server_name)
  399. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  400. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  401. self.assertEqual(
  402. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  403. )
  404. def test_get_perspectives_own_key(self):
  405. """Check that we can get the perspectives server's own keys
  406. This is slightly complicated by the fact that the perspectives server may
  407. use different keys for signing notary responses.
  408. """
  409. # arbitrarily advance the clock a bit
  410. self.reactor.advance(100)
  411. fetcher = PerspectivesKeyFetcher(self.hs)
  412. SERVER_NAME = self.mock_perspective_server.server_name
  413. testkey = signedjson.key.generate_signing_key("ver1")
  414. testverifykey = signedjson.key.get_verify_key(testkey)
  415. testverifykey_id = "ed25519:ver1"
  416. VALID_UNTIL_TS = 200 * 1000
  417. response = self.build_perspectives_response(
  418. SERVER_NAME, testkey, VALID_UNTIL_TS
  419. )
  420. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  421. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  422. keys = self.get_success(fetcher.get_keys(keys_to_fetch))
  423. self.assertIn(SERVER_NAME, keys)
  424. k = keys[SERVER_NAME][testverifykey_id]
  425. self.assertEqual(k.valid_until_ts, VALID_UNTIL_TS)
  426. self.assertEqual(k.verify_key, testverifykey)
  427. self.assertEqual(k.verify_key.alg, "ed25519")
  428. self.assertEqual(k.verify_key.version, "ver1")
  429. # check that the perspectives store is correctly updated
  430. lookup_triplet = (SERVER_NAME, testverifykey_id, None)
  431. key_json = self.get_success(
  432. self.hs.get_datastore().get_server_keys_json([lookup_triplet])
  433. )
  434. res = key_json[lookup_triplet]
  435. self.assertEqual(len(res), 1)
  436. res = res[0]
  437. self.assertEqual(res["key_id"], testverifykey_id)
  438. self.assertEqual(res["from_server"], self.mock_perspective_server.server_name)
  439. self.assertEqual(res["ts_added_ms"], self.reactor.seconds() * 1000)
  440. self.assertEqual(res["ts_valid_until_ms"], VALID_UNTIL_TS)
  441. self.assertEqual(
  442. bytes(res["key_json"]), canonicaljson.encode_canonical_json(response)
  443. )
  444. def test_invalid_perspectives_responses(self):
  445. """Check that invalid responses from the perspectives server are rejected"""
  446. # arbitrarily advance the clock a bit
  447. self.reactor.advance(100)
  448. SERVER_NAME = "server2"
  449. testkey = signedjson.key.generate_signing_key("ver1")
  450. testverifykey = signedjson.key.get_verify_key(testkey)
  451. testverifykey_id = "ed25519:ver1"
  452. VALID_UNTIL_TS = 200 * 1000
  453. def build_response():
  454. return self.build_perspectives_response(
  455. SERVER_NAME, testkey, VALID_UNTIL_TS
  456. )
  457. def get_key_from_perspectives(response):
  458. fetcher = PerspectivesKeyFetcher(self.hs)
  459. keys_to_fetch = {SERVER_NAME: {"key1": 0}}
  460. self.expect_outgoing_key_query(SERVER_NAME, "key1", response)
  461. return self.get_success(fetcher.get_keys(keys_to_fetch))
  462. # start with a valid response so we can check we are testing the right thing
  463. response = build_response()
  464. keys = get_key_from_perspectives(response)
  465. k = keys[SERVER_NAME][testverifykey_id]
  466. self.assertEqual(k.verify_key, testverifykey)
  467. # remove the perspectives server's signature
  468. response = build_response()
  469. del response["signatures"][self.mock_perspective_server.server_name]
  470. keys = get_key_from_perspectives(response)
  471. self.assertEqual(keys, {}, "Expected empty dict with missing persp server sig")
  472. # remove the origin server's signature
  473. response = build_response()
  474. del response["signatures"][SERVER_NAME]
  475. keys = get_key_from_perspectives(response)
  476. self.assertEqual(keys, {}, "Expected empty dict with missing origin server sig")
  477. def get_key_id(key):
  478. """Get the matrix ID tag for a given SigningKey or VerifyKey"""
  479. return "%s:%s" % (key.alg, key.version)
  480. @defer.inlineCallbacks
  481. def run_in_context(f, *args, **kwargs):
  482. with LoggingContext("testctx"):
  483. rv = yield f(*args, **kwargs)
  484. return rv
  485. def _verify_json_for_server(kr, *args):
  486. """thin wrapper around verify_json_for_server which makes sure it is wrapped
  487. with the patched defer.inlineCallbacks.
  488. """
  489. @defer.inlineCallbacks
  490. def v():
  491. rv1 = yield kr.verify_json_for_server(*args)
  492. return rv1
  493. return run_in_context(v)