-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from BitBagCommerce/VSF2-54-password-reminder-…
…token-fix Vsf2 54 password reminder token fix
- Loading branch information
Showing
17 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@resetting_password | ||
Feature: Resetting one customer password | ||
In order to reset my password | ||
As a Customer | ||
I need to be able to reset it by reset query | ||
|
||
|
||
Background: | ||
Given the store operates on a single channel in "United States" | ||
And the store has locale "en_US" | ||
And there is a customer account "[email protected]" | ||
|
||
@graphql | ||
Scenario: Setting token for password reset | ||
Given I prepare password reset request operation for user "[email protected]" | ||
And I send that GraphQL request | ||
Then I should receive a JSON response | ||
And This response should contain pattern '/^\{"data":\{"shop_send_reset_password_emailCustomer":\{"customer":\{"id":"\/api\/v2\/shop\/customers\/(\d+)"\}\}\}\}$/' | ||
And user "[email protected]" should have reset password token set | ||
|
||
@graphql | ||
Scenario: Checking for valid reset password token availability | ||
Given I prepare password reset request operation for user "[email protected]" | ||
And I send that GraphQL request | ||
And I prepare check reset password token operation for user's "[email protected]" token | ||
And I send that GraphQL request | ||
Then I should receive a JSON response | ||
And This response should contain pattern '/^\{"data":\{"password_reset_tokenUser":\{"username":"([^"]+)"\}\}\}$/' | ||
|
||
@graphql | ||
Scenario: Checking for invalid reset password token availability | ||
Given I prepare password reset request operation for user "[email protected]" | ||
And I send that GraphQL request | ||
And I prepare check reset password token operation for invalid token | ||
And I send that GraphQL request | ||
Then I should receive a JSON response | ||
And This response should contain pattern '/"data":\{"password_reset_tokenUser":null\}/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace spec\BitBag\SyliusVueStorefront2Plugin\Resolver\Query; | ||
|
||
use BitBag\SyliusVueStorefront2Plugin\Resolver\Query\PasswordResetTokenResolver; | ||
use PhpSpec\ObjectBehavior; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\Component\User\Repository\UserRepositoryInterface; | ||
|
||
class PasswordResetTokenResolverSpec extends ObjectBehavior | ||
{ | ||
public function let( | ||
UserRepositoryInterface $userRepository | ||
): void { | ||
$this->beConstructedWith( | ||
$userRepository | ||
); | ||
} | ||
|
||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(PasswordResetTokenResolver::class); | ||
} | ||
|
||
public function it_returns_user_on_valid_token( | ||
UserRepositoryInterface $userRepository, | ||
ShopUserInterface $user | ||
): void { | ||
$context = [ | ||
'args' => [ | ||
'passwordResetToken' => "TOKEN", | ||
], | ||
]; | ||
|
||
$token = $context['args']['passwordResetToken']; | ||
|
||
$userRepository->findOneBy(['passwordResetToken' => $token])->willReturn($user); | ||
|
||
$this->__invoke(null, $context)->shouldReturn($user); | ||
} | ||
|
||
public function it_should_return_null_on_invalid_token( | ||
UserRepositoryInterface $userRepository, | ||
): void { | ||
$context = [ | ||
'args' => [ | ||
'passwordResetToken' => "TOKEN", | ||
], | ||
]; | ||
|
||
$token = $context['args']['passwordResetToken']; | ||
|
||
$userRepository->findOneBy(['passwordResetToken' => $token])->willReturn(null); | ||
|
||
$this->shouldThrow(\RuntimeException::class) | ||
->during('__invoke', [null, $context]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* You can find more information about us on https://bitbag.io and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusVueStorefront2Plugin\Resolver\Query; | ||
|
||
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface; | ||
use Sylius\Component\Core\Model\ShopUserInterface; | ||
use Sylius\Component\User\Repository\UserRepositoryInterface; | ||
|
||
class PasswordResetTokenResolver implements QueryItemResolverInterface | ||
{ | ||
private UserRepositoryInterface $userRepository; | ||
|
||
public function __construct(UserRepositoryInterface $userRepository) | ||
{ | ||
$this->userRepository = $userRepository; | ||
} | ||
|
||
public function __invoke($item, array $context): ShopUserInterface | ||
{ | ||
$token = $context['args']['passwordResetToken']; | ||
/** @var ?ShopUserInterface $user */ | ||
$user = $this->userRepository->findOneBy(['passwordResetToken' => $token]); | ||
|
||
if (null !== $user) { | ||
return $user; | ||
} | ||
|
||
throw new \RuntimeException('Token not found'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/Behat/Resources/suites/account/resetting_password.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
default: | ||
suites: | ||
graphql_resetting_password: | ||
contexts: | ||
- sylius.behat.context.setup.locale | ||
- sylius.behat.context.setup.customer | ||
- bitbag.sylius_vue_storefront2_plugin.context.graphql | ||
- bitbag.sylius_vue_storefront2_plugin.context.customer | ||
- sylius.behat.context.setup.channel | ||
filters: | ||
tags: "@resetting_password&&@graphql" |