Skip to content

Commit

Permalink
chore: remove unnecessary api endpoint check (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer authored May 23, 2023
1 parent 4f10140 commit 7a867a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
9 changes: 0 additions & 9 deletions src/GapicClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
40 changes: 30 additions & 10 deletions tests/Tests/Unit/GapicClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']],
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7a867a5

Please sign in to comment.