mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 17:15:08 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
119 lines
4.3 KiB
PHP
119 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Platform\Settings\MailConfigApplier;
|
|
use App\Modules\Platform\Settings\MailProviderSettings;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
beforeEach(function () {
|
|
$this->admin = User::factory()->create();
|
|
});
|
|
|
|
test('the password is encrypted at rest', function () {
|
|
MailProviderSettings::current()->fill(['password' => 'super-secret-smtp-password'])->save();
|
|
|
|
$raw = DB::table('mail_provider_settings')->value('password');
|
|
|
|
expect($raw)->not->toBe('super-secret-smtp-password')
|
|
->and(MailProviderSettings::current()->password)->toBe('super-secret-smtp-password');
|
|
});
|
|
|
|
test('apply() is a no-op when no host is configured', function () {
|
|
$originalHost = config('mail.mailers.smtp.host');
|
|
|
|
app(MailConfigApplier::class)->apply();
|
|
|
|
expect(config('mail.mailers.smtp.host'))->toBe($originalHost);
|
|
});
|
|
|
|
test('apply() overrides mail config once a host is saved', function () {
|
|
MailProviderSettings::current()->fill([
|
|
'host' => 'smtp.example.test',
|
|
'port' => 2525,
|
|
'username' => 'mailer',
|
|
'password' => 'secret',
|
|
'encryption' => 'tls',
|
|
'from_address' => 'noreply@example.test',
|
|
'from_name' => 'Example App',
|
|
])->save();
|
|
|
|
app(MailConfigApplier::class)->flush();
|
|
app(MailConfigApplier::class)->apply();
|
|
|
|
expect(config('mail.default'))->toBe('smtp')
|
|
->and(config('mail.mailers.smtp.host'))->toBe('smtp.example.test')
|
|
->and(config('mail.mailers.smtp.port'))->toBe(2525)
|
|
->and(config('mail.mailers.smtp.username'))->toBe('mailer')
|
|
->and(config('mail.mailers.smtp.password'))->toBe('secret')
|
|
->and(config('mail.mailers.smtp.encryption'))->toBe('tls')
|
|
->and(config('mail.from.address'))->toBe('noreply@example.test')
|
|
->and(config('mail.from.name'))->toBe('Example App');
|
|
});
|
|
|
|
test('apply() maps "none" encryption to a null Symfony-compatible value', function () {
|
|
MailProviderSettings::current()->fill(['host' => 'smtp.example.test', 'encryption' => 'none'])->save();
|
|
|
|
app(MailConfigApplier::class)->flush();
|
|
app(MailConfigApplier::class)->apply();
|
|
|
|
expect(config('mail.mailers.smtp.encryption'))->toBeNull();
|
|
});
|
|
|
|
test('staff can save mail provider settings', function () {
|
|
$this->actingAs($this->admin)->patch('/system/settings/email', validEmailSettingsPayload([
|
|
'provider' => 'sendgrid',
|
|
'host' => 'smtp.sendgrid.net',
|
|
'port' => 587,
|
|
'username' => 'apikey',
|
|
'password' => 'sg-secret',
|
|
]))->assertRedirect();
|
|
|
|
$settings = MailProviderSettings::current();
|
|
expect($settings->provider->value)->toBe('sendgrid')
|
|
->and($settings->host)->toBe('smtp.sendgrid.net')
|
|
->and($settings->port)->toBe(587)
|
|
->and($settings->password)->toBe('sg-secret');
|
|
});
|
|
|
|
test('saving with a blank password keeps the previously stored password', function () {
|
|
$this->actingAs($this->admin)->patch('/system/settings/email', validEmailSettingsPayload([
|
|
'username' => 'mailer',
|
|
'password' => 'first-password',
|
|
]));
|
|
|
|
$this->actingAs($this->admin)->patch('/system/settings/email', validEmailSettingsPayload([
|
|
'username' => 'mailer',
|
|
'password' => '',
|
|
'from_name' => 'Renamed App',
|
|
]));
|
|
|
|
$settings = MailProviderSettings::current();
|
|
expect($settings->password)->toBe('first-password')
|
|
->and($settings->from_name)->toBe('Renamed App');
|
|
});
|
|
|
|
test('saving mail provider settings rejects invalid input', function () {
|
|
$this->actingAs($this->admin)->patch('/system/settings/email', validEmailSettingsPayload([
|
|
'port' => 999999,
|
|
'encryption' => 'rot13',
|
|
'from_address' => 'not-an-email',
|
|
]))->assertSessionHasErrors(['port', 'encryption', 'from_address']);
|
|
});
|
|
|
|
test('saving mail provider settings signals the queue worker to restart', function () {
|
|
Cache::forget('illuminate:queue:restart');
|
|
|
|
$this->actingAs($this->admin)->patch('/system/settings/email', validEmailSettingsPayload());
|
|
|
|
expect(Cache::get('illuminate:queue:restart'))->not->toBeNull();
|
|
});
|
|
|
|
test('clients cannot save mail provider settings', function () {
|
|
$this->actingAs(User::factory()->client()->create())
|
|
->patch('/system/settings/email', validEmailSettingsPayload())
|
|
->assertForbidden();
|
|
});
|