1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2025-12-01 05:43:04 +00:00

test: add smtp sender test for MX lookup timeouts

هذا الالتزام موجود في:
Adam Cooke
2024-03-01 21:41:46 +00:00
الأصل 0c1f9250d4
التزام e4638a0c40

عرض الملف

@@ -46,6 +46,7 @@ RSpec.describe SMTPSender do
describe "#start" do
context "when no servers are provided to the class and there are no SMTP relays" do
context "when there are MX records" do
before do
allow(DNSResolver.local).to receive(:mx).and_return([[5, "mx1.example.com"], [10, "mx2.example.com"]])
allow(DNSResolver.local).to receive(:a).with("mx1.example.com").and_return(["1.2.3.4"])
@@ -62,6 +63,34 @@ RSpec.describe SMTPSender do
end
end
context "when there are no MX records" do
before do
allow(DNSResolver.local).to receive(:mx).and_return([])
allow(DNSResolver.local).to receive(:a).with("example.com").and_return(["1.2.3.4"])
end
it "attempts to create an SMTP connection for the domain itself" do
endpoint = sender.start
expect(endpoint).to be_a SMTPClient::Endpoint
expect(endpoint).to have_attributes(
ip_address: "1.2.3.4",
server: have_attributes(hostname: "example.com", port: 25, ssl_mode: SMTPClient::SSLModes::AUTO)
)
end
end
context "when the MX lookup times out" do
before do
allow(DNSResolver.local).to receive(:mx).and_raise(Resolv::ResolvError.new("DNS resolv timeout: example.com"))
allow(DNSResolver.local).to receive(:a).with("example.com").and_return(["1.2.3.4"])
end
it "raises an error" do
expect { sender.start }.to raise_error Resolv::ResolvError
end
end
end
context "when there are no servers provided to the class but there are SMTP relays" do
before do
allow(SMTPSender).to receive(:smtp_relays).and_return([SMTPClient::Server.new("relay.example.com", port: 2525, ssl_mode: SMTPClient::SSLModes::TLS)])