rack-contrib-sign 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
 - data/lib/rack/contrib/sign.rb +1 -0
 - data/lib/rack/contrib/sign/middleware.rb +2 -0
 - data/lib/rack/contrib/sign/receipt.rb +16 -4
 - data/lib/rack/contrib/sign/version.rb +1 -1
 - data/spec/rack/contrib/sign/middleware_spec.rb +17 -5
 - data/spec/rack/contrib/sign/receipt_spec.rb +30 -6
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0f04f49f937e4e268755732df3b62e1fa36a0646
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: f93c5ed88d1dd26885d43014f1b25818a77e0617
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5152592a6cbcae4aa188c8fdd81cbe647a74dcd0bdc84898a8693e1624579edbb8fe2d7003d93c9c3442eccafd2f23f25a0fe7d64f25676e6a895a7625464cec
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: b6b67f84cadd35298807bb9136ef20c43cdb802b8061e72eb05102dfc39d93674e25fb34c405ab4ecf738d309d0fc8c6fc126fe014ab8d9a42fde35f39f7bc91
         
     | 
    
        data/lib/rack/contrib/sign.rb
    CHANGED
    
    
| 
         @@ -47,9 +47,11 @@ module Rack 
     | 
|
| 
       47 
47 
     | 
    
         
             
                    # Extract environmental data into a Receipt
         
     | 
| 
       48 
48 
     | 
    
         
             
                    def build_receipt env, credentials
         
     | 
| 
       49 
49 
     | 
    
         
             
                      receipt = Rack::Contrib::Sign::Receipt.new
         
     | 
| 
      
 50 
     | 
    
         
            +
                      receipt.host = env['rack.url_scheme'] + '://' + env['HTTP_HOST']
         
     | 
| 
       50 
51 
     | 
    
         
             
                      receipt.uri = env['REQUEST_URI']
         
     | 
| 
       51 
52 
     | 
    
         
             
                      receipt.request_method = env['REQUEST_METHOD']
         
     | 
| 
       52 
53 
     | 
    
         
             
                      receipt.body = extract_body env
         
     | 
| 
      
 54 
     | 
    
         
            +
                      receipt.content_type = env['HTTP_CONTENT_TYPE'] || ''
         
     | 
| 
       53 
55 
     | 
    
         | 
| 
       54 
56 
     | 
    
         
             
                      extract_headers(env).each { |h,v| receipt.headers[h] = v }
         
     | 
| 
       55 
57 
     | 
    
         | 
| 
         @@ -8,7 +8,9 @@ module Rack 
     | 
|
| 
       8 
8 
     | 
    
         
             
                    attr_accessor :api_key
         
     | 
| 
       9 
9 
     | 
    
         
             
                    attr_accessor :api_secret
         
     | 
| 
       10 
10 
     | 
    
         
             
                    attr_accessor :body
         
     | 
| 
      
 11 
     | 
    
         
            +
                    attr_accessor :content_type
         
     | 
| 
       11 
12 
     | 
    
         
             
                    attr_accessor :uri
         
     | 
| 
      
 13 
     | 
    
         
            +
                    attr_accessor :host
         
     | 
| 
       12 
14 
     | 
    
         | 
| 
       13 
15 
     | 
    
         
             
                    def initialize
         
     | 
| 
       14 
16 
     | 
    
         
             
                      @headers = {}
         
     | 
| 
         @@ -18,17 +20,27 @@ module Rack 
     | 
|
| 
       18 
20 
     | 
    
         
             
                      @request_method = s.upcase
         
     | 
| 
       19 
21 
     | 
    
         
             
                    end
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
      
 23 
     | 
    
         
            +
                    def body_md5
         
     | 
| 
      
 24 
     | 
    
         
            +
                      Digest::MD5.hexdigest(body)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                    def body_length
         
     | 
| 
      
 28 
     | 
    
         
            +
                      body.length
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       21 
31 
     | 
    
         
             
                    def to_s
         
     | 
| 
       22 
32 
     | 
    
         
             
                      preamble + header_text
         
     | 
| 
       23 
33 
     | 
    
         
             
                    end
         
     | 
| 
       24 
34 
     | 
    
         | 
| 
       25 
35 
     | 
    
         
             
                    def preamble
         
     | 
| 
       26 
36 
     | 
    
         
             
                      s = ""
         
     | 
| 
       27 
     | 
    
         
            -
                      s << "%s 
     | 
| 
      
 37 
     | 
    
         
            +
                      s << "%s\n" % request_method
         
     | 
| 
      
 38 
     | 
    
         
            +
                      s << "%s\n" % host
         
     | 
| 
      
 39 
     | 
    
         
            +
                      s << "%s\n" % uri
         
     | 
| 
       28 
40 
     | 
    
         
             
                      s << "%s\n" % api_key
         
     | 
| 
       29 
     | 
    
         
            -
                      s << "%s\n" %  
     | 
| 
       30 
     | 
    
         
            -
                      s << "%s\n" %  
     | 
| 
       31 
     | 
    
         
            -
                      s << " 
     | 
| 
      
 41 
     | 
    
         
            +
                      s << "%s\n" % content_type
         
     | 
| 
      
 42 
     | 
    
         
            +
                      s << "%s\n" % body_length
         
     | 
| 
      
 43 
     | 
    
         
            +
                      s << "%s\n" % body_md5
         
     | 
| 
       32 
44 
     | 
    
         
             
                      s
         
     | 
| 
       33 
45 
     | 
    
         
             
                    end
         
     | 
| 
       34 
46 
     | 
    
         | 
| 
         @@ -29,7 +29,10 @@ describe Rack::Contrib::Sign::Middleware do 
     | 
|
| 
       29 
29 
     | 
    
         
             
                it "sets various options" do
         
     | 
| 
       30 
30 
     | 
    
         
             
                  env = {
         
     | 
| 
       31 
31 
     | 
    
         
             
                    'REQUEST_METHOD' => 'POST',
         
     | 
| 
       32 
     | 
    
         
            -
                    ' 
     | 
| 
      
 32 
     | 
    
         
            +
                    'HTTP_HOST' => '127.0.0.1:9292',
         
     | 
| 
      
 33 
     | 
    
         
            +
                    'rack.url_scheme' => 'http',
         
     | 
| 
      
 34 
     | 
    
         
            +
                    'HTTP_CONTENT_TYPE' => 'text/plain',
         
     | 
| 
      
 35 
     | 
    
         
            +
                    'REQUEST_URI' => '/foo/bar',
         
     | 
| 
       33 
36 
     | 
    
         
             
                    'HTTP_HI_FOOO' => 'YIPEE',
         
     | 
| 
       34 
37 
     | 
    
         
             
                    'rack.input' => StringIO.new('foo=bar')
         
     | 
| 
       35 
38 
     | 
    
         
             
                  }
         
     | 
| 
         @@ -38,7 +41,9 @@ describe Rack::Contrib::Sign::Middleware do 
     | 
|
| 
       38 
41 
     | 
    
         | 
| 
       39 
42 
     | 
    
         
             
                  receipt = ware.build_receipt(env, creds)
         
     | 
| 
       40 
43 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                  receipt. 
     | 
| 
      
 44 
     | 
    
         
            +
                  receipt.host.should eq('http://127.0.0.1:9292')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  receipt.content_type.should eq('text/plain')
         
     | 
| 
      
 46 
     | 
    
         
            +
                  receipt.uri.should eq('/foo/bar')
         
     | 
| 
       42 
47 
     | 
    
         
             
                  receipt.request_method.should eq('POST')
         
     | 
| 
       43 
48 
     | 
    
         
             
                  receipt.body.should eq('foo=bar')
         
     | 
| 
       44 
49 
     | 
    
         
             
                  receipt.api_key.should eq('123')
         
     | 
| 
         @@ -130,6 +135,8 @@ describe Rack::Contrib::Sign::Middleware do 
     | 
|
| 
       130 
135 
     | 
    
         
             
                    env = {
         
     | 
| 
       131 
136 
     | 
    
         
             
                      'HTTP_AUTHORIZATION' => 'foo-bar 123:foo',
         
     | 
| 
       132 
137 
     | 
    
         
             
                      'REQUEST_METHOD' => '?',
         
     | 
| 
      
 138 
     | 
    
         
            +
                      'HTTP_HOST' => '127.0.0.1:9292',
         
     | 
| 
      
 139 
     | 
    
         
            +
                      'rack.url_scheme' => 'http',
         
     | 
| 
       133 
140 
     | 
    
         
             
                      'rack.input' => StringIO.new()
         
     | 
| 
       134 
141 
     | 
    
         
             
                    }
         
     | 
| 
       135 
142 
     | 
    
         | 
| 
         @@ -143,7 +150,9 @@ describe Rack::Contrib::Sign::Middleware do 
     | 
|
| 
       143 
150 
     | 
    
         
             
                    env = {
         
     | 
| 
       144 
151 
     | 
    
         
             
                      'HTTP_AUTHORIZATION' => 'foo-bar abc:YABBA DABBA DOOO',
         
     | 
| 
       145 
152 
     | 
    
         
             
                      'REQUEST_METHOD' => 'POST',
         
     | 
| 
       146 
     | 
    
         
            -
                      ' 
     | 
| 
      
 153 
     | 
    
         
            +
                      'HTTP_HOST' => '127.0.0.1:9292',
         
     | 
| 
      
 154 
     | 
    
         
            +
                      'rack.url_scheme' => 'http',
         
     | 
| 
      
 155 
     | 
    
         
            +
                      'REQUEST_URI' => '/foo/bar/baz',
         
     | 
| 
       147 
156 
     | 
    
         
             
                      'rack.input' => StringIO.new('foo=bar'),
         
     | 
| 
       148 
157 
     | 
    
         
             
                    }
         
     | 
| 
       149 
158 
     | 
    
         | 
| 
         @@ -154,9 +163,12 @@ describe Rack::Contrib::Sign::Middleware do 
     | 
|
| 
       154 
163 
     | 
    
         
             
                  it "works when I sign it right" do
         
     | 
| 
       155 
164 
     | 
    
         
             
                    cred_provider['123'] = 'abc'
         
     | 
| 
       156 
165 
     | 
    
         
             
                    env = {
         
     | 
| 
       157 
     | 
    
         
            -
                      'HTTP_AUTHORIZATION' => 'foo-bar 123: 
     | 
| 
      
 166 
     | 
    
         
            +
                      'HTTP_AUTHORIZATION' => 'foo-bar 123:75e8d7d1c4eeb07a049f9f7c1395aa2e61e5a879',
         
     | 
| 
       158 
167 
     | 
    
         
             
                      'REQUEST_METHOD' => 'POST',
         
     | 
| 
       159 
     | 
    
         
            -
                      ' 
     | 
| 
      
 168 
     | 
    
         
            +
                      'HTTP_HOST' => '127.0.0.1:9292',
         
     | 
| 
      
 169 
     | 
    
         
            +
                      'HTTP_CONTENT_TYPE' => 'text/plain',
         
     | 
| 
      
 170 
     | 
    
         
            +
                      'rack.url_scheme' => 'http',
         
     | 
| 
      
 171 
     | 
    
         
            +
                      'REQUEST_URI' => '/foo/bar/baz',
         
     | 
| 
       160 
172 
     | 
    
         
             
                      'rack.input' => StringIO.new('foo=bar'),
         
     | 
| 
       161 
173 
     | 
    
         
             
                      'HTTP_HI_FOOOO' => 'aoenuoneuh',
         
     | 
| 
       162 
174 
     | 
    
         
             
                      'HTTP_BYE_FOOO' => 'oeucorgcgc'
         
     | 
| 
         @@ -9,8 +9,12 @@ describe Rack::Contrib::Sign::Receipt do 
     | 
|
| 
       9 
9 
     | 
    
         
             
              it { should respond_to(:api_secret=) }
         
     | 
| 
       10 
10 
     | 
    
         
             
              it { should respond_to(:body) }
         
     | 
| 
       11 
11 
     | 
    
         
             
              it { should respond_to(:body=) }
         
     | 
| 
      
 12 
     | 
    
         
            +
              it { should respond_to(:content_type) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              it { should respond_to(:content_type=) }
         
     | 
| 
       12 
14 
     | 
    
         
             
              it { should respond_to(:request_method) }
         
     | 
| 
       13 
15 
     | 
    
         
             
              it { should respond_to(:request_method=) }
         
     | 
| 
      
 16 
     | 
    
         
            +
              it { should respond_to(:host) }
         
     | 
| 
      
 17 
     | 
    
         
            +
              it { should respond_to(:host=) }
         
     | 
| 
       14 
18 
     | 
    
         
             
              it { should respond_to(:uri) }
         
     | 
| 
       15 
19 
     | 
    
         
             
              it { should respond_to(:uri=) }
         
     | 
| 
       16 
20 
     | 
    
         
             
              it { should respond_to(:headers) }
         
     | 
| 
         @@ -22,6 +26,22 @@ describe Rack::Contrib::Sign::Receipt do 
     | 
|
| 
       22 
26 
     | 
    
         
             
                end
         
     | 
| 
       23 
27 
     | 
    
         
             
              end
         
     | 
| 
       24 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
              describe "#body_md5" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                it "returns the md5 of the body" do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  receipt.body = 'herro'
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                  receipt.body_md5.should eq("18f1072de45420e57fd22ee5bd59df9e")
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              describe "#body_length" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                it "returns the length of the body" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  receipt.body = 'herro'
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                  receipt.body_length.should eq(5)
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       25 
45 
     | 
    
         
             
              describe "#headers" do
         
     | 
| 
       26 
46 
     | 
    
         
             
                it "defaults to an empty hash" do
         
     | 
| 
       27 
47 
     | 
    
         
             
                  receipt.headers.should eq({})
         
     | 
| 
         @@ -43,18 +63,22 @@ describe Rack::Contrib::Sign::Receipt do 
     | 
|
| 
       43 
63 
     | 
    
         
             
              describe "#preamble" do
         
     | 
| 
       44 
64 
     | 
    
         
             
                it "incorporates all the preamble elements in a string block" do
         
     | 
| 
       45 
65 
     | 
    
         
             
                  receipt.api_key = 'abc'
         
     | 
| 
       46 
     | 
    
         
            -
                  receipt.api_secret = '123'
         
     | 
| 
       47 
66 
     | 
    
         
             
                  receipt.body = 'foo=bar'
         
     | 
| 
       48 
67 
     | 
    
         
             
                  receipt.request_method = 'post'
         
     | 
| 
       49 
     | 
    
         
            -
                  receipt. 
     | 
| 
      
 68 
     | 
    
         
            +
                  receipt.host = 'http://example.com'
         
     | 
| 
      
 69 
     | 
    
         
            +
                  receipt.uri = '/123?foo=bar'
         
     | 
| 
      
 70 
     | 
    
         
            +
                  receipt.content_type = "text/json"
         
     | 
| 
       50 
71 
     | 
    
         | 
| 
       51 
72 
     | 
    
         
             
                  returned = receipt.preamble
         
     | 
| 
       52 
73 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                  r = " 
     | 
| 
      
 74 
     | 
    
         
            +
                  r = ""
         
     | 
| 
      
 75 
     | 
    
         
            +
                  r << "POST\n"
         
     | 
| 
      
 76 
     | 
    
         
            +
                  r << "http://example.com\n"
         
     | 
| 
      
 77 
     | 
    
         
            +
                  r << "/123?foo=bar\n"
         
     | 
| 
       54 
78 
     | 
    
         
             
                  r << "abc\n"
         
     | 
| 
       55 
     | 
    
         
            -
                  r << " 
     | 
| 
       56 
     | 
    
         
            -
                  r << " 
     | 
| 
       57 
     | 
    
         
            -
                  r << " 
     | 
| 
      
 79 
     | 
    
         
            +
                  r << "text/json\n"
         
     | 
| 
      
 80 
     | 
    
         
            +
                  r << "7\n"
         
     | 
| 
      
 81 
     | 
    
         
            +
                  r << "06ad47d8e64bd28de537b62ff85357c4\n"
         
     | 
| 
       58 
82 
     | 
    
         | 
| 
       59 
83 
     | 
    
         
             
                  returned.should eq(r)
         
     | 
| 
       60 
84 
     | 
    
         
             
                end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: rack-contrib-sign
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Graham Christensen
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2013-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-07-29 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     |