Skip to content

Commit e807e4a

Browse files
committed
fix: make context commands key protected
1 parent 3cdd8c3 commit e807e4a

15 files changed

+112
-23
lines changed

src/Gateway/Context/ContextGatewayCommand.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ abstract class ContextGatewayCommand implements \JsonSerializable
1111
*/
1212
public array $payload = [];
1313

14-
public string $keyName;
14+
protected string $keyName;
15+
16+
public function getKey(): string
17+
{
18+
return $this->keyName;
19+
}
1520

1621
public function setPayloadValue(string $key, mixed $value): void
1722
{

src/Registration/RegistrationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Shopware\App\SDK\Event\RegistrationCompletedEvent;
2020
use Shopware\App\SDK\Exception\MissingShopParameterException;
2121
use Shopware\App\SDK\Exception\ShopNotFoundException;
22-
use Shopware\App\SDK\Exception\SignatureNotFoundException;
2322
use Shopware\App\SDK\Exception\SignatureInvalidException;
23+
use Shopware\App\SDK\Exception\SignatureNotFoundException;
2424
use Shopware\App\SDK\Shop\ShopInterface;
2525
use Shopware\App\SDK\Shop\ShopRepositoryInterface;
2626

tests/Context/ContextResolverTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,61 @@ public function testAssembleContextGatewayRequest(): void
11771177
static::assertSame(['foo' => 'bar'], $action->data);
11781178
}
11791179

1180+
public function testAssembleContextGatewayWithInvalidData(): void
1181+
{
1182+
$contextResolver = new ContextResolver($this->createMock(InAppPurchaseProvider::class));
1183+
1184+
$body = [
1185+
'source' => [
1186+
'url' => 'https://example.com',
1187+
'appVersion' => 'foo',
1188+
'inAppPurchases' => 'ey',
1189+
],
1190+
'cart' => [
1191+
'token' => 'cart-token',
1192+
],
1193+
'salesChannelContext' => [
1194+
'salesChannel' => [
1195+
'id' => 'sales-channel-id'
1196+
],
1197+
],
1198+
'data' => 'foo',
1199+
];
1200+
1201+
$request = new Request('POST', '/', [], json_encode($body, JSON_THROW_ON_ERROR));
1202+
1203+
static::expectException(MalformedWebhookBodyException::class);
1204+
1205+
$contextResolver->assembleContextGatewayRequest($request, $this->getShop());
1206+
}
1207+
1208+
public function testAssembleContextGatewayWithMissingData(): void
1209+
{
1210+
$contextResolver = new ContextResolver($this->createMock(InAppPurchaseProvider::class));
1211+
1212+
$body = [
1213+
'source' => [
1214+
'url' => 'https://example.com',
1215+
'appVersion' => 'foo',
1216+
'inAppPurchases' => 'ey',
1217+
],
1218+
'cart' => [
1219+
'token' => 'cart-token',
1220+
],
1221+
'salesChannelContext' => [
1222+
'salesChannel' => [
1223+
'id' => 'sales-channel-id'
1224+
],
1225+
],
1226+
];
1227+
1228+
$request = new Request('POST', '/', [], json_encode($body, JSON_THROW_ON_ERROR));
1229+
1230+
static::expectException(MalformedWebhookBodyException::class);
1231+
1232+
$contextResolver->assembleContextGatewayRequest($request, $this->getShop());
1233+
}
1234+
11801235
public function testAssembleInAppPurchasesFilterRequest(): void
11811236
{
11821237
$expectedPurchases = new Collection(['identifier-1', 'identifier-2', 'identifier-3']);

tests/Gateway/Context/Command/AddCustomerMessageCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('foo', $command->message);
1919
static::assertSame('foo', $command->getPayloadValue('message'));
20-
static::assertSame('context_add-customer-message', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangeBillingAddressCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('foo', $command->addressId);
1919
static::assertSame('foo', $command->getPayloadValue('addressId'));
20-
static::assertSame('context_change-billing-address', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangeCurrencyCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('EUR', $command->iso);
1919
static::assertSame('EUR', $command->getPayloadValue('iso'));
20-
static::assertSame('context_change-currency', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangeLanguageCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('de-DE', $command->iso);
1919
static::assertSame('de-DE', $command->getPayloadValue('iso'));
20-
static::assertSame('context_change-language', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangePaymentMethodCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('payment_technical-name', $command->technicalName);
1919
static::assertSame('payment_technical-name', $command->getPayloadValue('technicalName'));
20-
static::assertSame('context_change-payment-method', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangeShippingAddressCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testConstruct(): void
1717

1818
static::assertSame('foo', $command->addressId);
1919
static::assertSame('foo', $command->getPayloadValue('addressId'));
20-
static::assertSame('context_change-shipping-address', $command->keyName);
2120
}
2221

2322
public function testKey(): void

tests/Gateway/Context/Command/ChangeShippingLocationCommandTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function testConstruct(): void
1919
static::assertSame('DE-BY', $command->countryStateIso);
2020
static::assertSame('DE', $command->getPayloadValue('countryIso'));
2121
static::assertSame('DE-BY', $command->getPayloadValue('countryStateIso'));
22-
static::assertSame('context_change-shipping-location', $command->keyName);
2322
}
2423

2524
public function testConstructDefaults(): void
@@ -30,7 +29,6 @@ public function testConstructDefaults(): void
3029
static::assertSame(null, $command->countryStateIso);
3130
static::assertFalse($command->hasPayloadValue('countryIso'));
3231
static::assertFalse($command->hasPayloadValue('countryStateIso'));
33-
static::assertSame('context_change-shipping-location', $command->keyName);
3432
}
3533

3634
public function testKey(): void

0 commit comments

Comments
 (0)