Sha256: 575aa1f545de84b56fca24682e1ba4e74cdabcbb64877901be4bf2a7adee1d2a

Contents?: true

Size: 1.97 KB

Versions: 3

Compression:

Stored size: 1.97 KB

Contents

require 'test_helper'

class CanonicalizationTest < Test::Unit::TestCase
  # from section 3.4.6 of rfc4871
  def setup
    @input = <<-eos.rfc_format
      A: <SP> X <CRLF>
      B <SP> : <SP> Y <HTAB><CRLF>
      <HTAB> Z <SP><SP><CRLF>
      <CRLF>
      <SP> C <SP><CRLF>
      D <SP><HTAB><SP> E <CRLF>
      <CRLF>
      <CRLF>
    eos
    @mail = Dkim::SignedMail.new(@input)
    @mail.signable_headers = ['A', 'B']
  end
  def test_relaxed_header
    @mail.header_canonicalization = 'relaxed'
    expected_header = <<-eos.rfc_format
      a:X <CRLF>
      b:Y <SP> Z <CRLF>
    eos
    assert_equal expected_header, @mail.canonical_header
  end
  def test_relaxed_body
    @mail.body_canonicalization = 'relaxed'
    expected_body = <<-eos.rfc_format
      <SP> C <CRLF>
      D <SP> E <CRLF>
    eos
    assert_equal expected_body, @mail.canonical_body
  end

  def test_simple_header
    @mail.header_canonicalization = 'simple'
    expected_header = <<-eos.rfc_format
      A: <SP> X <CRLF>
      B <SP> : <SP> Y <HTAB><CRLF>
      <HTAB> Z <SP><SP><CRLF>
    eos
    assert_equal expected_header, @mail.canonical_header
  end
  def test_simple_body
    @mail.body_canonicalization = 'simple'
    expected_body = <<-eos.rfc_format
      <SP> C <SP><CRLF>
      D <SP><HTAB><SP> E <CRLF>
    eos
    assert_equal expected_body, @mail.canonical_body
  end

  # from errata: empty bodies
  def test_simple_empty_body
    @mail = Dkim::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 = Dkim::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<crlf><sp><sp><cr><lf><cr><lf>".rfc_format
    @mail = Dkim::SignedMail.new("test: test\r\n\r\n#{body}")
    @mail.body_canonicalization = 'relaxed'

    assert_equal "testing\r\n", @mail.canonical_body
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dkim-0.1.0 test/canonicalization_test.rb
dkim-0.0.3 test/canonicalization_test.rb
dkim-0.0.2 test/canonicalization_test.rb