@@ -224,7 +224,7 @@ public function provideCooldown()
224224 /**
225225 * @dataProvider provideCooldown
226226 */
227- public function testCooldown (int $ attempt , int $ expectedExpiry )
227+ public function testInitiateCooldown (int $ attempt , int $ expectedExpiry )
228228 {
229229 $ cache = $ this ->prophesize (CacheItemPoolInterface::class);
230230
@@ -274,6 +274,36 @@ public function testCooldown(int $attempt, int $expectedExpiry)
274274
275275 $ this ->assertNull ($ result1 );
276276 }
277+
278+ public function provideMalformedResponseFromAllowLocationsLookup ()
279+ {
280+ return [
281+ [200 , '{"locations": ["us-west1"]} ' ], // missing allowLocations
282+ [200 , '{"locations": ["us-west1"] ' ], // invalid JSON
283+ [401 , '' ], // 4xx error
284+ [500 , '' ], // 5xx error
285+ ];
286+ }
287+
288+ /**
289+ * @dataProvider provideMalformedResponseFromAllowLocationsLookup
290+ */
291+ public function testMalformedResponseFromAllowLocationsLookup (int $ statusCode , string $ responseBody )
292+ {
293+ $ this ->impl ->setCache (new MemoryCacheItemPool ());
294+ $ handler = getHandler ([
295+ new Response ($ statusCode , [], $ responseBody ),
296+ ]);
297+ $ result = $ this ->impl ->getTrustBoundary (
298+ GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN ,
299+ $ handler ,
300+ 'default ' ,
301+ ['authorization ' => ['xyz ' ]]
302+ );
303+
304+ $ this ->assertNull ($ result );
305+ $ this ->assertTrue ($ this ->impl ->cooldownIsActive ());
306+ }
277307}
278308
279309class TrustBoundaryTraitImpl
@@ -305,4 +335,9 @@ public function setCache($cache)
305335 {
306336 $ this ->cache = $ cache ;
307337 }
338+
339+ public function cooldownIsActive (): bool
340+ {
341+ return (bool ) $ this ->getCachedValue ($ this ->getCacheKey () . ':trustboundary:cooldown ' );
342+ }
308343}
0 commit comments