From 7a867a500ba680262b6ecce10886254c233de944 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 22 May 2023 23:30:03 -0600 Subject: [PATCH] chore: remove unnecessary api endpoint check (#313) --- src/GapicClientTrait.php | 9 ----- tests/Tests/Unit/GapicClientTraitTest.php | 40 +++++++++++++++++------ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/GapicClientTrait.php b/src/GapicClientTrait.php index a8dd6782a..5d6da74e2 100644 --- a/src/GapicClientTrait.php +++ b/src/GapicClientTrait.php @@ -200,15 +200,6 @@ private function buildClientOptions(array $options) $options['apiEndpoint'] = $this->pluck('serviceAddress', $options, false); } - // If an API endpoint is set, ensure the "audience" does not conflict - // with the custom endpoint by setting "user defined" scopes. - if ($options['apiEndpoint'] != $defaultOptions['apiEndpoint'] - && empty($options['credentialsConfig']['scopes']) - && !empty($options['credentialsConfig']['defaultScopes']) - ) { - $options['credentialsConfig']['scopes'] = $options['credentialsConfig']['defaultScopes']; - } - if (extension_loaded('sysvshm') && isset($options['gcpApiConfigPath']) && file_exists($options['gcpApiConfigPath']) diff --git a/tests/Tests/Unit/GapicClientTraitTest.php b/tests/Tests/Unit/GapicClientTraitTest.php index 3c98429e4..3ae482393 100644 --- a/tests/Tests/Unit/GapicClientTraitTest.php +++ b/tests/Tests/Unit/GapicClientTraitTest.php @@ -1389,16 +1389,6 @@ public function testDefaultScopes() $defaultOptions = $client->call('buildClientOptions', [[]]); $this->assertArrayNotHasKey('scopes', $defaultOptions['credentialsConfig']); - // verify scopes are set when a custom api endpoint is used - $defaultOptions = $client->call('buildClientOptions', [[ - 'apiEndpoint' => 'www.someotherendpoint.com', - ]]); - $this->assertArrayHasKey('scopes', $defaultOptions['credentialsConfig']); - $this->assertEquals( - $client::$serviceScopes, - $defaultOptions['credentialsConfig']['scopes'] - ); - // verify user-defined scopes override default scopes $defaultOptions = $client->call('buildClientOptions', [[ 'credentialsConfig' => ['scopes' => ['user-scope-1']], @@ -1461,6 +1451,36 @@ public function testDefaultAudience() ]]); } + public function testDefaultAudienceWithCustomApiEndpoint() + { + $retrySettings = $this->prophesize(RetrySettings::class); + $credentialsWrapper = $this->prophesize(CredentialsWrapper::class) + ->reveal(); + $transport = $this->prophesize(TransportInterface::class); + $transport + ->startUnaryCall( + Argument::any(), + [ + 'audience' => 'https://service-address/', + 'headers' => [], + 'credentialsWrapper' => $credentialsWrapper, + ] + ) + ->shouldBeCalledOnce(); + + $client = new GapicClientTraitDefaultScopeAndAudienceStub(); + $client->set('credentialsWrapper', $credentialsWrapper); + $client->set('agentHeader', []); + $client->set( + 'retrySettings', + ['method.name' => $retrySettings->reveal()] + ); + $client->set('transport', $transport->reveal()); + $client->call('startCall', ['method.name', 'decodeType', [ + 'apiEndpoint' => 'www.someotherendpoint.com', + ]]); + } + public function testDefaultAudienceWithOperations() { $retrySettings = $this->prophesize(RetrySettings::class);