File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
packages/google-cloud-ndb Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ def get_and_validate(self, key):
4949 del self .data [key ]
5050 raise KeyError (key )
5151
52+ def __repr__ (self ):
53+ return "ContextCache()"
54+
5255
5356def _future_result (result ):
5457 """Returns a completed Future with the given result.
Original file line number Diff line number Diff line change 1717"""
1818import os
1919import pickle
20+ import traceback
21+
22+ try :
23+ from unittest import mock
24+ except ImportError : # pragma: NO PY3 COVER
25+ import mock
2026
2127import pytest
2228
2329import test_utils .system
2430
31+ from google .api_core import exceptions as core_exceptions
2532from google .cloud import ndb
2633
2734from . import eventually , length_equals , KIND
@@ -315,3 +322,27 @@ class SomeKind(ndb.Model):
315322 entity = key .get ()
316323
317324 assert entity .bar == 42
325+
326+
327+ @mock .patch ("google.cloud.ndb._datastore_api.begin_transaction" )
328+ def test_do_not_disclose_cache_contents (begin_transaction , client_context ):
329+ """Regression test for #482.
330+
331+ https://github.com/googleapis/python-ndb/issues/482
332+ """
333+ begin_transaction .side_effect = core_exceptions .ServiceUnavailable (
334+ "Spurious Error"
335+ )
336+
337+ client_context .cache ["hello dad" ] = "i'm in jail"
338+
339+ @ndb .transactional ()
340+ def callback ():
341+ pass
342+
343+ with pytest .raises (Exception ) as error_info :
344+ callback ()
345+
346+ error = error_info .value
347+ message = "" .join (traceback .format_exception_only (type (error ), error ))
348+ assert "hello dad" not in message
Original file line number Diff line number Diff line change @@ -58,6 +58,12 @@ def test_get_and_validate_miss():
5858 with pytest .raises (KeyError ):
5959 cache .get_and_validate ("nonexistent_key" )
6060
61+ @staticmethod
62+ def test___repr__ ():
63+ cache = _cache .ContextCache ()
64+ cache ["hello dad" ] = "i'm in jail"
65+ assert repr (cache ) == "ContextCache()"
66+
6167
6268class Test_GlobalCacheBatch :
6369 @staticmethod
You can’t perform that action at this time.
0 commit comments