123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- <?php
- namespace Tests\Feature;
- use App\Alias;
- use App\AliasRecipient;
- use App\Domain;
- use App\Mail\ForwardEmail;
- use App\Notifications\NearBandwidthLimit;
- use App\Recipient;
- use App\User;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Support\Facades\Mail;
- use Illuminate\Support\Facades\Notification;
- use Tests\TestCase;
- class ReceiveEmailTest extends TestCase
- {
- use RefreshDatabase;
- protected $user;
- protected function setUp(): void
- {
- parent::setUp();
- $this->user = factory(User::class)->create(['username' => 'johndoe']);
- $this->user->recipients()->save($this->user->defaultRecipient);
- }
- /** @test */
- public function it_can_forward_email_from_file()
- {
- Mail::fake();
- Notification::fake();
- Mail::assertNothingSent();
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '1000'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '1000'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- Notification::assertNothingSent();
- }
- /** @test */
- public function it_can_forward_email_from_file_with_attachment()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_with_attachment.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['attachment@johndoe.anonaddy.com'],
- '--local_part' => ['attachment'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '1000'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'attachment@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'attachment',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '1000'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- /** @test */
- public function it_can_forward_email_from_file_to_multiple_recipients()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_multiple_recipients.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com', 'amazon@johndoe.anonaddy.com', 'paypal@johndoe.anonaddy.me'],
- '--local_part' => ['ebay', 'amazon', 'paypal'],
- '--extension' => ['', '', ''],
- '--domain' => ['johndoe.anonaddy.com', 'johndoe.anonaddy.com', 'johndoe.anonaddy.com'],
- '--size' => '1217'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'amazon@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'amazon',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'paypal@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'paypal',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertEquals(3, $this->user->aliases()->count());
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '1217'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- /** @test */
- public function it_can_forward_email_from_file_with_extension()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_with_extension.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay+a@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => ['2.3'],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '789'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '789'
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- /** @test */
- public function it_can_forward_email_with_existing_alias()
- {
- Mail::fake();
- Mail::assertNothingSent();
- factory(Alias::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- ]);
- $defaultRecipient = $this->user->defaultRecipient;
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '559'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '559'
- ]);
- $this->assertCount(1, $this->user->aliases);
- Mail::assertQueued(ForwardEmail::class, function ($mail) use ($defaultRecipient) {
- return $mail->hasTo($defaultRecipient->email);
- });
- }
- /** @test */
- public function it_can_forward_email_with_uuid_generated_alias()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $uuid = '86064c92-da41-443e-a2bf-5a7b0247842f';
- config([
- 'anonaddy.admin_username' => 'random'
- ]);
- factory(Alias::class)->create([
- 'id' => $uuid,
- 'user_id' => $this->user->id,
- 'email' => $uuid.'@anonaddy.me',
- 'local_part' => $uuid,
- 'domain' => 'anonaddy.me',
- ]);
- $defaultRecipient = $this->user->defaultRecipient;
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_with_uuid.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => [$uuid.'@anonaddy.me'],
- '--local_part' => [$uuid],
- '--extension' => [''],
- '--domain' => ['anonaddy.me'],
- '--size' => '892'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'local_part' => $uuid,
- 'domain' => 'anonaddy.me',
- 'email' => $uuid.'@anonaddy.me',
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '892'
- ]);
- $this->assertCount(1, $this->user->aliases);
- Mail::assertQueued(ForwardEmail::class, function ($mail) use ($defaultRecipient) {
- return $mail->hasTo($defaultRecipient->email);
- });
- }
- /** @test */
- public function it_can_forward_email_with_existing_alias_and_receipients()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $alias = factory(Alias::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- ]);
- $recipient = factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'one@example.com'
- ]);
- $recipient2 = factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'two@example.com'
- ]);
- AliasRecipient::create([
- 'alias' => $alias,
- 'recipient' => $recipient
- ]);
- AliasRecipient::create([
- 'alias' => $alias,
- 'recipient' => $recipient2
- ]);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '444'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '444'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo('one@example.com') &&
- $mail->hasTo('two@example.com');
- });
- }
- /** @test */
- public function it_can_attach_recipients_to_new_alias_with_extension()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $recipient = factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'one@example.com'
- ]);
- $recipient2 = factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'two@example.com'
- ]);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_with_extension.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => ['2.3'],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '444'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'extension' => '2.3',
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '444'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) use ($recipient, $recipient2) {
- return $mail->hasTo($recipient->email) &&
- $mail->hasTo($recipient2->email);
- });
- }
- /** @test */
- public function it_can_not_attach_unverified_recipient_to_new_alias_with_extension()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $defaultRecipient = $this->user->defaultRecipient;
- factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'one@example.com',
- 'email_verified_at' => null
- ]);
- $verifiedRecipient = factory(Recipient::class)->create([
- 'user_id' => $this->user->id,
- 'email' => 'two@example.com'
- ]);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_with_extension.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => ['2.3'],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '444'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '444'
- ]);
- $alias = $this->user->aliases()->where('email', 'ebay@johndoe.'.config('anonaddy.domain'))->first();
- $this->assertCount(1, $alias->recipients);
- Mail::assertQueued(ForwardEmail::class, function ($mail) use ($defaultRecipient, $verifiedRecipient) {
- return $mail->hasTo($verifiedRecipient->email);
- });
- }
- /** @test */
- public function it_does_not_send_email_if_default_recipient_has_not_yet_been_verified()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $this->user->defaultRecipient->update(['email_verified_at' => null]);
- $this->assertNull($this->user->defaultRecipient->email_verified_at);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '1000'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseMissing('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '0'
- ]);
- Mail::assertNotSent(ForwardEmail::class);
- }
- /** @test */
- public function it_can_unsubscribe_alias_by_emailing_list_unsubscribe()
- {
- 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.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['8f36380f-df4e-4875-bb12-9c4448573712@unsubscribe.anonaddy.com'],
- '--local_part' => ['8f36380f-df4e-4875-bb12-9c4448573712'],
- '--extension' => [''],
- '--domain' => ['unsubscribe.anonaddy.com'],
- '--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('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '0'
- ]);
- 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.com', 'another@johndoe.anonaddy.com'],
- '--local_part' => ['8f36380f-df4e-4875-bb12-9c4448573712', 'another'],
- '--extension' => ['', ''],
- '--domain' => ['unsubscribe.anonaddy.com', 'johndoe.anonaddy.com'],
- '--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()
- {
- 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')
- ]);
- $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.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['8f36380f-df4e-4875-bb12-9c4448573712@unsubscribe.anonaddy.com'],
- '--local_part' => ['8f36380f-df4e-4875-bb12-9c4448573712'],
- '--extension' => [''],
- '--domain' => ['unsubscribe.anonaddy.com'],
- '--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' => true
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '0'
- ]);
- Mail::assertNotSent(ForwardEmail::class);
- }
- /** @test */
- public function it_can_forward_email_to_admin_username_for_root_domain()
- {
- Mail::fake();
- Mail::assertNothingSent();
- config(['anonaddy.admin_username' => 'johndoe']);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_admin.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@anonaddy.me'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['anonaddy.me'],
- '--size' => '1346'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@anonaddy.me',
- 'local_part' => 'ebay',
- 'domain' => 'anonaddy.me',
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '1346'
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- /** @test */
- public function it_can_forward_email_for_custom_domain()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $domain = factory(Domain::class)->create([
- 'user_id' => $this->user->id,
- 'domain' => 'example.com'
- ]);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_custom_domain.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@example.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['example.com'],
- '--size' => '871'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'domain_id' => $domain->id,
- 'email' => 'ebay@example.com',
- 'local_part' => 'ebay',
- 'domain' => 'example.com',
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '871'
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- /** @test */
- public function it_can_send_near_bandwidth_limit_notification()
- {
- Notification::fake();
- Notification::assertNothingSent();
- $this->user->update(['bandwidth' => 100943820]);
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.com'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.com'],
- '--size' => '1000'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.'.config('anonaddy.domain'),
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.'.config('anonaddy.domain'),
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '100944820'
- ]);
- Notification::assertSentTo(
- $this->user,
- NearBandwidthLimit::class
- );
- }
- /** @test */
- public function it_can_forward_email_from_file_for_all_domains()
- {
- Mail::fake();
- Mail::assertNothingSent();
- $this->artisan(
- 'anonaddy:receive-email',
- [
- 'file' => base_path('tests/emails/email_other_domain.eml'),
- '--sender' => 'will@anonaddy.com',
- '--recipient' => ['ebay@johndoe.anonaddy.me'],
- '--local_part' => ['ebay'],
- '--extension' => [''],
- '--domain' => ['johndoe.anonaddy.me'],
- '--size' => '1000'
- ]
- )->assertExitCode(0);
- $this->assertDatabaseHas('aliases', [
- 'email' => 'ebay@johndoe.anonaddy.me',
- 'local_part' => 'ebay',
- 'domain' => 'johndoe.anonaddy.me',
- 'emails_forwarded' => 1,
- 'emails_blocked' => 0
- ]);
- $this->assertEquals(1, $this->user->aliases()->count());
- $this->assertDatabaseHas('users', [
- 'id' => $this->user->id,
- 'username' => 'johndoe',
- 'bandwidth' => '1000'
- ]);
- Mail::assertQueued(ForwardEmail::class, function ($mail) {
- return $mail->hasTo($this->user->email);
- });
- }
- }
|