~ubuntu-branches/ubuntu/hardy/ruby1.8/hardy-updates

« back to all changes in this revision

Viewing changes to test/uri/test_mailto.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test/unit'
 
2
require 'uri/mailto'
 
3
 
 
4
module URI
 
5
 
 
6
 
 
7
class TestMailTo < Test::Unit::TestCase
 
8
  def setup
 
9
    @u = URI::MailTo
 
10
  end
 
11
 
 
12
  def teardown
 
13
  end
 
14
 
 
15
  def uri_to_ary(uri)
 
16
    uri.class.component.collect {|c| uri.send(c)}
 
17
  end
 
18
 
 
19
  def test_build
 
20
    ok = []
 
21
    bad = []
 
22
 
 
23
    # RFC2368, 6. Examples
 
24
    # mailto:chris@example.com
 
25
    ok << ["mailto:chris@example.com"]
 
26
    ok[-1] << ["chris@example.com", nil]
 
27
    ok[-1] << {:to => "chris@example.com"}
 
28
 
 
29
    # mailto:infobot@example.com?subject=current-issue
 
30
    ok << ["mailto:infobot@example.com?subject=current-issue"]
 
31
    ok[-1] << ["infobot@example.com", ["subject=current-issue"]]
 
32
    ok[-1] << {:to => "infobot@example.com", 
 
33
      :headers => ["subject=current-issue"]}
 
34
 
 
35
    # mailto:infobot@example.com?body=send%20current-issue
 
36
    ok << ["mailto:infobot@example.com?body=send%20current-issue"]
 
37
    ok[-1] << ["infobot@example.com", ["body=send%20current-issue"]]
 
38
    ok[-1] << {:to => "infobot@example.com", 
 
39
      :headers => ["body=send%20current-issue"]}
 
40
 
 
41
    # mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index
 
42
    ok << ["mailto:infobot@example.com?body=send%20current-issue%0D%0Asend%20index"]
 
43
    ok[-1] << ["infobot@example.com", 
 
44
      ["body=send%20current-issue%0D%0Asend%20index"]]
 
45
    ok[-1] << {:to => "infobot@example.com", 
 
46
      :headers => ["body=send%20current-issue%0D%0Asend%20index"]}
 
47
 
 
48
    # mailto:foobar@example.com?In-Reply-To=%3c3469A91.D10AF4C@example.com
 
49
    ok << ["mailto:foobar@example.com?In-Reply-To=%3c3469A91.D10AF4C@example.com"]
 
50
    ok[-1] << ["foobar@example.com", 
 
51
      ["In-Reply-To=%3c3469A91.D10AF4C@example.com"]]
 
52
    ok[-1] << {:to => "foobar@example.com", 
 
53
      :headers => ["In-Reply-To=%3c3469A91.D10AF4C@example.com"]}
 
54
 
 
55
    # mailto:majordomo@example.com?body=subscribe%20bamboo-l
 
56
    ok << ["mailto:majordomo@example.com?body=subscribe%20bamboo-l"]
 
57
    ok[-1] << ["majordomo@example.com", ["body=subscribe%20bamboo-l"]]
 
58
    ok[-1] << {:to => "majordomo@example.com", 
 
59
      :headers => ["body=subscribe%20bamboo-l"]}
 
60
 
 
61
    # mailto:joe@example.com?cc=bob@example.com&body=hello
 
62
    ok << ["mailto:joe@example.com?cc=bob@example.com&body=hello"]
 
63
    ok[-1] << ["joe@example.com", ["cc=bob@example.com", "body=hello"]]
 
64
    ok[-1] << {:to => "joe@example.com", 
 
65
      :headers => ["cc=bob@example.com", "body=hello"]}
 
66
 
 
67
    # mailto:?to=joe@example.com&cc=bob@example.com&body=hello
 
68
    ok << ["mailto:?to=joe@example.com&cc=bob@example.com&body=hello"]
 
69
    ok[-1] << [nil, 
 
70
      ["to=joe@example.com", "cc=bob@example.com", "body=hello"]]
 
71
    ok[-1] << {:headers => ["to=joe@example.com", 
 
72
        "cc=bob@example.com", "body=hello"]}
 
73
 
 
74
    # mailto:gorby%25kremvax@example.com
 
75
    ok << ["mailto:gorby%25kremvax@example.com"]
 
76
    ok[-1] << ["gorby%25kremvax@example.com", nil]
 
77
    ok[-1] << {:to => "gorby%25kremvax@example.com"}
 
78
 
 
79
    # mailto:unlikely%3Faddress@example.com?blat=foop
 
80
    ok << ["mailto:unlikely%3Faddress@example.com?blat=foop"]
 
81
    ok[-1] << ["unlikely%3Faddress@example.com", ["blat=foop"]]
 
82
    ok[-1] << {:to => "unlikely%3Faddress@example.com", 
 
83
      :headers => ["blat=foop"]}
 
84
 
 
85
    ok_all = ok.flatten.join("\0")
 
86
 
 
87
    # mailto:joe@example.com?cc=bob@example.com?body=hello   ; WRONG!
 
88
    bad << ["joe@example.com", ["cc=bob@example.com?body=hello"]]
 
89
 
 
90
    # mailto:javascript:alert()
 
91
    bad << ["javascript:alert()", []]
 
92
 
 
93
    # '=' which is in hname or hvalue is wrong.
 
94
    bad << ["foo@example.jp?subject=1+1=2", []]
 
95
 
 
96
    ok.each do |x|
 
97
      assert_equal(x[0],
 
98
                   @u.build(x[1]).to_s)
 
99
      assert_equal(x[0],
 
100
                   @u.build(x[2]).to_s)
 
101
    end
 
102
 
 
103
    bad.each do |x|
 
104
      assert_raises(URI::InvalidComponentError) {
 
105
        @u.build(x)
 
106
      }
 
107
    end
 
108
 
 
109
    assert_equal(ok_all, ok.flatten.join("\0"))
 
110
  end
 
111
 
 
112
  def test_select
 
113
    u = URI.parse('mailto:joe@example.com?cc=bob@example.com&body=hello')
 
114
    assert_equal(uri_to_ary(u), u.select(*u.component))
 
115
    assert_raises(ArgumentError) do
 
116
      u.select(:scheme, :host, :not_exist, :port)
 
117
    end
 
118
  end
 
119
end
 
120
 
 
121
 
 
122
end