Skip to content

Commit

Permalink
fix: make sure hmac generation works with requests that use string re…
Browse files Browse the repository at this point in the history
…sourcetypes
  • Loading branch information
kauffinger committed Nov 6, 2024
1 parent 69bd638 commit f043e5b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Services/OnOfficeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function retryOnlyOnConnectionError(): bool
*
* Read more: https://apidoc.onoffice.de/onoffice-api-request/request-elemente/action/#hmac
*/
public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType $resourceType): string
public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType|string $resourceType): string
{
return base64_encode(
hash_hmac(
Expand All @@ -101,7 +101,9 @@ public function getHmac(OnOfficeAction $actionId, OnOfficeResourceType $resource
[
'timestamp' => Carbon::now()->timestamp,
'token' => $this->getToken(),
'resourcetype' => $resourceType->value,
'resourcetype' => $resourceType instanceof OnOfficeResourceType
? $resourceType->value
: $resourceType,
'actionid' => $actionId->value,
]
),
Expand Down
19 changes: 19 additions & 0 deletions tests/Repositories/BaseRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@

Http::assertSentCount(1);
});

it('will call with string as resource type', function (){
Http::preventStrayRequests();
Http::fake([
'https://api.onoffice.de/api/stable/api.php/' => Http::response([
'status' => [
'code' => 200,
],
]),
]);

$builder = new BaseRepository;

$request = new OnOfficeRequest(OnOfficeAction::Read, 'estate');

$builder->query()->call($request);

Http::assertSentCount(1);
});
});

describe('middlewares', function () {
Expand Down
24 changes: 24 additions & 0 deletions tests/Services/OnOfficeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,30 @@
expect($response)->toBeInstanceOf(Collection::class)
->toHaveCount(1);
});

it('can handle string resource type', function (){
Http::preventStrayRequests();
Http::fake([
'*' => Http::response([
'status' => [
'code' => 200,
],
]),
]);

$onOfficeService = app(OnOfficeService::class);

$request = new OnOfficeRequest(
OnOfficeAction::Get,
'estate',
);

$onOfficeService->requestAll(function () use ($request) {
return app(OnOfficeService::class)->requestApi($request);
}, limit: 1);

Http::assertSentCount(1);
});
});

describe('requestAllChunked', function () {
Expand Down

0 comments on commit f043e5b

Please sign in to comment.