1
0
مراية لـ https://github.com/postalserver/postal.git تم المزامنة 2026-03-03 22:34:09 +00:00

refactor: refactor the SMTP sender

هذا الالتزام موجود في:
Adam Cooke
2024-02-29 10:32:57 +00:00
الأصل be0df7b463
التزام 633c509a45
11 ملفات معدلة مع 1291 إضافات و256 حذوفات

عرض الملف

@@ -0,0 +1,67 @@
# frozen_string_literal: true
require "rails_helper"
module SMTPClient
RSpec.describe Server do
let(:hostname) { "example.com" }
let(:port) { 25 }
let(:ssl_mode) { SSLModes::AUTO }
subject(:server) { described_class.new(hostname, port: port, ssl_mode: ssl_mode) }
describe "#endpoints" do
context "when there are A and AAAA records" do
before do
allow(DNSResolver.local).to receive(:a).and_return(["1.2.3.4", "2.3.4.5"])
allow(DNSResolver.local).to receive(:aaaa).and_return(["2a00::67a0:a::1234", "2a00::67a0:a::2345"])
end
it "asks the resolver for the A and AAAA records for the hostname" do
server.endpoints
expect(DNSResolver.local).to have_received(:a).with(hostname).once
expect(DNSResolver.local).to have_received(:aaaa).with(hostname).once
end
it "returns endpoints for ipv6 addresses followed by ipv4" do
expect(server.endpoints).to match [
have_attributes(ip_address: "2a00::67a0:a::1234"),
have_attributes(ip_address: "2a00::67a0:a::2345"),
have_attributes(ip_address: "1.2.3.4"),
have_attributes(ip_address: "2.3.4.5")
]
end
end
context "when there are just A records" do
before do
allow(DNSResolver.local).to receive(:a).and_return(["1.2.3.4", "2.3.4.5"])
allow(DNSResolver.local).to receive(:aaaa).and_return([])
end
it "returns ipv4 endpoints" do
expect(server.endpoints).to match [
have_attributes(ip_address: "1.2.3.4"),
have_attributes(ip_address: "2.3.4.5")
]
end
end
context "when there are just AAAA records" do
before do
allow(DNSResolver.local).to receive(:a).and_return([])
allow(DNSResolver.local).to receive(:aaaa).and_return(["2a00::67a0:a::1234", "2a00::67a0:a::2345"])
end
it "returns ipv6 endpoints" do
expect(server.endpoints).to match [
have_attributes(ip_address: "2a00::67a0:a::1234"),
have_attributes(ip_address: "2a00::67a0:a::2345")
]
end
end
end
end
end