-
Notifications
You must be signed in to change notification settings - Fork 1
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 #387 from silinternational/feature/IDP-1266-part-2…
…-rate-limit-both-non-user-emails [IDP-1266, part 2] Rate limit both non user emails, add EmailLog validation
- Loading branch information
Showing
4 changed files
with
197 additions
and
22 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
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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
use common\models\MfaBackupcode; | ||
use common\models\MfaWebauthn; | ||
use common\models\User; | ||
use Sil\SilIdBroker\Behat\Context\YiiContext; | ||
use Webmozart\Assert\Assert; | ||
|
||
class EmailContext extends YiiContext | ||
|
@@ -59,6 +58,10 @@ class EmailContext extends YiiContext | |
/** @var array<array> */ | ||
protected $matchingFakeEmails; | ||
|
||
private string $dummyExtGroupsAppPrefix = 'ext-dummy'; | ||
|
||
private ?EmailLog $tempEmailLog; | ||
|
||
public const METHOD_EMAIL_ADDRESS = '[email protected]'; | ||
public const MANAGER_EMAIL = '[email protected]'; | ||
|
||
|
@@ -1243,7 +1246,7 @@ public function theUserHasNotLoggedInFor($months) | |
} | ||
|
||
/** | ||
* @When I send abandoned user email | ||
* @When I send abandoned user email (again) | ||
*/ | ||
public function iSendAbandonedUserEmail() | ||
{ | ||
|
@@ -1292,4 +1295,76 @@ public function theDatabaseHasBeenPurged() | |
User::deleteAll(); | ||
$this->fakeEmailer->forgetFakeEmailsSent(); | ||
} | ||
|
||
/** | ||
* @Then the abandoned user email has been sent :expectedCount time(s) | ||
*/ | ||
public function theAbandonedUserEmailHasBeenSentTime($expectedCount) | ||
{ | ||
$actualCount = $this->countEmailsSent(EmailLog::MESSAGE_TYPE_ABANDONED_USERS); | ||
Assert::eq($actualCount, $expectedCount); | ||
} | ||
|
||
/** | ||
* @Given I send an external-groups sync-error email (again) | ||
*/ | ||
public function iSendAnExternalGroupsSyncErrorEmail() | ||
{ | ||
$this->fakeEmailer->sendExternalGroupSyncErrorsEmail( | ||
$this->dummyExtGroupsAppPrefix, | ||
['dummy error'], | ||
'[email protected]', | ||
'' | ||
); | ||
} | ||
|
||
/** | ||
* @Then the external-groups sync-error email has been sent :expectedCount time(s) | ||
*/ | ||
public function theExternalGroupsSyncErrorEmailHasBeenSentTime($expectedCount) | ||
{ | ||
// The $appPrefix is needed by the FakeEmailer, to find the appropriate | ||
// emails (by being able to accurately generate the expected subject). | ||
$this->fakeEmailer->otherDataForEmails['appPrefix'] = $this->dummyExtGroupsAppPrefix; | ||
|
||
$actualCount = $this->countEmailsSent( | ||
EmailLog::MESSAGE_TYPE_EXT_GROUP_SYNC_ERRORS | ||
); | ||
Assert::eq($actualCount, $expectedCount); | ||
} | ||
|
||
/** | ||
* @When I try to log an email as sent to that User and to a non-user address | ||
*/ | ||
public function iTryToLogAnEmailAsSentToThatUserAndToANonUserAddress() | ||
{ | ||
$this->tempEmailLog = new EmailLog([ | ||
'message_type' => EmailLog::MESSAGE_TYPE_ABANDONED_USERS, | ||
'non_user_address' => '[email protected]', | ||
'user_id' => $this->tempUser->id, | ||
]); | ||
$this->tempEmailLog->save(); | ||
} | ||
|
||
/** | ||
* @Then an email log validation error should have occurred | ||
*/ | ||
public function anEmailLogValidationErrorShouldHaveOccurred() | ||
{ | ||
Assert::notEmpty( | ||
$this->tempEmailLog->errors, | ||
'No EmailLog validation errors were found' | ||
); | ||
} | ||
|
||
/** | ||
* @When I try to log an email as sent to neither a User nor a non-user address | ||
*/ | ||
public function iTryToLogAnEmailAsSentToNeitherAUserNorANonUserAddress() | ||
{ | ||
$this->tempEmailLog = new EmailLog([ | ||
'message_type' => EmailLog::MESSAGE_TYPE_ABANDONED_USERS, | ||
]); | ||
$this->tempEmailLog->save(); | ||
} | ||
} |
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