Skip to content

Commit f84b45a

Browse files
author
Anna Bukatar
committed
ACP2E-1513: Customer suspects IDOR vulnerability
1 parent c129815 commit f84b45a

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Customer/RemoveItemFromCartTest.php

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Quote\Customer;
99

10+
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1011
use Magento\GraphQl\Quote\GetMaskedQuoteIdByReservedOrderId;
1112
use Magento\GraphQl\Quote\GetQuoteItemIdByReservedQuoteIdAndSku;
1213
use Magento\Integration\Api\CustomerTokenServiceInterface;
@@ -147,13 +148,56 @@ public function testRemoveItemFromAnotherCustomerCart()
147148
'test_quote',
148149
'simple_product'
149150
);
151+
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
150152

151-
$this->expectExceptionMessage(
152-
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\""
153-
);
153+
try {
154+
$this->graphQlMutation(
155+
$query,
156+
[],
157+
'',
158+
$this->getHeaderMap('customer2@search.example.com')
159+
);
160+
$this->fail('ResponseContainsErrorsException was not thrown');
161+
} catch (ResponseContainsErrorsException $e) {
162+
$this->assertStringContainsString(
163+
"The current user cannot perform operations on cart \"$anotherCustomerQuoteMaskedId\"",
164+
$e->getMessage()
165+
);
166+
$cartQuery = $this->getCartQuery($anotherCustomerQuoteMaskedId);
167+
$cart = $this->graphQlQuery(
168+
$cartQuery,
169+
[],
170+
'',
171+
$this->getHeaderMap('customer@search.example.com')
172+
);
173+
$this->assertTrue(count($cart['cart']['items']) > 0, 'The cart is empty');
174+
$this->assertTrue(
175+
$cart['cart']['items'][0]['product']['sku'] === 'simple_product',
176+
'The cart doesn\'t contain product'
177+
);
178+
}
179+
}
154180

155-
$query = $this->getQuery($anotherCustomerQuoteMaskedId, $anotherCustomerQuoteItemId);
156-
$this->graphQlMutation($query, [], '', $this->getHeaderMap('customer2@search.example.com'));
181+
/**
182+
* @param string $maskedQuoteId
183+
* @return string
184+
*/
185+
private function getCartQuery(string $maskedQuoteId): string
186+
{
187+
return <<<QUERY
188+
{
189+
cart(cart_id: "{$maskedQuoteId}") {
190+
id
191+
items {
192+
id
193+
quantity
194+
product {
195+
sku
196+
}
197+
}
198+
}
199+
}
200+
QUERY;
157201
}
158202

159203
/**

0 commit comments

Comments
 (0)