Merge pull request #10863 from VijaykumarPujar-tech/new_branch

Fix: Implement mandatory authentication check for Custom SMTP configuration
This commit is contained in:
Steven Nguyen 2025-12-11 13:51:27 -08:00 committed by GitHub
commit 3d0aa74ffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -2071,8 +2071,14 @@ App::patch('/v1/projects/:projectId/smtp')
// validate SMTP settings
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->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = $username;
$mail->Password = $password;
$mail->Host = $host;

View file

@ -564,6 +564,8 @@ class ProjectsConsoleClientTest extends Scope
public function testUpdateProjectSMTP($data): array
{
$id = $data['projectId'];
/**Test for SUCCESS: Valid Credentials*/
$response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/smtp', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
@ -603,6 +605,24 @@ class ProjectsConsoleClientTest extends Scope
$this->assertEquals('password', $response['body']['smtpPassword']);
$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;
}