مراية لـ
https://github.com/postalserver/postal.git
تم المزامنة 2026-01-17 13:39:46 +00:00
test: add test for dkim header generation
هذا الالتزام موجود في:
35
spec/lib/postal/dkim_header_spec.rb
Normal file
35
spec/lib/postal/dkim_header_spec.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Postal::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.load(frontmatter)
|
||||
email.strip
|
||||
it "works with #{path.split('/').first}" 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; " \
|
||||
"d=#{frontmatter['domain']}; s=#{frontmatter['dkim_identifier']}; t=#{mocked_time.to_i}; " \
|
||||
"bh=#{frontmatter['bh']}; "\
|
||||
"h=#{frontmatter['headers']}; " \
|
||||
"b=#{frontmatter['b']}"
|
||||
|
||||
header = described_class.new(domain, email)
|
||||
|
||||
expect(header.dkim_header).to eq expectation
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
المرجع في مشكلة جديدة
حظر مستخدم