Skip to content

Commit 559809a

Browse files
committed
Assert request made with trusted publishing has proper signature after token exchange
1 parent d406bca commit 559809a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tests/HttpClient/Plugin/TrustedPublishingTokenExchangeTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use GuzzleHttp\Psr7\Request;
1313
use GuzzleHttp\Psr7\Response;
1414
use Http\Mock\Client;
15+
use Http\Promise\FulfilledPromise;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PrivatePackagist\ApiClient\HttpClient\HttpPluginClientBuilder;
1718
use PrivatePackagist\OIDC\Identities\Token;
@@ -51,16 +52,18 @@ public function testTokenExchange(): void
5152
$this->httpClient->addResponse(new Response(200, [], json_encode(['audience' => 'test'])));
5253
$this->httpClient->addResponse(new Response(200, [], json_encode(['key' => 'key', 'secret' => 'secret'])));
5354

54-
$this->plugin->handleRequest($request, $this->next, $this->first);
55+
$this->plugin->handleRequest($request, function (Request $request) use (&$requestAfterPlugin) {
56+
$requestAfterPlugin = $request;
57+
58+
return new FulfilledPromise($request);
59+
}, $this->first);
5560

5661
$requests = $this->httpClient->getRequests();
5762
$this->assertCount(2, $requests);
5863
$this->assertSame('/oidc/audience', (string) $requests[0]->getUri());
5964
$this->assertSame('/oidc/token-exchange/organization/acme/package', (string) $requests[1]->getUri());
60-
61-
// Verify that the signature is configured using the correct key
62-
$this->builder->getHttpClient()->get('/api/foo');
63-
$this->assertStringContainsString('PACKAGIST-HMAC-SHA256 Key=key', $requests[2]->getHeader('Authorization')[0]);
65+
66+
$this->assertStringContainsString('PACKAGIST-HMAC-SHA256 Key=key', $requestAfterPlugin->getHeader('Authorization')[0]);
6467
}
6568

6669
public function testNoTokenGenerated(): void

0 commit comments

Comments
 (0)