Skip to content

Commit 9937e3d

Browse files
committed
test for the lookup swallowing errors
1 parent 4999bdc commit 9937e3d

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/TrustBoundaryTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Google\Auth\HttpHandler\HttpClientCache;
66
use Google\Auth\HttpHandler\HttpHandlerFactory;
7-
use GuzzleHttp\Exception\ClientException;
7+
use GuzzleHttp\Exception\RequestException;
88
use GuzzleHttp\Psr7\Request;
99
use InvalidArgumentException;
1010

@@ -143,7 +143,7 @@ private function lookupTrustBoundary(
143143
try {
144144
$response = $httpHandler($request);
145145
return json_decode((string) $response->getBody(), true);
146-
} catch (ClientException $e) {
146+
} catch (RequestException $e) {
147147
// We swallow all errors here - a failed trust boundary lookup
148148
// should not disrupt client authentication.
149149
}

tests/TrustBoundaryTraitTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use Google\Auth\HttpHandler\HttpHandlerFactory;
88
use Google\Auth\TrustBoundaryTrait;
99
use GuzzleHttp\Client;
10+
use GuzzleHttp\Exception\RequestException;
1011
use GuzzleHttp\Handler\MockHandler;
12+
use GuzzleHttp\Psr7\Request;
1113
use GuzzleHttp\Psr7\Response;
1214
use PHPUnit\Framework\TestCase;
1315
use Prophecy\Argument;
@@ -135,6 +137,28 @@ public function testSkipLookupOutsideDefaultUniverseDomain()
135137

136138
$this->assertNull($result1);
137139
}
140+
141+
public function testLookupIsFailOpen()
142+
{
143+
$mock = new MockHandler([
144+
new RequestException('Error Communicating with Server', new Request('GET', 'test'))
145+
]);
146+
$handler = HttpHandlerFactory::build(new Client(['handler' => $mock]));
147+
148+
$this->assertNull($mock->getLastRequest());
149+
150+
// First call, should fetch and cache
151+
$result1 = $this->impl->getTrustBoundary(
152+
GetUniverseDomainInterface::DEFAULT_UNIVERSE_DOMAIN,
153+
$handler,
154+
'default',
155+
['authorization' => ['xyz']]
156+
);
157+
158+
// Ensure the request was made and the error was swallowed
159+
$this->assertNotNull($mock->getLastRequest());
160+
$this->assertNull($result1);
161+
}
138162
}
139163

140164
class TrustBoundaryTraitImpl

0 commit comments

Comments
 (0)