Fixed: Require Mailman settings to be filled

This commit is contained in:
Philipp Lang 2022-10-18 15:26:21 +02:00
parent 5cd3578b36
commit 430578f184
2 changed files with 34 additions and 1 deletions

View File

@ -29,9 +29,27 @@ class SettingSaveAction
$settings->save();
}
/**
* @return array<string, string>
*/
public function rules(): array
{
return [
'base_url' => 'required',
'username' => 'required',
'password' => 'required',
];
}
public function afterValidator(Validator $validator, ActionRequest $request): void
{
if (!app(MailmanService::class)->setCredentials($request->input('base_url'), $request->input('username'), $request->input('password'))->check()) {
if (!$request->filled(['base_url', 'username', 'password'])) {
return;
}
$result = app(MailmanService::class)->setCredentials($request->input('base_url'), $request->input('username'), $request->input('password'))->check();
if (!$result) {
$validator->errors()->add('mailman', 'Verbindung fehlgeschlagen.');
}
}

View File

@ -72,4 +72,19 @@ class SettingTest extends TestCase
Phake::verify(app(MailmanService::class))->setCredentials('http://mailman.test/api', 'user', 'secret');
Phake::verify(app(MailmanService::class))->check();
}
public function testItValidatesPassword(): void
{
$this->stubIo(MailmanService::class, fn ($mock) => $mock);
$this->login()->loginNami();
$response = $this->from('/setting/mailman')->post('/setting/mailman', [
'base_url' => 'http://mailman.test/api',
'username' => 'user',
'password' => '',
]);
$response->assertSessionHasErrors(['password' => 'Passwort ist erforderlich.']);
Phake::verifyNoInteraction(app(MailmanService::class));
}
}