-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscribe to correct LoginEvent name #507
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b924747
Subscribe to correct LoginEvent name
doobry-systemli 9914c19
Remove `serverVersion` variable from default doctrine database URL
doobry-systemli 3999816
Fix class name in comment of `RecoveryProcessEvent`
doobry-systemli 5ec5978
Let `UsersregistrationMailCommand->execute()` return an integer
doobry-systemli 618e974
Test that LoginListener is triggered by UsersCheckPasswordCommand
doobry-systemli ce1d943
Update changelog
doobry-systemli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,5 +50,5 @@ MAILER_DELIVERY_ADDRESS="[email protected]" | |
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db" | ||
# DATABASE_URL="mysql://app:[email protected]:3306/app?serverVersion=8&charset=utf8mb4" | ||
# DATABASE_URL="postgresql://app:[email protected]:5432/app?serverVersion=14&charset=utf8" | ||
DATABASE_URL="mysql://mail:[email protected]:3306/mail?serverVersion=mariadb-10.3.23&charset=utf8mb4" | ||
DATABASE_URL="mysql://mail:[email protected]:3306/mail?charset=utf8mb4" | ||
###< doctrine/doctrine-bundle ### |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
use App\Command\UsersCheckPasswordCommand; | ||
use App\Entity\User; | ||
use App\Enum\Roles; | ||
use App\Event\LoginEvent; | ||
use App\EventListener\LoginListener; | ||
use App\Handler\MailCryptKeyHandler; | ||
use App\Handler\UserAuthenticationHandler; | ||
use App\Helper\FileDescriptorReader; | ||
|
@@ -13,6 +15,10 @@ | |
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Console\Exception\InvalidArgumentException; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
use Symfony\Component\EventDispatcher\EventDispatcher; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface; | ||
use Symfony\Component\PasswordHasher\PasswordHasherInterface; | ||
|
||
class UsersCheckPasswordCommandTest extends TestCase | ||
{ | ||
|
@@ -21,16 +27,21 @@ class UsersCheckPasswordCommandTest extends TestCase | |
protected $quotaUser; | ||
protected $mailCryptUser; | ||
protected $spamUser; | ||
protected $loginListener; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->plainUser = new User(); | ||
$this->plainUser->setPassword('passwordhash'); | ||
$this->quotaUser = new User(); | ||
$this->quotaUser->setPassword('passwordhash'); | ||
$this->quotaUser->setQuota(1024); | ||
$this->mailCryptUser = new User(); | ||
$this->mailCryptUser->setPassword('passwordhash'); | ||
$this->mailCryptUser->setMailCrypt(true); | ||
$this->mailCryptUser->setMailCryptPublicKey('somePublicKey'); | ||
$this->spamUser = new User(); | ||
$this->spamUser->setPassword('passwordhash'); | ||
$this->spamUser->setRoles([Roles::SPAM]); | ||
} | ||
|
||
|
@@ -92,6 +103,35 @@ public function testExecuteFd3($inputStream, $returnCode): void | |
$this->assertEquals($returnCode, $commandTester->getStatusCode()); | ||
} | ||
|
||
public function testExecuteCallsLoginListener(): void | ||
{ | ||
$inputStream = "[email protected]\x00password"; | ||
$returnCode = 0; | ||
|
||
$manager = $this->getManager(); | ||
$reader = $this->getReaderFd3($inputStream); | ||
$handler = $this->getHandler(); | ||
$mailCryptKeyHandler = $this->getMailCryptKeyHandler(); | ||
$mailCrypt = 2; | ||
$mailUID = 5000; | ||
$mailGID = 5000; | ||
$mailLocation = 'var/vmail'; | ||
|
||
$command = new UsersCheckPasswordCommand($manager, | ||
$reader, | ||
$handler, | ||
$mailCryptKeyHandler, | ||
$mailCrypt, | ||
$mailUID, | ||
$mailGID, | ||
$mailLocation); | ||
$commandTester = new CommandTester($command); | ||
|
||
$this->loginListener->expects(self::once())->method('onLogin'); | ||
$commandTester->execute([]); | ||
self::assertEquals($returnCode, $commandTester->getStatusCode()); | ||
} | ||
|
||
/** | ||
* @dataProvider validContentProvider | ||
*/ | ||
|
@@ -239,19 +279,21 @@ public function getManager(): EntityManagerInterface | |
|
||
public function getHandler(): UserAuthenticationHandler | ||
{ | ||
$handler = $this->getMockBuilder(UserAuthenticationHandler::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$handler->method('authenticate')->willReturnMap( | ||
$passwordHasher = $this->createMock(PasswordHasherInterface::class); | ||
$passwordHasher->method('verify')->willReturnMap( | ||
[ | ||
[$this->plainUser, 'password', $this->plainUser], | ||
[$this->quotaUser, 'password', $this->quotaUser], | ||
[$this->mailCryptUser, 'password', $this->mailCryptUser], | ||
[$this->spamUser, 'password', $this->spamUser], | ||
['passwordhash', 'password', true], | ||
['passwordhash', 'wrongpassword', false], | ||
['passwordhash', '', false], | ||
] | ||
); | ||
$passwordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class); | ||
$passwordHasherFactory->method('getPasswordHasher')->willReturn($passwordHasher); | ||
|
||
return $handler; | ||
$this->loginListener = $this->createMock(LoginListener::class); | ||
$eventDispatcher = new EventDispatcher(); | ||
$eventDispatcher->addListener(LoginEvent::NAME, [$this->loginListener, 'onLogin']); | ||
return new UserAuthenticationHandler($passwordHasherFactory, $eventDispatcher); | ||
} | ||
|
||
public function getMailCryptKeyHandler(): MailCryptKeyHandler | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any assertation here. It would be good to assert that the command returns successfully and the mocked services were called as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the code logic now so that
$this->loginListener->expects(self::once())->method('onLogin')
is in the test function itself. Probably it's easier to follow the logic of the test that way.I also added an assertion to make sure the
execute()
call succeeded, but that's not what we want to test here. We want to test whetherLoginListener->onLogin()
got triggered.