mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 01:18:37 +00:00
Merge pull request #10863 from VijaykumarPujar-tech/new_branch
Fix: Implement mandatory authentication check for Custom SMTP configuration
This commit is contained in:
commit
3d0aa74ffe
2 changed files with 26 additions and 0 deletions
|
|
@ -2071,8 +2071,14 @@ App::patch('/v1/projects/:projectId/smtp')
|
||||||
|
|
||||||
// validate SMTP settings
|
// validate SMTP settings
|
||||||
if ($enabled) {
|
if ($enabled) {
|
||||||
|
if (empty($username)) {
|
||||||
|
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'SMTP Username is required when enabling SMTP.');
|
||||||
|
} elseif (empty($password)) {
|
||||||
|
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'SMTP Password is required when enabling SMTP.');
|
||||||
|
}
|
||||||
$mail = new PHPMailer(true);
|
$mail = new PHPMailer(true);
|
||||||
$mail->isSMTP();
|
$mail->isSMTP();
|
||||||
|
$mail->SMTPAuth = true;
|
||||||
$mail->Username = $username;
|
$mail->Username = $username;
|
||||||
$mail->Password = $password;
|
$mail->Password = $password;
|
||||||
$mail->Host = $host;
|
$mail->Host = $host;
|
||||||
|
|
|
||||||
|
|
@ -564,6 +564,8 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
public function testUpdateProjectSMTP($data): array
|
public function testUpdateProjectSMTP($data): array
|
||||||
{
|
{
|
||||||
$id = $data['projectId'];
|
$id = $data['projectId'];
|
||||||
|
|
||||||
|
/**Test for SUCCESS: Valid Credentials*/
|
||||||
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
|
@ -603,6 +605,24 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertEquals('password', $response['body']['smtpPassword']);
|
$this->assertEquals('password', $response['body']['smtpPassword']);
|
||||||
$this->assertEquals('', $response['body']['smtpSecure']);
|
$this->assertEquals('', $response['body']['smtpSecure']);
|
||||||
|
|
||||||
|
/** Test for Missing or Invalid Credentials*/
|
||||||
|
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'enabled' => true,
|
||||||
|
'senderEmail' => 'fail@appwrite.io',
|
||||||
|
'senderName' => 'Failing Mailer',
|
||||||
|
'host' => 'maildev',
|
||||||
|
'port' => 1025,
|
||||||
|
'username' => 'invalid-user',
|
||||||
|
'password' => 'bad-password',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(400, $response['headers']['status-code']);
|
||||||
|
$this->assertEquals(Exception::PROJECT_SMTP_CONFIG_INVALID, $response['body']['type']);
|
||||||
|
$this->assertStringContainsStringIgnoringCase('SMTP authentication failed.', $response['body']['message']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue