crashlog-auth-hmac 1.1.2 → 1.1.3
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/.gitignore +0 -1
- data/.travis.yml +12 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +32 -0
- data/README.md +2 -0
- data/lib/crash_log.rb +2 -1
- data/lib/crash_log/auth_hmac.rb +10 -4
- data/lib/crash_log/auth_hmac/version.rb +1 -1
- data/spec/crash_log/auth_hmac_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    CHANGED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,32 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                crashlog-auth-hmac (1.1.2)
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            GEM
         | 
| 7 | 
            +
              remote: https://rubygems.org/
         | 
| 8 | 
            +
              specs:
         | 
| 9 | 
            +
                activesupport (3.2.7)
         | 
| 10 | 
            +
                  i18n (~> 0.6)
         | 
| 11 | 
            +
                  multi_json (~> 1.0)
         | 
| 12 | 
            +
                diff-lcs (1.1.3)
         | 
| 13 | 
            +
                i18n (0.6.0)
         | 
| 14 | 
            +
                multi_json (1.3.6)
         | 
| 15 | 
            +
                rake (0.9.2.2)
         | 
| 16 | 
            +
                rspec (2.11.0)
         | 
| 17 | 
            +
                  rspec-core (~> 2.11.0)
         | 
| 18 | 
            +
                  rspec-expectations (~> 2.11.0)
         | 
| 19 | 
            +
                  rspec-mocks (~> 2.11.0)
         | 
| 20 | 
            +
                rspec-core (2.11.1)
         | 
| 21 | 
            +
                rspec-expectations (2.11.2)
         | 
| 22 | 
            +
                  diff-lcs (~> 1.1.3)
         | 
| 23 | 
            +
                rspec-mocks (2.11.1)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            PLATFORMS
         | 
| 26 | 
            +
              ruby
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            DEPENDENCIES
         | 
| 29 | 
            +
              activesupport (~> 3.2.0)
         | 
| 30 | 
            +
              crashlog-auth-hmac!
         | 
| 31 | 
            +
              rake
         | 
| 32 | 
            +
              rspec (>= 2.7.0)
         | 
    
        data/README.md
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            # Crashlog::AuthHMAC
         | 
| 2 2 |  | 
| 3 | 
            +
            [](http://travis-ci.org/crashlog/auth-hmac)
         | 
| 4 | 
            +
             | 
| 3 5 | 
             
            auth-hmac is a Ruby implementation of HMAC based authentication of HTTP requests.
         | 
| 4 6 |  | 
| 5 7 | 
             
            HMAC authentication involves a client and server having a shared secret key. When sending the request the client, signs the request using the secret key. This involves building a canonical representation of the request and then generating a HMAC of the request using the secret. The generated HMAC is then sent as part of the request.
         | 
    
        data/lib/crash_log.rb
    CHANGED
    
    
    
        data/lib/crash_log/auth_hmac.rb
    CHANGED
    
    | @@ -26,6 +26,8 @@ module CrashLog | |
| 26 26 | 
             
                  def headers(request)
         | 
| 27 27 | 
             
                    if request.respond_to?(:headers)
         | 
| 28 28 | 
             
                      request.headers
         | 
| 29 | 
            +
                    elsif request.is_a?(Hash) && request.has_key?(:request_headers)
         | 
| 30 | 
            +
                      request[:request_headers]
         | 
| 29 31 | 
             
                    elsif request.respond_to?(:[])
         | 
| 30 32 | 
             
                      request
         | 
| 31 33 | 
             
                    else
         | 
| @@ -71,6 +73,8 @@ module CrashLog | |
| 71 73 | 
             
                  def request_method(request)
         | 
| 72 74 | 
             
                    if request.respond_to?(:request_method) && request.request_method.is_a?(String)
         | 
| 73 75 | 
             
                      request.request_method
         | 
| 76 | 
            +
                    elsif request.is_a?(Hash) && request.has_key?(:method)
         | 
| 77 | 
            +
                      request[:method].to_s
         | 
| 74 78 | 
             
                    elsif request.respond_to?(:method) && request.method.is_a?(String)
         | 
| 75 79 | 
             
                      request.method
         | 
| 76 80 | 
             
                    elsif request.respond_to?(:env) && request.env
         | 
| @@ -103,6 +107,8 @@ module CrashLog | |
| 103 107 | 
             
                    # Try unparsed_uri in case it is a Webrick request
         | 
| 104 108 | 
             
                    path = if request.respond_to?(:unparsed_uri)
         | 
| 105 109 | 
             
                      request.unparsed_uri
         | 
| 110 | 
            +
                    elsif request.is_a?(Hash) && request.has_key?(:url) && request[:url].is_a?(URI)
         | 
| 111 | 
            +
                      request[:url].path
         | 
| 106 112 | 
             
                    else
         | 
| 107 113 | 
             
                      request.path
         | 
| 108 114 | 
             
                    end
         | 
| @@ -150,7 +156,7 @@ module CrashLog | |
| 150 156 | 
             
                # Supports same options as AuthHMAC.initialize for overriding service_id and
         | 
| 151 157 | 
             
                # signature method.
         | 
| 152 158 | 
             
                #
         | 
| 153 | 
            -
                def  | 
| 159 | 
            +
                def self.canonical_string(request, options = nil)
         | 
| 154 160 | 
             
                  self.new(nil, options).canonical_string(request)
         | 
| 155 161 | 
             
                end
         | 
| 156 162 |  | 
| @@ -159,7 +165,7 @@ module CrashLog | |
| 159 165 | 
             
                # Supports same options as AuthHMAC.initialize for overriding service_id and
         | 
| 160 166 | 
             
                # signature method.
         | 
| 161 167 | 
             
                #
         | 
| 162 | 
            -
                def  | 
| 168 | 
            +
                def self.signature(request, secret, options = nil)
         | 
| 163 169 | 
             
                  self.new(nil, options).signature(request, secret)
         | 
| 164 170 | 
             
                end
         | 
| 165 171 |  | 
| @@ -168,7 +174,7 @@ module CrashLog | |
| 168 174 | 
             
                # Supports same options as AuthHMAC.initialize for overriding service_id and
         | 
| 169 175 | 
             
                # signature method.
         | 
| 170 176 | 
             
                #
         | 
| 171 | 
            -
                def  | 
| 177 | 
            +
                def self.sign!(request, access_key_id, secret, options = nil)
         | 
| 172 178 | 
             
                  credentials = { access_key_id => secret }
         | 
| 173 179 | 
             
                  self.new(credentials, options).sign!(request, access_key_id)
         | 
| 174 180 | 
             
                end
         | 
| @@ -178,7 +184,7 @@ module CrashLog | |
| 178 184 | 
             
                # Supports same options as AuthHMAC.initialize for overriding service_id and
         | 
| 179 185 | 
             
                # signature method.
         | 
| 180 186 | 
             
                #
         | 
| 181 | 
            -
                def  | 
| 187 | 
            +
                def self.authenticated?(request, access_key_id, secret, options)
         | 
| 182 188 | 
             
                  credentials = { access_key_id => secret }
         | 
| 183 189 | 
             
                  self.new(credentials, options).authenticated?(request)
         | 
| 184 190 | 
             
                end
         | 
| @@ -54,6 +54,22 @@ describe CrashLog::AuthHMAC do | |
| 54 54 | 
             
                  CrashLog::AuthHMAC.sign!(request, "my-key-id", "secret", options)
         | 
| 55 55 | 
             
                  request['Authorization'].should == "MyService my-key-id:/L4N1v1BZSHfAYkQjsvZn696D9c="
         | 
| 56 56 | 
             
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it 'can sign a faraday request hash' do
         | 
| 59 | 
            +
                  Time.stub(:now).and_return(Time.parse("Thu, 10 Jul 2008 03:29:56 GMT"))
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  env = {
         | 
| 62 | 
            +
                    :method=>:get,
         | 
| 63 | 
            +
                    :body=>"test",
         | 
| 64 | 
            +
                    :url=>URI.parse("http://sushi.com/api/foo.json"),
         | 
| 65 | 
            +
                    :request_headers=>{"Date" => Time.now.utc.httpdate},
         | 
| 66 | 
            +
                    :parallel_manager=>nil,
         | 
| 67 | 
            +
                    :request=>nil,
         | 
| 68 | 
            +
                    :ssl=>{}
         | 
| 69 | 
            +
                  }
         | 
| 70 | 
            +
                  CrashLog::AuthHMAC.sign!(env, "access_id", "secret", { :service_id => 'MyService' })
         | 
| 71 | 
            +
                  env['Authorization'].should == 'MyService access_id:ZQnbYwmno+PsaavXzUAdvj/DKvo='
         | 
| 72 | 
            +
                end
         | 
| 57 73 | 
             
              end
         | 
| 58 74 |  | 
| 59 75 | 
             
              describe "#sign!" do
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: crashlog-auth-hmac
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.1. | 
| 4 | 
            +
              version: 1.1.3
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-08- | 
| 12 | 
            +
            date: 2012-08-06 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies: []
         | 
| 14 14 | 
             
            description: A Ruby Gem for authenticating HTTP requests using a HMAC
         | 
| 15 15 | 
             
            email:
         | 
| @@ -20,7 +20,9 @@ extra_rdoc_files: [] | |
| 20 20 | 
             
            files:
         | 
| 21 21 | 
             
            - .gitignore
         | 
| 22 22 | 
             
            - .rspec
         | 
| 23 | 
            +
            - .travis.yml
         | 
| 23 24 | 
             
            - Gemfile
         | 
| 25 | 
            +
            - Gemfile.lock
         | 
| 24 26 | 
             
            - LICENSE
         | 
| 25 27 | 
             
            - README.md
         | 
| 26 28 | 
             
            - Rakefile
         |