Impedisce combinazioni SMTP errate tra porta e crittografia.
Evita l'errore SSL wrong version number quando SSL/TLS è impostato sulla porta 587 invece che sulla 465. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
require "test_helper"
|
||||
|
||||
class MailIdentityTest < ActiveSupport::TestCase
|
||||
test "smtp settings use starttls on port 587" do
|
||||
identity = MailIdentity.new(
|
||||
name: "Test",
|
||||
from_name: "Test",
|
||||
from_email: "hello@example.com",
|
||||
smtp_host: "smtp.example.com",
|
||||
smtp_port: 587,
|
||||
encryption: "starttls",
|
||||
smtp_authentication: "plain",
|
||||
active: true
|
||||
)
|
||||
assert identity.valid?
|
||||
settings = identity.smtp_settings
|
||||
assert settings[:enable_starttls_auto]
|
||||
assert_not settings[:ssl]
|
||||
end
|
||||
|
||||
test "smtp settings use ssl on port 465" do
|
||||
identity = MailIdentity.new(
|
||||
name: "Test",
|
||||
from_name: "Test",
|
||||
from_email: "hello@example.com",
|
||||
smtp_host: "smtps.example.com",
|
||||
smtp_port: 465,
|
||||
encryption: "tls",
|
||||
smtp_authentication: "plain",
|
||||
active: true
|
||||
)
|
||||
assert identity.valid?
|
||||
settings = identity.smtp_settings
|
||||
assert settings[:ssl]
|
||||
assert_not settings[:enable_starttls_auto]
|
||||
end
|
||||
|
||||
test "rejects ssl encryption on port 587" do
|
||||
identity = MailIdentity.new(
|
||||
name: "Test",
|
||||
from_name: "Test",
|
||||
from_email: "hello@example.com",
|
||||
smtp_host: "smtps.example.com",
|
||||
smtp_port: 587,
|
||||
encryption: "tls",
|
||||
smtp_authentication: "plain",
|
||||
active: true
|
||||
)
|
||||
assert_not identity.valid?
|
||||
assert_includes identity.errors[:smtp_port], "con SSL/TLS va usata la porta 465 (es. smtps.aruba.it)"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user