Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
[WEB-10582] Add and update token refresh tests to handle toggling bet…
Browse files Browse the repository at this point in the history
…ween versions
  • Loading branch information
AnnieCSerato committed Nov 27, 2024
1 parent 5ba8aee commit 2773a09
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion tests/Identity/Command/TokenExchangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,52 @@ public function testSmokeTest(): void
$request = $command->getRequest();
parse_str((string)$request->getBody(), $bodyParams);
$this->assertEquals('POST', $request->getMethod());
$this->assertRegExp('/^\/api\/v1\/tokens\/exchange$/', $request->getUri()->getPath());
$this->assertRegExp('/^\/api\/v2\/tokens\/exchange$/', $request->getUri()->getPath());
$this->assertRegExp('/^Basic [[:alnum:]=]+$/', $request->getHeaderLine('Authorization'));
$this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
$this->assertEquals($grantType, $bodyParams['grant_type']);
$this->assertEquals($code, $bodyParams['code']);
$this->assertEquals($redirectUri, $bodyParams['redirect_uri']);
}

/**
* @param bool $useRotation
* @param string $expectedUrlRegex
* @return void
* @dataProvider useTokenRotationProvider
*/
public function testUseTokenRotationTest($useRotation, $expectedUrlRegex): void
{
$grantType = 'my_grant_type';
$code = '123abc456';
$redirectUri = 'myuri';

$command = new TokenExchange(
'app_id',
'app_password',
'http://my.server.com',
['grant_type' => $grantType, 'code' => $code, 'redirect_uri' => $redirectUri, 'use_rotation' => $useRotation]
);

$request = $command->getRequest();
parse_str((string)$request->getBody(), $bodyParams);
$this->assertEquals('POST', $request->getMethod());
$this->assertRegExp($expectedUrlRegex, $request->getUri()->getPath());
$this->assertRegExp('/^Basic [[:alnum:]=]+$/', $request->getHeaderLine('Authorization'));
$this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
$this->assertEquals($grantType, $bodyParams['grant_type']);
$this->assertEquals($code, $bodyParams['code']);
$this->assertEquals($redirectUri, $bodyParams['redirect_uri']);
}

/**
* @return array<array<mixed>>
*/
public function useTokenRotationProvider(): array
{
return [
['useRotation' => false, 'expectedUrlRegex' => '/^\/api\/v1\/tokens\/exchange$/' ],
['useRotation' => true, 'expectedUrlRegex' => '/^\/api\/v2\/tokens\/exchange$/' ],
];
}
}

0 comments on commit 2773a09

Please sign in to comment.