rufus-verbs 0.10 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +64 -0
 - data/CREDITS.txt +9 -0
 - data/LICENSE.txt +21 -0
 - data/README.txt +4 -4
 - data/Rakefile +80 -0
 - data/doc/rdoc-style.css +320 -0
 - data/lib/rufus-verbs.rb +3 -0
 - data/lib/rufus/verbs.rb +67 -76
 - data/lib/rufus/verbs/conditional.rb +78 -88
 - data/lib/rufus/verbs/cookies.rb +214 -224
 - data/lib/rufus/verbs/digest.rb +173 -182
 - data/lib/rufus/verbs/endpoint.rb +496 -502
 - data/lib/rufus/verbs/verbose.rb +52 -61
 - data/lib/rufus/verbs/version.rb +6 -16
 - data/rufus-verbs.gemspec +87 -0
 - data/test/auth0_test.rb +22 -25
 - data/test/auth1_test.rb +1 -4
 - data/test/base.rb +56 -0
 - data/test/block_test.rb +25 -27
 - data/test/conditional_test.rb +24 -26
 - data/test/cookie0_test.rb +98 -100
 - data/test/cookie1_test.rb +28 -30
 - data/test/dryrun_test.rb +53 -40
 - data/test/escape_test.rb +16 -18
 - data/test/fopen_test.rb +31 -33
 - data/test/https_test.rb +19 -22
 - data/test/iconditional_test.rb +36 -38
 - data/test/items.rb +189 -189
 - data/test/proxy_test.rb +53 -55
 - data/test/redir_test.rb +16 -18
 - data/test/simple_test.rb +77 -82
 - data/test/test.rb +22 -26
 - data/test/timeout_test.rb +15 -19
 - data/test/uri_test.rb +12 -14
 - metadata +38 -17
 - data/test/testbase.rb +0 -47
 
    
        data/test/conditional_test.rb
    CHANGED
    
    | 
         @@ -7,43 +7,41 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            # Wed Jan 16 13:54:36 JST 2008
         
     | 
| 
       8 
8 
     | 
    
         
             
            #
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            require 'test/unit'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'testbase'
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            require ' 
     | 
| 
      
 11 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/base.rb'
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
14 
     | 
    
         
             
            class ConditionalTest < Test::Unit::TestCase
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
              include TestBaseMixin
         
     | 
| 
       18 
16 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              include Rufus::Verbs
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
19 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
              def test_1
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
                ep = ConditionalEndPoint.new(:host => "localhost", :port => 7777)
         
     | 
| 
      
 23 
     | 
    
         
            +
                expect 200, {}, ep.get(:resource => "items")
         
     | 
| 
       26 
24 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                res = ep.put :resource => "items", :id => 0 do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  "blockdata"
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal 404, res.code.to_i
         
     | 
| 
       31 
29 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                res = ep.post :resource => "items", :id => 0 do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  "blockdata"
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal 201, res.code.to_i
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_equal "http://localhost:7777/items/0", res['Location']
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
                res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_kind_of Net::HTTPResponse, res
         
     | 
| 
      
 38 
     | 
    
         
            +
                assert_respond_to res, :lastmod
         
     | 
| 
      
 39 
     | 
    
         
            +
                i = res.object_id
         
     | 
| 
      
 40 
     | 
    
         
            +
                #p res.to_hash
         
     | 
| 
       43 
41 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                res = expect 200, { 0 => "blockdata" }, ep.get(:res => "items")
         
     | 
| 
      
 43 
     | 
    
         
            +
                assert_equal i, res.object_id
         
     | 
| 
       46 
44 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal 1, ep.cache_current_size
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
       49 
47 
     | 
    
         
             
            end
         
     | 
    
        data/test/cookie0_test.rb
    CHANGED
    
    | 
         @@ -7,139 +7,137 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            # Sat Jan 19 18:22:48 JST 2008
         
     | 
| 
       8 
8 
     | 
    
         
             
            #
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            require 'test/unit'
         
     | 
| 
       11 
     | 
    
         
            -
            #require 'testbase'
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            require ' 
     | 
| 
       14 
     | 
    
         
            -
            require 'rufus/verbs/cookies'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/base.rb'
         
     | 
| 
      
 12 
     | 
    
         
            +
            #require 'rufus/verbs/cookies'
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
14 
     | 
    
         | 
| 
       17 
15 
     | 
    
         
             
            class Cookie0Test < Test::Unit::TestCase
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
              #include TestBaseMixin
         
     | 
| 
       19 
17 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 18 
     | 
    
         
            +
              include Rufus::Verbs::CookieMixin
         
     | 
| 
      
 19 
     | 
    
         
            +
              include Rufus::Verbs::HostMixin
         
     | 
| 
       22 
20 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
              #
         
     | 
| 
      
 22 
     | 
    
         
            +
              # testing split_host(s)
         
     | 
| 
      
 23 
     | 
    
         
            +
              #
         
     | 
| 
      
 24 
     | 
    
         
            +
              def test_0
         
     | 
| 
       27 
25 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                assert_equal [ 'localhost', nil ], split_host('localhost')
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal [ 'benz', '.car.co.nz' ], split_host('benz.car.co.nz')
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal [ '127.0.0.1', nil ], split_host('127.0.0.1')
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal [ '::1', nil ], split_host('::1')
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
              #
         
     | 
| 
      
 33 
     | 
    
         
            +
              # testing the CookieJar
         
     | 
| 
      
 34 
     | 
    
         
            +
              #
         
     | 
| 
      
 35 
     | 
    
         
            +
              def test_1
         
     | 
| 
       38 
36 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 37 
     | 
    
         
            +
                cookie0 = TestCookie.new
         
     | 
| 
      
 38 
     | 
    
         
            +
                cookie1 = TestCookie.new
         
     | 
| 
       41 
39 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                jar = Rufus::Verbs::CookieJar.new 77
         
     | 
| 
      
 41 
     | 
    
         
            +
                assert_equal 0, jar.size
         
     | 
| 
       44 
42 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
      
 43 
     | 
    
         
            +
                jar.add_cookie(".rubyforge.org", "/", cookie0)
         
     | 
| 
      
 44 
     | 
    
         
            +
                assert_equal 1, jar.size
         
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
         
     | 
| 
       48 
46 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 47 
     | 
    
         
            +
                jar.add_cookie("rufus.rubyforge.org", "/sub", cookie1)
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal 2, jar.size
         
     | 
| 
      
 49 
     | 
    
         
            +
                assert_equal [ cookie1, cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/sub/0")
         
     | 
| 
      
 50 
     | 
    
         
            +
                assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/main")
         
     | 
| 
      
 51 
     | 
    
         
            +
                assert_equal [ cookie0 ], jar.fetch_cookies("rufus.rubyforge.org", "/")
         
     | 
| 
       54 
52 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
                jar.remove_cookie("rufus.rubyforge.org", "/sub", cookie1)
         
     | 
| 
      
 54 
     | 
    
         
            +
                assert_equal 1, jar.size
         
     | 
| 
      
 55 
     | 
    
         
            +
              end
         
     | 
| 
       58 
56 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
      
 57 
     | 
    
         
            +
              #
         
     | 
| 
      
 58 
     | 
    
         
            +
              # testing cookie_acceptable?(opts, cookie)
         
     | 
| 
      
 59 
     | 
    
         
            +
              #
         
     | 
| 
      
 60 
     | 
    
         
            +
              def test_2
         
     | 
| 
       63 
61 
     | 
    
         | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
                jar = Rufus::Verbs::CookieJar.new 77
         
     | 
| 
       65 
63 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                opts = { :host => 'rufus.rubyforge.org', :path => '/' }
         
     | 
| 
      
 65 
     | 
    
         
            +
                c = TestCookie.new '.rubyforge.org', '/'
         
     | 
| 
      
 66 
     | 
    
         
            +
                r = TestResponse.new opts
         
     | 
| 
      
 67 
     | 
    
         
            +
                assert cookie_acceptable?(opts, r, c)
         
     | 
| 
       70 
68 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 69 
     | 
    
         
            +
                # * The value for the Domain attribute contains no embedded dots
         
     | 
| 
      
 70 
     | 
    
         
            +
                #   or does not start with a dot.
         
     | 
| 
       73 
71 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
                opts = { :host => 'rufus.rubyforge.org', :path => '/' }
         
     | 
| 
      
 73 
     | 
    
         
            +
                c = TestCookie.new 'rufus.rubyforge.org', '/'
         
     | 
| 
      
 74 
     | 
    
         
            +
                r = TestResponse.new opts
         
     | 
| 
      
 75 
     | 
    
         
            +
                assert ! cookie_acceptable?(opts, r, c)
         
     | 
| 
       78 
76 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
      
 77 
     | 
    
         
            +
                opts = { :host => 'rufus.rubyforge.org', :path => '/' }
         
     | 
| 
      
 78 
     | 
    
         
            +
                c = TestCookie.new 'org', '/'
         
     | 
| 
      
 79 
     | 
    
         
            +
                r = TestResponse.new opts
         
     | 
| 
      
 80 
     | 
    
         
            +
                assert ! cookie_acceptable?(opts, r, c)
         
     | 
| 
       83 
81 
     | 
    
         | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
      
 82 
     | 
    
         
            +
                # * The value for the Path attribute is not a prefix of the 
         
     | 
| 
      
 83 
     | 
    
         
            +
                #   request-URI.
         
     | 
| 
       86 
84 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                opts = { :host => 'rufus.rubyforge.org', :path => '/this' }
         
     | 
| 
      
 86 
     | 
    
         
            +
                c = TestCookie.new '.rubyforge.org', '/that'
         
     | 
| 
      
 87 
     | 
    
         
            +
                r = TestResponse.new opts
         
     | 
| 
      
 88 
     | 
    
         
            +
                assert ! cookie_acceptable?(opts, r, c)
         
     | 
| 
       91 
89 
     | 
    
         | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 90 
     | 
    
         
            +
                # * The value for the request-host does not domain-match the 
         
     | 
| 
      
 91 
     | 
    
         
            +
                #   Domain attribute.
         
     | 
| 
       94 
92 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
                opts = { :host => 'rufus.rubyforg.org', :path => '/' }
         
     | 
| 
      
 94 
     | 
    
         
            +
                c = TestCookie.new '.rubyforge.org', '/'
         
     | 
| 
      
 95 
     | 
    
         
            +
                r = TestResponse.new opts
         
     | 
| 
      
 96 
     | 
    
         
            +
                assert ! cookie_acceptable?(opts, r, c)
         
     | 
| 
       99 
97 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
                    
         
     | 
| 
       104 
     | 
    
         
            -
                    # implicit...
         
     | 
| 
       105 
     | 
    
         
            -
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
                # * The request-host is a FQDN (not IP address) and has the form
         
     | 
| 
      
 99 
     | 
    
         
            +
                #   HD, where D is the value of the Domain attribute, and H is a
         
     | 
| 
      
 100 
     | 
    
         
            +
                #   string that contains one or more dots.
         
     | 
| 
       106 
101 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                # 
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
                #    cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
         
     | 
| 
       110 
     | 
    
         
            -
                #    p WEBrick::Cookie.parse_set_cookie(cookie)
         
     | 
| 
       111 
     | 
    
         
            -
                #    p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
         
     | 
| 
       112 
     | 
    
         
            -
                #end
         
     | 
| 
      
 102 
     | 
    
         
            +
                # implicit...
         
     | 
| 
      
 103 
     | 
    
         
            +
              end
         
     | 
| 
       113 
104 
     | 
    
         | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
              #def test_webrick_cookie
         
     | 
| 
      
 106 
     | 
    
         
            +
              #  require 'webrick/cookie'
         
     | 
| 
      
 107 
     | 
    
         
            +
              #  cookie = "PREF=ID=18da97219de4985:TM=12007507:LM=12007507:S=Guc1JcA15ySZYl2n; expires=Mon, 18-Jan-2010 09:30:37 GMT; path=/; domain=.google.com"
         
     | 
| 
      
 108 
     | 
    
         
            +
              #  p WEBrick::Cookie.parse_set_cookie(cookie)
         
     | 
| 
      
 109 
     | 
    
         
            +
              #  p Rufus::Verbs::Cookie.parse_set_cookie(cookie)
         
     | 
| 
      
 110 
     | 
    
         
            +
              #end
         
     | 
| 
       115 
111 
     | 
    
         | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
      
 112 
     | 
    
         
            +
              protected
         
     | 
| 
       117 
113 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
      
 114 
     | 
    
         
            +
              class TestCookie
         
     | 
| 
       119 
115 
     | 
    
         | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
      
 116 
     | 
    
         
            +
                attr_reader :domain, :path, :name
         
     | 
| 
       121 
117 
     | 
    
         | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                            @path = path
         
     | 
| 
       124 
     | 
    
         
            -
                            @name = name
         
     | 
| 
       125 
     | 
    
         
            -
                        end
         
     | 
| 
       126 
     | 
    
         
            -
                    end
         
     | 
| 
      
 118 
     | 
    
         
            +
                def initialize (domain=nil, path=nil, name='whatever')
         
     | 
| 
       127 
119 
     | 
    
         | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
                  @domain = domain
         
     | 
| 
      
 121 
     | 
    
         
            +
                  @path = path
         
     | 
| 
      
 122 
     | 
    
         
            +
                  @name = name
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
              end
         
     | 
| 
       129 
125 
     | 
    
         | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
      
 126 
     | 
    
         
            +
              class TestResponse
         
     | 
| 
       131 
127 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
                        end
         
     | 
| 
      
 128 
     | 
    
         
            +
                def initialize (opts)
         
     | 
| 
       134 
129 
     | 
    
         | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
      
 130 
     | 
    
         
            +
                  @path = opts[:path]
         
     | 
| 
      
 131 
     | 
    
         
            +
                end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                def request
         
     | 
| 
       136 
134 
     | 
    
         | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
      
 135 
     | 
    
         
            +
                  r = Object.new
         
     | 
| 
      
 136 
     | 
    
         
            +
                  class << r
         
     | 
| 
      
 137 
     | 
    
         
            +
                    attr_accessor :path
         
     | 
| 
      
 138 
     | 
    
         
            +
                  end
         
     | 
| 
      
 139 
     | 
    
         
            +
                  r.path = @path
         
     | 
| 
      
 140 
     | 
    
         
            +
                  r
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
       145 
143 
     | 
    
         
             
            end
         
     | 
    
        data/test/cookie1_test.rb
    CHANGED
    
    | 
         @@ -7,54 +7,52 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            # Sun Jan 13 12:33:03 JST 2008
         
     | 
| 
       8 
8 
     | 
    
         
             
            #
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            require 'test/unit'
         
     | 
| 
       11 
     | 
    
         
            -
            require 'testbase'
         
     | 
| 
       12 
10 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            require ' 
     | 
| 
      
 11 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/base.rb'
         
     | 
| 
       14 
12 
     | 
    
         | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
14 
     | 
    
         
             
            class Cookie1Test < Test::Unit::TestCase
         
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
              include TestBaseMixin
         
     | 
| 
       18 
16 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 17 
     | 
    
         
            +
              include Rufus::Verbs
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
19 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
              def test_0
         
     | 
| 
       23 
21 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 22 
     | 
    
         
            +
                ep = EndPoint.new :cookies => true
         
     | 
| 
      
 23 
     | 
    
         
            +
                class << ep
         
     | 
| 
      
 24 
     | 
    
         
            +
                  attr_reader :cookies
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
       28 
26 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
                assert_equal 0, ep.cookies.size
         
     | 
| 
       30 
28 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
                ep.get :uri => "http://localhost:7777/cookie"
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert_equal 1, ep.cookies.size
         
     | 
| 
       33 
31 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
                req = ep.get :uri => "http://localhost:7777/cookie", :dry_run => true
         
     | 
| 
      
 33 
     | 
    
         
            +
                assert_match /^tcookie=\d*$/, req['Cookie']
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 36 
     | 
    
         
            +
              def test_1
         
     | 
| 
       39 
37 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                ep0 = EndPoint.new :cookies => true
         
     | 
| 
      
 39 
     | 
    
         
            +
                ep1 = EndPoint.new :cookies => true
         
     | 
| 
       42 
40 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 41 
     | 
    
         
            +
                ep0.post("http://localhost:7777/cookie") { "smurf0" }
         
     | 
| 
      
 42 
     | 
    
         
            +
                ep1.post("http://localhost:7777/cookie") { "smurf1" }
         
     | 
| 
       45 
43 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
                expect 200, [ 'smurf0' ], ep0.get("http://localhost:7777/cookie")
         
     | 
| 
      
 45 
     | 
    
         
            +
                expect 200, [ 'smurf1' ], ep1.get("http://localhost:7777/cookie")
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
       49 
47 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 48 
     | 
    
         
            +
              def test_2
         
     | 
| 
       51 
49 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
      
 50 
     | 
    
         
            +
                ep = EndPoint.new :cookies => false # explicitely
         
     | 
| 
       53 
51 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 52 
     | 
    
         
            +
                res0 = ep.post("http://localhost:7777/cookie") { "smurf0" }
         
     | 
| 
      
 53 
     | 
    
         
            +
                res1 = expect 200, [], ep.get("http://localhost:7777/cookie")
         
     | 
| 
       56 
54 
     | 
    
         | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                assert_not_equal res0['Set-Cookie'], res1['Set-Cookie']
         
     | 
| 
      
 56 
     | 
    
         
            +
              end
         
     | 
| 
       59 
57 
     | 
    
         
             
            end
         
     | 
| 
       60 
58 
     | 
    
         | 
    
        data/test/dryrun_test.rb
    CHANGED
    
    | 
         @@ -7,64 +7,77 @@ 
     | 
|
| 
       7 
7 
     | 
    
         
             
            # Tue Jan 15 09:26:45 JST 2008
         
     | 
| 
       8 
8 
     | 
    
         
             
            #
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            require 'test/unit'
         
     | 
| 
       11 
10 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            require ' 
     | 
| 
      
 11 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/base.rb'
         
     | 
| 
       13 
12 
     | 
    
         | 
| 
       14 
13 
     | 
    
         | 
| 
       15 
14 
     | 
    
         
             
            class DryRunTest < Test::Unit::TestCase
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
              include Rufus::Verbs
         
     | 
| 
       18 
17 
     | 
    
         | 
| 
       19 
18 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 19 
     | 
    
         
            +
              def test_0
         
     | 
| 
       21 
20 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
                req = put(
         
     | 
| 
      
 22 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 23 
     | 
    
         
            +
                  :uri => "http://localhost:7777/items/1",
         
     | 
| 
      
 24 
     | 
    
         
            +
                  :params => { "a" => "A", :b => :B })
         
     | 
| 
       26 
25 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                assert_equal "/items/1?a=A&b=B", req.path
         
     | 
| 
       28 
27 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
                req = post(
         
     | 
| 
      
 29 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 30 
     | 
    
         
            +
                  :uri => "http://localhost:7777/items/1",
         
     | 
| 
      
 31 
     | 
    
         
            +
                  :params => { "a" => "A", :b => :B })
         
     | 
| 
       33 
32 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
      
 33 
     | 
    
         
            +
                assert_equal "/items/1?a=A&b=B", req.path
         
     | 
| 
       35 
34 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                req = put(
         
     | 
| 
      
 36 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 37 
     | 
    
         
            +
                  :uri => "http://localhost:7777/items/1",
         
     | 
| 
      
 38 
     | 
    
         
            +
                  :query => { "a" => "A", :b => :B })
         
     | 
| 
       40 
39 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                assert_equal "/items/1?a=A&b=B", req.path
         
     | 
| 
       42 
41 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                req = put(
         
     | 
| 
      
 43 
     | 
    
         
            +
                  "http://localhost:7777/items/1?a=A", :d => "toto", :dry_run => true)
         
     | 
| 
       45 
44 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 45 
     | 
    
         
            +
                assert_equal "/items/1?a=A", req.path
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert_equal "toto", req.body
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
       49 
48 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
              def test_1
         
     | 
| 
       51 
50 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
      
 51 
     | 
    
         
            +
                ep = Rufus::Verbs::EndPoint.new(
         
     | 
| 
      
 52 
     | 
    
         
            +
                  :host => 'localhost',
         
     | 
| 
      
 53 
     | 
    
         
            +
                  :resource => 'whatever')
         
     | 
| 
       55 
54 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                req = ep.get(
         
     | 
| 
      
 56 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 57 
     | 
    
         
            +
                  :resource => 'other',
         
     | 
| 
      
 58 
     | 
    
         
            +
                  :params => { 'a' => 'A', 'b' => 'B' })
         
     | 
| 
       60 
59 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                assert_equal "/other?a=A&b=B", req.path
         
     | 
| 
       62 
61 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
      
 62 
     | 
    
         
            +
                req = ep.post(
         
     | 
| 
      
 63 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 64 
     | 
    
         
            +
                  :resource => 'other',
         
     | 
| 
      
 65 
     | 
    
         
            +
                  :query => { 'a' => 'A', 'b' => 'B' })
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                assert_equal "/other?a=A&b=B", req.path
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              def test_cgi_escape
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                ep = Rufus::Verbs::EndPoint.new(
         
     | 
| 
      
 73 
     | 
    
         
            +
                  :host => 'localhost',
         
     | 
| 
      
 74 
     | 
    
         
            +
                  :resource => 'whatever')
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                req = ep.post(
         
     | 
| 
      
 77 
     | 
    
         
            +
                  :dry_run => true,
         
     | 
| 
      
 78 
     | 
    
         
            +
                  :resource => 'other',
         
     | 
| 
      
 79 
     | 
    
         
            +
                  :query => { 'a' => 'A&A', 'b' => 'B?B' })
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                assert_equal "/other?a=A%26A&b=B%3FB", req.path
         
     | 
| 
      
 82 
     | 
    
         
            +
              end
         
     | 
| 
       70 
83 
     | 
    
         
             
            end
         
     |