Added test for unsubscribe plus other recipient
This commit is contained in:
parent
4f2d380819
commit
52b61a0db6
3 changed files with 84 additions and 3 deletions
|
@ -71,8 +71,10 @@ class ReceiveEmail extends Command
|
|||
];
|
||||
});
|
||||
|
||||
// Divide the size of the email by the number of recipients to prevent it being added multiple times
|
||||
$this->size = $this->option('size') / count($recipients);
|
||||
// Divide the size of the email by the number of recipients (excluding any unsubscribe recipients) to prevent it being added multiple times
|
||||
$recipientCount = $recipients->where('domain', '!=', 'unsubscribe.'.config('anonaddy.domain'))->count();
|
||||
|
||||
$this->size = $this->option('size') / ($recipientCount ? $recipientCount : 1);
|
||||
|
||||
foreach ($recipients as $key => $recipient) {
|
||||
$subdomain = substr($recipient['domain'], 0, strrpos($recipient['domain'], '.'.config('anonaddy.domain'))); // e.g. johndoe
|
||||
|
@ -132,7 +134,7 @@ class ReceiveEmail extends Command
|
|||
})
|
||||
->toArray();
|
||||
|
||||
if (in_array($this->parser->getAddresses('from')[0]['address'], $userRecipients)) {
|
||||
if (in_array($this->option('sender'), $userRecipients)) {
|
||||
$alias->deactivate();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -408,6 +408,70 @@ class ReceiveEmailTest extends TestCase
|
|||
Mail::assertNotSent(ForwardEmail::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_count_unsubscribe_recipient_when_calculating_size()
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
Mail::assertNothingSent();
|
||||
|
||||
factory(Alias::class)->create([
|
||||
'id' => '8f36380f-df4e-4875-bb12-9c4448573712',
|
||||
'user_id' => $this->user->id,
|
||||
'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
|
||||
'local_part' => 'ebay',
|
||||
'domain' => 'johndoe.'.config('anonaddy.domain')
|
||||
]);
|
||||
|
||||
factory(Recipient::class)->create([
|
||||
'user_id' => $this->user->id,
|
||||
'email' => 'will@anonaddy.com'
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('aliases', [
|
||||
'id' => '8f36380f-df4e-4875-bb12-9c4448573712',
|
||||
'user_id' => $this->user->id,
|
||||
'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
|
||||
'active' => true
|
||||
]);
|
||||
|
||||
$this->artisan(
|
||||
'anonaddy:receive-email',
|
||||
[
|
||||
'file' => base_path('tests/emails/email_unsubscribe_plus_other_recipient.eml'),
|
||||
'--sender' => 'will@anonaddy.com',
|
||||
'--recipient' => ['8f36380f-df4e-4875-bb12-9c4448573712@unsubscribe.anonaddy.me', 'another@johndoe.anonaddy.me'],
|
||||
'--local_part' => ['8f36380f-df4e-4875-bb12-9c4448573712', 'another'],
|
||||
'--extension' => ['', ''],
|
||||
'--domain' => ['unsubscribe.anonaddy.me', 'johndoe.anonaddy.me'],
|
||||
'--size' => '1000'
|
||||
]
|
||||
)->assertExitCode(0);
|
||||
|
||||
$this->assertDatabaseHas('aliases', [
|
||||
'id' => '8f36380f-df4e-4875-bb12-9c4448573712',
|
||||
'user_id' => $this->user->id,
|
||||
'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
|
||||
'local_part' => 'ebay',
|
||||
'domain' => 'johndoe.'.config('anonaddy.domain'),
|
||||
'active' => false
|
||||
]);
|
||||
$this->assertDatabaseHas('aliases', [
|
||||
'user_id' => $this->user->id,
|
||||
'email' => 'another@johndoe.'.config('anonaddy.domain'),
|
||||
'local_part' => 'another',
|
||||
'domain' => 'johndoe.'.config('anonaddy.domain'),
|
||||
'active' => true
|
||||
]);
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $this->user->id,
|
||||
'username' => 'johndoe',
|
||||
'bandwidth' => '1000'
|
||||
]);
|
||||
|
||||
Mail::assertNotSent(ForwardEmail::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_cannot_unsubscribe_alias_if_not_a_verified_user_recipient()
|
||||
{
|
||||
|
|
15
tests/emails/email_unsubscribe_plus_other_recipient.eml
Normal file
15
tests/emails/email_unsubscribe_plus_other_recipient.eml
Normal file
|
@ -0,0 +1,15 @@
|
|||
Date: Wed, 20 Feb 2019 15:00:00 +0100 (CET)
|
||||
From: Will <will@anonaddy.com>
|
||||
To: <8f36380f-df4e-4875-bb12-9c4448573712@unsubscribe.anonaddy.me>, <another@johndoe.anonaddy.me>
|
||||
Subject: Unsubscribe
|
||||
Content-Type: multipart/mixed; boundary="----=_Part_10031_1199410393.1550677940425"
|
||||
|
||||
------=_Part_10031_1199410393.1550677940425
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
------=_Part_10031_1199410393.1550677940425
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
------=_Part_10031_1199410393.1550677940425--
|
Loading…
Add table
Reference in a new issue