مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2025-11-30 21:32:30 +00:00
refactor: move app/util/* to app/lib/
هذا الالتزام موجود في:
34
spec/lib/dkim_header_spec.rb
Normal file
34
spec/lib/dkim_header_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe DKIMHeader do
|
||||
examples = Rails.root.join("spec/examples/dkim_signing/*.msg")
|
||||
Dir[examples].each do |path|
|
||||
contents = File.read(path)
|
||||
frontmatter, email = contents.split(/^---\n/m, 2)
|
||||
frontmatter = YAML.safe_load(frontmatter)
|
||||
email.strip
|
||||
it "works with #{path.split('/').last}" do
|
||||
mocked_time = Time.at(frontmatter["time"].to_i)
|
||||
allow(Time).to receive(:now).and_return(mocked_time)
|
||||
|
||||
domain = instance_double("Domain")
|
||||
allow(domain).to receive(:dkim_status).and_return("OK")
|
||||
allow(domain).to receive(:name).and_return(frontmatter["domain"])
|
||||
allow(domain).to receive(:dkim_key).and_return(OpenSSL::PKey::RSA.new(frontmatter["private_key"]))
|
||||
allow(domain).to receive(:dkim_identifier).and_return(frontmatter["dkim_identifier"])
|
||||
|
||||
expectation = "DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r\n" \
|
||||
"\td=#{frontmatter['domain']};\r\n" \
|
||||
"\ts=#{frontmatter['dkim_identifier']}; t=#{mocked_time.to_i};\r\n" \
|
||||
"\tbh=#{frontmatter['bh']};\r\n" \
|
||||
"\th=#{frontmatter['headers']};\r\n" \
|
||||
"\tb=#{frontmatter['b'].scan(/.{1,72}/).join("\r\n\t")}"
|
||||
|
||||
header = described_class.new(domain, email)
|
||||
|
||||
expect(header.dkim_header).to eq expectation
|
||||
end
|
||||
end
|
||||
end
|
||||
85
spec/lib/dns_resolver_spec.rb
Normal file
85
spec/lib/dns_resolver_spec.rb
Normal file
@@ -0,0 +1,85 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe DNSResolver do
|
||||
subject(:resolver) { described_class.new }
|
||||
|
||||
# Now, we could mock everything in here which would give us some comfort
|
||||
# but I do think that we'll benefit more from having a full E2E test here
|
||||
# so we'll test this using values which we know to be fairly static and
|
||||
# that are within our control.
|
||||
|
||||
describe "#a" do
|
||||
it "returns a list of IP addresses" do
|
||||
expect(resolver.a("www.test.postalserver.io").sort).to eq ["1.2.3.4", "2.3.4.5"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#aaaa" do
|
||||
it "returns a list of IP addresses" do
|
||||
expect(resolver.aaaa("www.test.postalserver.io").sort).to eq ["2a00:67a0:a::1", "2a00:67a0:a::2"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#txt" do
|
||||
it "returns a list of TXT records" do
|
||||
expect(resolver.txt("test.postalserver.io").sort).to eq [
|
||||
"an example txt record",
|
||||
"another example"
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#cname" do
|
||||
it "returns a list of CNAME records" do
|
||||
expect(resolver.cname("cname.test.postalserver.io")).to eq ["www.test.postalserver.io"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#mx" do
|
||||
it "returns a list of MX records" do
|
||||
expect(resolver.mx("test.postalserver.io")).to eq [
|
||||
[10, "mx1.test.postalserver.io"],
|
||||
[20, "mx2.test.postalserver.io"]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#effective_ns" do
|
||||
it "returns the nameserver names that are authoritative for the given domain" do
|
||||
expect(resolver.effective_ns("postalserver.io").sort).to eq [
|
||||
"prestigious-honeybadger.katapultdns.com",
|
||||
"the-cake-is-a-lie.katapultdns.com"
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ip_to_hostname" do
|
||||
it "returns the hostname for the given IP" do
|
||||
expect(resolver.ip_to_hostname("151.252.1.100")).to eq "ns1.katapultdns.com"
|
||||
end
|
||||
end
|
||||
|
||||
describe ".for_domain" do
|
||||
it "finds the effective nameservers for a given domain and returns them" do
|
||||
resolver = described_class.for_domain("test.postalserver.io")
|
||||
expect(resolver.nameservers.sort).to eq ["151.252.1.100", "151.252.2.100"]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".local" do
|
||||
it "returns a resolver with no nameservers" do
|
||||
resolver = described_class.local
|
||||
expect(resolver.nameservers).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
context "when using a resolver for a domain" do
|
||||
subject(:resolver) { described_class.for_domain("test.postalserver.io") }
|
||||
|
||||
it "will not return domains that are not hosted on that server" do
|
||||
expect(resolver.a("example.com")).to eq []
|
||||
end
|
||||
end
|
||||
end
|
||||
18
spec/lib/message_dequeuer_spec.rb
Normal file
18
spec/lib/message_dequeuer_spec.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe MessageDequeuer do
|
||||
describe ".process" do
|
||||
it "calls the initial process with the given message and logger" do
|
||||
message = create(:queued_message)
|
||||
logger = TestLogger.new
|
||||
|
||||
mock = double("InitialProcessor")
|
||||
expect(mock).to receive(:process).with(no_args)
|
||||
expect(MessageDequeuer::InitialProcessor).to receive(:new).with(message, logger: logger).and_return(mock)
|
||||
|
||||
described_class.process(message, logger: logger)
|
||||
end
|
||||
end
|
||||
end
|
||||
44
spec/lib/query_string_spec.rb
Normal file
44
spec/lib/query_string_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe QueryString do
|
||||
it "works with a single item" do
|
||||
qs = described_class.new("to: test@example.com")
|
||||
expect(qs.hash["to"]).to eq "test@example.com"
|
||||
end
|
||||
|
||||
it "works with a multiple items" do
|
||||
qs = described_class.new("to: test@example.com from: another@example.com")
|
||||
expect(qs.hash["to"]).to eq "test@example.com"
|
||||
expect(qs.hash["from"]).to eq "another@example.com"
|
||||
end
|
||||
|
||||
it "does not require a space after the field name" do
|
||||
qs = described_class.new("to:test@example.com from:another@example.com")
|
||||
expect(qs.hash["to"]).to eq "test@example.com"
|
||||
expect(qs.hash["from"]).to eq "another@example.com"
|
||||
end
|
||||
|
||||
it "returns nil when it receives blank" do
|
||||
qs = described_class.new("to:[blank]")
|
||||
expect(qs.hash["to"]).to eq nil
|
||||
end
|
||||
|
||||
it "handles dates with spaces" do
|
||||
qs = described_class.new("date: 2017-02-12 15:20")
|
||||
expect(qs.hash["date"]).to eq("2017-02-12 15:20")
|
||||
end
|
||||
|
||||
it "returns an array for multiple items" do
|
||||
qs = described_class.new("to: test@example.com to: another@example.com")
|
||||
expect(qs.hash["to"]).to be_a(Array)
|
||||
expect(qs.hash["to"][0]).to eq "test@example.com"
|
||||
expect(qs.hash["to"][1]).to eq "another@example.com"
|
||||
end
|
||||
|
||||
it "works with a z in the string" do
|
||||
qs = described_class.new("to: testaz@example.com")
|
||||
expect(qs.hash["to"]).to eq "testaz@example.com"
|
||||
end
|
||||
end
|
||||
المرجع في مشكلة جديدة
حظر مستخدم