فهرست منبع

Added default alias domain option

Will Browning 5 سال پیش
والد
کامیت
50bbc9db3a

+ 3 - 3
app/Console/Commands/ReceiveEmail.php

@@ -129,7 +129,7 @@ class ReceiveEmail extends Command
                 $this->checkRateLimit($user);
 
                 // Check whether this email is a reply/send from or a new email to be forwarded.
-                if (filter_var(Str::replaceLast('=', '@', $recipient['extension']), FILTER_VALIDATE_EMAIL)) {
+                if (filter_var(Str::replaceLast('=', '@', $recipient['extension']), FILTER_VALIDATE_EMAIL) && $user->isVerifiedRecipient($this->option('sender'))) {
                     if ($this->parser->getHeader('In-Reply-To')) {
                         $this->handleReply($user, $recipient);
                     } else {
@@ -161,7 +161,7 @@ class ReceiveEmail extends Command
     {
         $alias = $user->aliases()->where('email', $recipient['local_part'] . '@' . $recipient['domain'])->first();
 
-        if ($alias && $user->isVerifiedRecipient($this->option('sender'))) {
+        if ($alias) {
             $sendTo = Str::replaceLast('=', '@', $recipient['extension']);
 
             $emailData = new EmailData($this->parser);
@@ -188,7 +188,7 @@ class ReceiveEmail extends Command
         ]);
 
         // This is a new alias but at a shared domain or the sender is not a verified recipient.
-        if ((!isset($alias->id) && in_array($recipient['domain'], config('anonaddy.all_domains'))) || !$user->isVerifiedRecipient($this->option('sender'))) {
+        if (!isset($alias->id) && in_array($recipient['domain'], config('anonaddy.all_domains'))) {
             exit(0);
         }
 

+ 2 - 1
app/Http/Controllers/Api/DomainOptionController.php

@@ -9,7 +9,8 @@ class DomainOptionController extends Controller
     public function index()
     {
         return response()->json([
-            'data' => user()->domainOptions()
+            'data' => user()->domainOptions(),
+            'defaultAliasDomain' => user()->default_alias_domain
         ]);
     }
 }

+ 16 - 0
app/Http/Controllers/DefaultAliasDomainController.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Http\Requests\UpdateDefaultAliasDomainRequest;
+
+class DefaultAliasDomainController extends Controller
+{
+    public function update(UpdateDefaultAliasDomainRequest $request)
+    {
+        user()->default_alias_domain = $request->domain;
+        user()->save();
+
+        return back()->with(['status' => 'Default Alias Domain Updated Successfully']);
+    }
+}

+ 2 - 1
app/Http/Controllers/ShowAliasController.php

@@ -15,7 +15,8 @@ class ShowAliasController extends Controller
             'totalReplies' => user()->totalEmailsReplied(),
             'domain' => user()->username.'.'.config('anonaddy.domain'),
             'bandwidthMb' => user()->bandwidth_mb,
-            'domainOptions' => user()->domainOptions()
+            'domainOptions' => user()->domainOptions(),
+            'defaultAliasDomain' => user()->default_alias_domain
         ]);
     }
 }

+ 35 - 0
app/Http/Requests/UpdateDefaultAliasDomainRequest.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Validation\Rule;
+
+class UpdateDefaultAliasDomainRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'domain' => [
+                'required',
+                'string',
+                Rule::in($this->user()->domainOptions())
+            ]
+        ];
+    }
+}

+ 35 - 35
composer.lock

@@ -686,24 +686,24 @@
         },
         {
             "name": "fideloper/proxy",
-            "version": "4.2.2",
+            "version": "4.3.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/fideloper/TrustedProxy.git",
-                "reference": "790194d5d3da89a713478875d2e2d05855a90a81"
+                "reference": "ec38ad69ee378a1eec04fb0e417a97cfaf7ed11a"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/fideloper/TrustedProxy/zipball/790194d5d3da89a713478875d2e2d05855a90a81",
-                "reference": "790194d5d3da89a713478875d2e2d05855a90a81",
+                "url": "https://api.github.com/repos/fideloper/TrustedProxy/zipball/ec38ad69ee378a1eec04fb0e417a97cfaf7ed11a",
+                "reference": "ec38ad69ee378a1eec04fb0e417a97cfaf7ed11a",
                 "shasum": ""
             },
             "require": {
-                "illuminate/contracts": "^5.0|^6.0|^7.0",
+                "illuminate/contracts": "^5.0|^6.0|^7.0|^8.0",
                 "php": ">=5.4.0"
             },
             "require-dev": {
-                "illuminate/http": "^5.0|^6.0|^7.0",
+                "illuminate/http": "^5.0|^6.0|^7.0|^8.0",
                 "mockery/mockery": "^1.0",
                 "phpunit/phpunit": "^6.0"
             },
@@ -736,27 +736,27 @@
                 "proxy",
                 "trusted proxy"
             ],
-            "time": "2019-12-20T13:11:11+00:00"
+            "time": "2020-02-22T01:51:47+00:00"
         },
         {
             "name": "firebase/php-jwt",
-            "version": "v5.0.0",
+            "version": "v5.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/firebase/php-jwt.git",
-                "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e"
+                "reference": "4566062c68f76f43d44f1643f4970fe89757d4c6"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
-                "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
+                "url": "https://api.github.com/repos/firebase/php-jwt/zipball/4566062c68f76f43d44f1643f4970fe89757d4c6",
+                "reference": "4566062c68f76f43d44f1643f4970fe89757d4c6",
                 "shasum": ""
             },
             "require": {
                 "php": ">=5.3.0"
             },
             "require-dev": {
-                "phpunit/phpunit": " 4.8.35"
+                "phpunit/phpunit": "^4.8|^5"
             },
             "type": "library",
             "autoload": {
@@ -782,7 +782,7 @@
             ],
             "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
             "homepage": "https://github.com/firebase/php-jwt",
-            "time": "2017-06-27T22:17:23+00:00"
+            "time": "2020-02-24T23:15:03+00:00"
         },
         {
             "name": "guzzlehttp/guzzle",
@@ -1269,16 +1269,16 @@
         },
         {
             "name": "laravel/framework",
-            "version": "v6.15.1",
+            "version": "v6.17.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/laravel/framework.git",
-                "reference": "b7c152e3327c03428fb68d5abb63ca8b3eca8422"
+                "reference": "32d1ed55dd46dcd706ff2e45bb7965be7320b87d"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/laravel/framework/zipball/b7c152e3327c03428fb68d5abb63ca8b3eca8422",
-                "reference": "b7c152e3327c03428fb68d5abb63ca8b3eca8422",
+                "url": "https://api.github.com/repos/laravel/framework/zipball/32d1ed55dd46dcd706ff2e45bb7965be7320b87d",
+                "reference": "32d1ed55dd46dcd706ff2e45bb7965be7320b87d",
                 "shasum": ""
             },
             "require": {
@@ -1346,7 +1346,7 @@
                 "aws/aws-sdk-php": "^3.0",
                 "doctrine/dbal": "^2.6",
                 "filp/whoops": "^2.4",
-                "guzzlehttp/guzzle": "^6.3",
+                "guzzlehttp/guzzle": "^6.3|^7.0",
                 "league/flysystem-cached-adapter": "^1.0",
                 "mockery/mockery": "^1.3.1",
                 "moontoast/math": "^1.1",
@@ -1366,7 +1366,7 @@
                 "ext-redis": "Required to use the Redis cache and queue drivers.",
                 "filp/whoops": "Required for friendly error pages in development (^2.4).",
                 "fzaninotto/faker": "Required to use the eloquent factory builder (^1.9.1).",
-                "guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.0).",
+                "guzzlehttp/guzzle": "Required to use the Mailgun mail driver and the ping methods on schedules (^6.0|^7.0).",
                 "laravel/tinker": "Required to use the tinker console command (^2.0).",
                 "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
                 "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).",
@@ -1411,7 +1411,7 @@
                 "framework",
                 "laravel"
             ],
-            "time": "2020-02-12T21:56:14+00:00"
+            "time": "2020-02-26T14:23:01+00:00"
         },
         {
             "name": "laravel/passport",
@@ -2467,16 +2467,16 @@
         },
         {
             "name": "phpseclib/phpseclib",
-            "version": "2.0.23",
+            "version": "2.0.25",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpseclib/phpseclib.git",
-                "reference": "c78eb5058d5bb1a183133c36d4ba5b6675dfa099"
+                "reference": "c18159618ed7cd7ff721ac1a8fec7860a475d2f0"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/c78eb5058d5bb1a183133c36d4ba5b6675dfa099",
-                "reference": "c78eb5058d5bb1a183133c36d4ba5b6675dfa099",
+                "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/c18159618ed7cd7ff721ac1a8fec7860a475d2f0",
+                "reference": "c18159618ed7cd7ff721ac1a8fec7860a475d2f0",
                 "shasum": ""
             },
             "require": {
@@ -2555,7 +2555,7 @@
                 "x.509",
                 "x509"
             ],
-            "time": "2019-09-17T03:41:22+00:00"
+            "time": "2020-02-25T04:16:50+00:00"
         },
         {
             "name": "pragmarx/google2fa",
@@ -3154,16 +3154,16 @@
         },
         {
             "name": "ramsey/uuid",
-            "version": "3.9.2",
+            "version": "3.9.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/ramsey/uuid.git",
-                "reference": "7779489a47d443f845271badbdcedfe4df8e06fb"
+                "reference": "7e1633a6964b48589b142d60542f9ed31bd37a92"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/ramsey/uuid/zipball/7779489a47d443f845271badbdcedfe4df8e06fb",
-                "reference": "7779489a47d443f845271badbdcedfe4df8e06fb",
+                "url": "https://api.github.com/repos/ramsey/uuid/zipball/7e1633a6964b48589b142d60542f9ed31bd37a92",
+                "reference": "7e1633a6964b48589b142d60542f9ed31bd37a92",
                 "shasum": ""
             },
             "require": {
@@ -3237,7 +3237,7 @@
                 "identifier",
                 "uuid"
             ],
-            "time": "2019-12-17T08:18:51+00:00"
+            "time": "2020-02-21T04:36:14+00:00"
         },
         {
             "name": "swiftmailer/swiftmailer",
@@ -6041,16 +6041,16 @@
         },
         {
             "name": "phpdocumentor/reflection-docblock",
-            "version": "5.0.0",
+            "version": "5.1.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
-                "reference": "a48807183a4b819072f26e347bbd0b5199a9d15f"
+                "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/a48807183a4b819072f26e347bbd0b5199a9d15f",
-                "reference": "a48807183a4b819072f26e347bbd0b5199a9d15f",
+                "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e",
+                "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e",
                 "shasum": ""
             },
             "require": {
@@ -6090,7 +6090,7 @@
                 }
             ],
             "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.",
-            "time": "2020-02-09T09:16:15+00:00"
+            "time": "2020-02-22T12:28:44+00:00"
         },
         {
             "name": "phpdocumentor/type-resolver",

+ 32 - 0
database/migrations/2020_02_28_111536_add_default_alias_domain_to_users_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddDefaultAliasDomainToUsersTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->string('default_alias_domain')->after('default_recipient_id')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->dropColumn('default_alias_domain');
+        });
+    }
+}

+ 16 - 10
package-lock.json

@@ -2538,9 +2538,9 @@
             "dev": true
         },
         "dayjs": {
-            "version": "1.8.20",
-            "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.20.tgz",
-            "integrity": "sha512-mH0MCDxw6UCGJYxVN78h8ugWycZAO8thkj3bW6vApL5tS0hQplIDdAQcmbvl7n35H0AKdCJQaArTrIQw2xt4Qg=="
+            "version": "1.8.21",
+            "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.21.tgz",
+            "integrity": "sha512-1kbWK0hziklUHkGgiKr7xm59KwAg/K3Tp7H/8X+f58DnNCwY3pKYjOCJpIlVs125FRBukGVZdKZojC073D0IeQ=="
         },
         "de-indent": {
             "version": "1.0.2",
@@ -9312,9 +9312,9 @@
             "integrity": "sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ=="
         },
         "vue-good-table": {
-            "version": "2.18.1",
-            "resolved": "https://registry.npmjs.org/vue-good-table/-/vue-good-table-2.18.1.tgz",
-            "integrity": "sha512-W9D5M87GgzgQowtWVARqxSwSvHx0MKnKV5d9Zlz5Fx3XfuJWm4lufZUpWlTwKTbLWoG4cLjHd6N0m55S9Ild3Q==",
+            "version": "2.19.0",
+            "resolved": "https://registry.npmjs.org/vue-good-table/-/vue-good-table-2.19.0.tgz",
+            "integrity": "sha512-ua8WNV+b9XuFXqDA0wFMp43bMjkRIQ93P24V64MgQKp7GcYg2xp7S/gej7BYYLZiSZpH9lkDMq7w4IuVg1p7Pg==",
             "requires": {
                 "date-fns": "^2.0.0-beta.4",
                 "diacriticless": "1.0.1",
@@ -9322,13 +9322,14 @@
                 "lodash.clonedeep": "^4.5.0",
                 "lodash.filter": "^4.6.0",
                 "lodash.foreach": "^4.5.0",
-                "lodash.isequal": "^4.5.0"
+                "lodash.isequal": "^4.5.0",
+                "vue-select": "^3.1.0"
             },
             "dependencies": {
                 "date-fns": {
-                    "version": "2.7.0",
-                    "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.7.0.tgz",
-                    "integrity": "sha512-wxYp2PGoUDN5ZEACc61aOtYFvSsJUylIvCjpjDOqM1UDaKIIuMJ9fAnMYFHV3TQaDpfTVxhwNK/GiCaHKuemTA=="
+                    "version": "2.10.0",
+                    "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.10.0.tgz",
+                    "integrity": "sha512-EhfEKevYGWhWlZbNeplfhIU/+N+x0iCIx7VzKlXma2EdQyznVlZhCptXUY+BegNpPW2kjdx15Rvq503YcXXrcA=="
                 }
             }
         },
@@ -9359,6 +9360,11 @@
             "resolved": "https://registry.npmjs.org/vue-notification/-/vue-notification-1.3.20.tgz",
             "integrity": "sha512-vPj67Ah72p8xvtyVE8emfadqVWguOScAjt6OJDEUdcW5hW189NsqvfkOrctxHUUO9UYl9cTbIkzAEcPnHu+zBQ=="
         },
+        "vue-select": {
+            "version": "3.4.0",
+            "resolved": "https://registry.npmjs.org/vue-select/-/vue-select-3.4.0.tgz",
+            "integrity": "sha512-UHd0fiUjPgRmHIGhI6yUKtnJsHOdvzD00QUGUtD+FaxWWZRWF2AAb7KPZRj0j/egVfZQvey6M6woHn78GbTogA=="
+        },
         "vue-style-loader": {
             "version": "4.1.2",
             "resolved": "https://registry.npmjs.org/vue-style-loader/-/vue-style-loader-4.1.2.tgz",

+ 2 - 2
package.json

@@ -13,7 +13,7 @@
     "dependencies": {
         "axios": "^0.18.1",
         "cross-env": "^5.2.1",
-        "dayjs": "^1.8.20",
+        "dayjs": "^1.8.21",
         "laravel-mix": "^4.1.4",
         "laravel-mix-purgecss": "^4.2.0",
         "lodash": "^4.17.15",
@@ -25,7 +25,7 @@
         "tippy.js": "^4.3.5",
         "v-clipboard": "^2.2.2",
         "vue": "^2.6.11",
-        "vue-good-table": "^2.18.1",
+        "vue-good-table": "^2.19.0",
         "vue-multiselect": "^2.1.6",
         "vue-notification": "^1.3.20",
         "vue-template-compiler": "^2.6.11"

+ 5 - 1
resources/js/pages/Aliases.vue

@@ -580,6 +580,10 @@ export default {
       type: Array,
       required: true,
     },
+    defaultAliasDomain: {
+      type: String,
+      required: true,
+    },
   },
   components: {
     Modal,
@@ -601,7 +605,7 @@ export default {
       editAliasRecipientsModalOpen: false,
       generateAliasModalOpen: false,
       generateAliasLoading: false,
-      generateAliasDomain: this.domain,
+      generateAliasDomain: this.defaultAliasDomain ? this.defaultAliasDomain : this.domain,
       generateAliasDescription: '',
       generateAliasFormat: 'uuid',
       aliasFormatOptions: [

+ 1 - 1
resources/views/aliases/index.blade.php

@@ -4,6 +4,6 @@
     <div class="container py-8">
         @include('shared.status')
 
-        <aliases :default-recipient="{{json_encode($defaultRecipient)}}" :initial-aliases="{{json_encode($aliases)}}" :recipient-options="{{json_encode($recipients)}}" :total-forwarded="{{$totalForwarded}}" :total-blocked="{{$totalBlocked}}" :total-replies="{{$totalReplies}}" domain="{{config('anonaddy.domain')}}" subdomain="{{$domain}}" :bandwidth-mb="{{$bandwidthMb}}" :month="{{json_encode(now()->format('M'))}}" :domain-options="{{$domainOptions}}" />
+        <aliases :default-recipient="{{json_encode($defaultRecipient)}}" :initial-aliases="{{json_encode($aliases)}}" :recipient-options="{{json_encode($recipients)}}" :total-forwarded="{{$totalForwarded}}" :total-blocked="{{$totalBlocked}}" :total-replies="{{$totalReplies}}" domain="{{config('anonaddy.domain')}}" subdomain="{{$domain}}" :bandwidth-mb="{{$bandwidthMb}}" :month="{{json_encode(now()->format('M'))}}" :domain-options="{{$domainOptions}}" default-alias-domain={{$defaultAliasDomain}} />
     </div>
 @endsection

+ 44 - 0
resources/views/settings/show.blade.php

@@ -146,6 +146,50 @@
 
             @endif
 
+            <form method="POST" action="{{ route('settings.default_alias_domain') }}" class="pt-16">
+                @csrf
+
+                <div class="mb-6">
+
+                    <h3 class="font-bold text-xl">
+                        Update Default Alias Domain
+                    </h3>
+
+                    <div class="mt-4 w-24 border-b-2 border-grey-200"></div>
+
+                    <p class="mt-6">The default alias domain is the domain you'd like to be selected by default in the drop down options when generating a new alias on the site or the browser extension. This will save you needing to select your preferred domain from the dropdown  each time.</p>
+
+                    <div class="mt-6 flex flex-wrap mb-4">
+                        <label for="default-recipient" class="block text-grey-700 text-sm mb-2">
+                            {{ __('Select Default Domain') }}:
+                        </label>
+
+                        <div class="block relative w-full">
+                            <select id="default-alias-domain" class="block appearance-none w-full text-grey-700 bg-grey-100 p-3 pr-8 rounded shadow focus:shadow-outline" name="domain" required>
+                                @foreach($user->domainOptions() as $domainOption)
+                                <option value="{{ $domainOption }}" {{ $user->default_alias_domain === $domainOption ? 'selected' : '' }}>{{ $domainOption }}</option>
+                                @endforeach
+                            </select>
+                            <div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
+                                <svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/></svg>
+                            </div>
+                        </div>
+
+                        @if ($errors->has('domain'))
+                            <p class="text-red-500 text-xs italic mt-4">
+                                {{ $errors->first('domain') }}
+                            </p>
+                        @endif
+                    </div>
+
+                </div>
+
+                <button type="submit" class="bg-cyan-400 w-full hover:bg-cyan-300 text-cyan-900 font-bold py-3 px-4 rounded focus:outline-none">
+                    {{ __('Update Default Alias Domain') }}
+                </button>
+
+            </form>
+
             <form id="update-password" method="POST" action="{{ route('settings.password') }}" class="pt-16">
                 @csrf
 

+ 2 - 0
routes/web.php

@@ -43,6 +43,8 @@ Route::group([
     Route::post('/default-recipient', 'DefaultRecipientController@update')->name('settings.default_recipient');
     Route::post('/edit-default-recipient', 'DefaultRecipientController@edit')->name('settings.edit_default_recipient');
 
+    Route::post('/default-alias-domain', 'DefaultAliasDomainController@update')->name('settings.default_alias_domain');
+
     Route::post('/from-name', 'FromNameController@update')->name('settings.from_name');
 
     Route::post('/email-subject', 'EmailSubjectController@update')->name('settings.email_subject');

+ 1 - 1
tests/Feature/ReplyToEmailTest.php

@@ -106,7 +106,7 @@ class ReplyToEmailTest extends TestCase
             'email' => $alias->email,
             'local_part' => $alias->local_part,
             'domain' => $alias->domain,
-            'emails_forwarded' => 0,
+            'emails_forwarded' => 1,
             'emails_blocked' => 0,
             'emails_replied' => 0
         ]);

+ 34 - 1
tests/Feature/SettingsTest.php

@@ -49,7 +49,7 @@ class SettingsTest extends TestCase
     }
 
     /** @test */
-    public function user_can_not_update_to_unverified_default_recipient()
+    public function user_cannot_update_to_unverified_default_recipient()
     {
         $newDefaultRecipient = factory(Recipient::class)->create([
             'user_id' => $this->user->id,
@@ -66,6 +66,39 @@ class SettingsTest extends TestCase
         $this->assertNotEquals($this->user->default_recipient_id, $newDefaultRecipient->id);
     }
 
+    /** @test */
+    public function user_can_update_default_alias_domain()
+    {
+        $defaultAliasDomain = $this->user->username.'.anonaddy.me';
+
+        $response = $this->post('/settings/default-alias-domain', [
+            'domain' => $defaultAliasDomain
+        ]);
+
+        $response->assertStatus(302);
+        $this->assertDatabaseHas('users', [
+            'id' => $this->user->id,
+            'default_alias_domain' => $defaultAliasDomain
+        ]);
+    }
+
+    /** @test */
+    public function user_cannot_update_default_alias_domain_if_invalid()
+    {
+        $defaultAliasDomain = 'johndoe.anonaddy.me';
+
+        $response = $this->post('/settings/default-alias-domain', [
+            'domain' => $defaultAliasDomain
+        ]);
+
+        $response->assertStatus(302);
+        $response->assertSessionHasErrors(['domain']);
+        $this->assertDatabaseHas('users', [
+            'id' => $this->user->id,
+            'default_alias_domain' => null
+        ]);
+    }
+
     /** @test */
     public function user_can_update_reply_from_name()
     {

+ 21 - 0
tests/Unit/UserTest.php

@@ -194,4 +194,25 @@ class UserTest extends TestCase
 
         $this->assertEquals(96.27, $this->user->bandwidth_mb);
     }
+
+    /** @test */
+    public function user_get_domain_options()
+    {
+        $username = $this->user->username;
+
+        $domainOptions = $this->user->domainOptions();
+
+        $expected = collect([
+            'anonaddy.me',
+            'anonaddy.com',
+            $username.'.anonaddy.me',
+            $username.'.anonaddy.com',
+        ]);
+
+        $this->assertCount($expected->count(), $domainOptions);
+
+        $expected->zip($domainOptions)->each(function ($itemPair) {
+            $this->assertEquals($itemPair[0], $itemPair[1]);
+        });
+    }
 }