Fixed: Require Mailman settings to be filled
This commit is contained in:
parent
5cd3578b36
commit
430578f184
|
@ -29,9 +29,27 @@ class SettingSaveAction
|
||||||
$settings->save();
|
$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
|
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.');
|
$validator->errors()->add('mailman', 'Verbindung fehlgeschlagen.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))->setCredentials('http://mailman.test/api', 'user', 'secret');
|
||||||
Phake::verify(app(MailmanService::class))->check();
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue