-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c2f92
commit 254a23e
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Auth0\SDK\API\Management; | ||
|
||
use Auth0\SDK\Contract\API\Management\KeysInterface; | ||
use Auth0\SDK\Utility\Request\RequestOptions; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Handles requests to the Keys endpoint of the v2 Management API. | ||
* | ||
* @see https://auth0.com/docs/api/management/v2/keys | ||
*/ | ||
final class Keys extends ManagementEndpoint implements KeysInterface | ||
{ | ||
public function postEncryptionRekey( | ||
?RequestOptions $options = null, | ||
): ResponseInterface { | ||
return $this->getHttpClient() | ||
->method('post') | ||
->addPath(['keys', 'encryption', 'rekey']) | ||
->withOptions($options) | ||
->call(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Auth0\SDK\Contract\API\Management; | ||
|
||
use Auth0\SDK\Utility\Request\RequestOptions; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
interface KeysInterface | ||
{ | ||
/** | ||
* Perform rekeying operation on the key hierarchy. | ||
* Required scope: `create:encryption_keys`, `update:encryption_keys`. | ||
* | ||
* @param null|RequestOptions $options Optional. Additional request options to use, such as a field filtering or pagination. (Not all endpoints support these. See @see for supported options.) | ||
* | ||
* @throws \Auth0\SDK\Exception\NetworkException when the API request fails due to a network error | ||
* | ||
* @see https://auth0.com/docs/api/management/v2#!/keys/post-encryption-rekey | ||
*/ | ||
public function postEncryptionRekey( | ||
?RequestOptions $options = null, | ||
): ResponseInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Auth0\SDK\Exception\ArgumentException; | ||
use Auth0\SDK\Configuration\SdkConfiguration; | ||
use Auth0\SDK\Utility\HttpClient; | ||
use Auth0\SDK\Utility\HttpRequest; | ||
use Auth0\SDK\Utility\HttpResponse; | ||
use Auth0\Tests\Utilities\HttpResponseGenerator; | ||
use Auth0\Tests\Utilities\MockDomain; | ||
|
||
uses()->group('management', 'management.keys'); | ||
|
||
beforeEach(function(): void { | ||
$this->config = new SdkConfiguration([ | ||
'domain' => MockDomain::valid(), | ||
'cookieSecret' => uniqid(), | ||
'clientId' => uniqid(), | ||
'redirectUri' => uniqid() | ||
]); | ||
|
||
$this->client = new HttpClient($this->config, HttpClient::CONTEXT_MANAGEMENT_CLIENT); | ||
$this->endpoint = $this->api->mock()->keys(); | ||
}); | ||
|
||
test('postEncryptionRekey() issues an appropriate request', function(): void { | ||
|
||
$this->endpoint->postEncryptionRekey(); | ||
|
||
$a =$this->api->getRequestUrl(); | ||
print_r($a); | ||
expect($this->api->getRequestMethod())->toEqual('POST'); | ||
expect($this->api->getRequestUrl())->toEndWith('/api/v2/keys/encryption/rekey'); | ||
|
||
$headers = $this->api->getRequestHeaders(); | ||
expect($headers['Content-Type'][0])->toEqual('application/json'); | ||
}); | ||
|
||
test('postEncryptionRekey() returns 204 on success', function(): void { | ||
|
||
// Mock the API response for successful rekey with status 204 | ||
$this->httpResponse204 = HttpResponseGenerator::create('success', 204); | ||
|
||
// Mock the client to return the mocked 204 response | ||
$this->client->mockResponse($this->httpResponse204); | ||
$response = $this->client->method('post') | ||
->addPath(['keys', 'encryption', 'rekey']) | ||
->call(); | ||
expect($response->getStatusCode())->toEqual(204); | ||
}); |