require 'test_helper' module Dkim class CanonicalizationTest < Minitest::Test # from section 3.4.6 of RFC 6376 def setup @input = <<-eos.rfc_format A: X B : Y Z C D E eos @mail = SignedMail.new(@input) @mail.signable_headers = ['A', 'B'] end def test_relaxed_header @mail.header_canonicalization = 'relaxed' expected_header = <<-eos.rfc_format a:X b:Y Z eos assert_equal expected_header, @mail.canonical_header end def test_relaxed_body @mail.body_canonicalization = 'relaxed' expected_body = <<-eos.rfc_format C D E eos assert_equal expected_body, @mail.canonical_body end def test_simple_header @mail.header_canonicalization = 'simple' expected_header = <<-eos.rfc_format A: X B : Y Z eos assert_equal expected_header, @mail.canonical_header end def test_simple_body @mail.body_canonicalization = 'simple' expected_body = <<-eos.rfc_format C D E eos assert_equal expected_body, @mail.canonical_body end # from errata: empty bodies def test_simple_empty_body @mail = SignedMail.new("test: test\r\n\r\n") @mail.body_canonicalization = 'simple' assert_equal "\r\n", @mail.canonical_body end def test_relaxed_empty_body @mail = SignedMail.new("test: test\r\n\r\n") @mail.body_canonicalization = 'relaxed' assert_equal "", @mail.canonical_body end def test_relaxed_errata_1384 body = "testing".rfc_format @mail = SignedMail.new("test: test\r\n\r\n#{body}") @mail.body_canonicalization = 'relaxed' assert_equal "testing\r\n", @mail.canonical_body end end end