Skip to content

Commit

Permalink
fix: check for empty parameters in register confirm request
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzKrafeld committed Jan 7, 2025
1 parent a1008d7 commit e346258
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/Registration/RegistrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ public function registerConfirm(RequestInterface $request): ResponseInterface
/** @var array<string, mixed> $requestContent */
$requestContent = \json_decode($request->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR);

if (!isset($requestContent['shopId'], $requestContent['apiKey']) || !is_string($requestContent['shopId']) || !is_string($requestContent['apiKey']) || !isset($requestContent['secretKey']) || !is_string($requestContent['secretKey'])) {
if (
empty($requestContent['shopId']) ||
empty($requestContent['apiKey']) ||
empty($requestContent['secretKey']) ||
!is_string($requestContent['shopId']) ||
!is_string($requestContent['apiKey']) ||
!is_string($requestContent['secretKey'])
) {
throw new MissingShopParameterException();
}

Expand Down
35 changes: 28 additions & 7 deletions tests/Registration/RegistrationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function testBodyRewindIsCalled(): void
}

/**
* @dataProvider missingShopParametersProvider
* @dataProvider missingRegisterShopParametersProvider
* @param array<string, mixed> $params
*/
public function testRegisterMissingShopParameters(array $params): void
Expand Down Expand Up @@ -445,7 +445,7 @@ public function testRegisterMissingShopParameters(array $params): void
}

/**
* @dataProvider missingShopParametersProvider
* @dataProvider missingRegisterConfirmShopParametersProvider
* @param array<string, mixed> $params
*/
public function testRegisterConfirmMissingShopParameters(array $params): void
Expand Down Expand Up @@ -484,24 +484,45 @@ public function testRegisterShopUrlIsSanitized(
/**
* @return iterable<array<array<string, mixed>>>
*/
public static function missingShopParametersProvider(): iterable
public static function missingRegisterShopParametersProvider(): iterable
{
yield [[]];
yield [['shop-id' => null]];
yield [['shop-id' => 123]];
yield [['shop-url' => null]];
yield [['shop-url' => 'https://my-shop.com']];
yield [['shop-id' => 123, 'shop-url' => null]];
yield [['shop-id' => '123', 'shop-url' => 'https://my-shop.com', 'apiKey' => null]];
yield [['shop-id' => '123', 'shop-url' => 'https://my-shop.com', 'apiKey' => 123]];
yield [['shop-id' => '123', 'shop-url' => 'https://my-shop.com', 'secretKey' => null]];
yield [['shop-id' => '123', 'shop-url' => 'https://my-shop.com', 'secretKey' => 123]];
}

/**
* @return iterable<array<array<string, mixed>>>
*/
public static function missingRegisterConfirmShopParametersProvider(): iterable
{
yield [[]];
yield [['shopId' => null]];
yield [['shopId' => 123]];
yield [['shop-url' => null]];
yield [['shop-url' => 'https://my-shop.com']];
yield [['shopId' => 123, 'shop-url' => null]];
yield [['shopId' => '123', 'shop-url' => 'https://my-shop.com', 'apiKey' => null]];
yield [['shopId' => '123', 'shop-url' => 'https://my-shop.com', 'apiKey' => 123]];
yield [['shopId' => '123', 'shop-url' => 'https://my-shop.com', 'secretKey' => null]];
yield [['shopId' => '123', 'shop-url' => 'https://my-shop.com', 'secretKey' => 123]];
yield [['apiKey' => 123]];
yield [['apiKey' => null]];
yield [['apiKey' => '123', 'secretKey' => null]];
yield [['apiKey' => '123', 'secretKey' => 123]];
yield [['shop-id' => '123', 'apiKey' => '123']];
yield [['shop-id' => '123', 'apiKey' => '123', 'secretKey' => 123]];
yield [['shop-id' => '', 'apiKey' => '', 'secretKey' => '']];
yield [['shop-id' => '', 'apiKey' => '', 'secretKey' => '123']];
yield [['shop-id' => '', 'apiKey' => '', 'secretKey' => '']];
yield [['shop-id' => '', 'apiKey' => '123', 'secretKey' => '']];
yield [['shop-id' => '', 'apiKey' => '123', 'secretKey' => '123']];
yield [['shop-id' => '123', 'apiKey' => '', 'secretKey' => '']];
yield [['shop-id' => '123', 'apiKey' => '', 'secretKey' => '123']];
yield [['shop-id' => '123', 'apiKey' => '123', 'secretKey' => '']];
}

/**
Expand Down

0 comments on commit e346258

Please sign in to comment.