diff --git a/src/API/Management.php b/src/API/Management.php index 5f842d4e..1e3c5f79 100644 --- a/src/API/Management.php +++ b/src/API/Management.php @@ -4,9 +4,9 @@ namespace Auth0\SDK\API; -use Auth0\SDK\API\Management\{Actions, AttackProtection, Blacklists, ClientGrants, Clients, Connections, DeviceCredentials, EmailTemplates, Emails, Grants, Guardian, Jobs, LogStreams, Logs, Organizations, ResourceServers, Roles, Rules, Stats, Tenants, Tickets, UserBlocks, Users, UsersByEmail}; +use Auth0\SDK\API\Management\{Actions, AttackProtection, Blacklists, ClientGrants, Clients, Connections, DeviceCredentials, EmailTemplates, Emails, Grants, Guardian, Jobs, Keys, LogStreams, Logs, Organizations, ResourceServers, Roles, Rules, Stats, Tenants, Tickets, UserBlocks, Users, UsersByEmail}; use Auth0\SDK\Configuration\SdkConfiguration; -use Auth0\SDK\Contract\API\Management\{ActionsInterface, AttackProtectionInterface, BlacklistsInterface, ClientGrantsInterface, ClientsInterface, ConnectionsInterface, DeviceCredentialsInterface, EmailTemplatesInterface, EmailsInterface, GrantsInterface, GuardianInterface, JobsInterface, LogStreamsInterface, LogsInterface, OrganizationsInterface, ResourceServersInterface, RolesInterface, RulesInterface, StatsInterface, TenantsInterface, TicketsInterface, UserBlocksInterface, UsersByEmailInterface, UsersInterface}; +use Auth0\SDK\Contract\API\Management\{ActionsInterface, AttackProtectionInterface, BlacklistsInterface, ClientGrantsInterface, ClientsInterface, ConnectionsInterface, DeviceCredentialsInterface, EmailTemplatesInterface, EmailsInterface, GrantsInterface, GuardianInterface, JobsInterface, KeysInterface, LogStreamsInterface, LogsInterface, OrganizationsInterface, ResourceServersInterface, RolesInterface, RulesInterface, StatsInterface, TenantsInterface, TicketsInterface, UserBlocksInterface, UsersByEmailInterface, UsersInterface}; use Auth0\SDK\Contract\API\{AuthenticationInterface, ManagementInterface}; use Auth0\SDK\Utility\{HttpClient, HttpResponse, HttpResponsePaginator}; use Psr\Cache\CacheItemPoolInterface; @@ -182,6 +182,11 @@ public function jobs(): JobsInterface return Jobs::instance($this->getHttpClient()); } + public function keys(): KeysInterface + { + return Keys::instance($this->getHttpClient()); + } + public function logs(): LogsInterface { return Logs::instance($this->getHttpClient()); diff --git a/src/API/Management/Keys.php b/src/API/Management/Keys.php new file mode 100644 index 00000000..2a9f9a01 --- /dev/null +++ b/src/API/Management/Keys.php @@ -0,0 +1,27 @@ +getHttpClient() + ->method('post') + ->addPath(['keys', 'encryption', 'rekey']) + ->withOptions($options) + ->call(); + } +} diff --git a/src/Contract/API/Management/KeysInterface.php b/src/Contract/API/Management/KeysInterface.php new file mode 100644 index 00000000..9727887d --- /dev/null +++ b/src/Contract/API/Management/KeysInterface.php @@ -0,0 +1,25 @@ +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(); + + 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 { + + // Mocked the API response for successful rekey with status 204 + $this->httpResponse204 = HttpResponseGenerator::create('success', 204); + + // Mocked 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); +});