faraday-digestauth 0.2.0 → 0.2.1
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/.rspec +3 -0
- data/.rubocop.yml +72 -0
- data/.rubocop_todo.yml +16 -0
- data/.travis.yml +3 -7
- data/README.md +8 -6
- data/Rakefile +8 -4
- data/faraday-digestauth.gemspec +7 -5
- data/lib/faraday/digestauth.rb +3 -3
- data/lib/faraday/digestauth/version.rb +1 -1
- data/lib/faraday/request/digestauth.rb +6 -2
- data/spec/faraday-digestauth_spec.rb +31 -6
- data/spec/spec_helper.rb +1 -0
- metadata +36 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c01446f0b7a664c1686708031360d4de062e0a4
|
4
|
+
data.tar.gz: 3c7447336b7b528bb1f9fe0ae111cccca2e9127f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a579073989264f24fdebe0f9ef56572af56fa667c8bc998c65e284ba1979acb6afb4140b157aa5936699e161e8e2d95dc632c938fb220609bd3bc8c3a089df83
|
7
|
+
data.tar.gz: a8721c84ad509ec0e97143565b1586d5ff049836e4077d3b60de699cb55708f702ab7fa36235bbb7120ac6a7156f708f1d6ad7825c8b0c5beaf1b68a07ccc157
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- vendor/**/*
|
4
|
+
- bin/**/*
|
5
|
+
|
6
|
+
LineLength:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
MethodLength:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
ClassLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Documentation:
|
16
|
+
# don't require classes to be documented
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
CollectionMethods:
|
20
|
+
# don't prefer map to collect, recuce to inject
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Encoding:
|
24
|
+
# no need to always specify encoding
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
StringLiterals:
|
28
|
+
# use single or double-quoted strings, as you please
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Void:
|
32
|
+
# == operator used in void context in specs
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
SignalException:
|
36
|
+
# prefer raise to fail
|
37
|
+
EnforcedStyle: only_raise
|
38
|
+
|
39
|
+
RaiseArgs:
|
40
|
+
# don't care for what kind of raise
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
PerlBackrefs:
|
44
|
+
# TODO: regular expression matching with $1, $2, etc.
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
BlockNesting:
|
48
|
+
# TODO: fix too much nesting
|
49
|
+
Max: 4
|
50
|
+
|
51
|
+
Lambda:
|
52
|
+
# TODO: replace all lambda with -> or Proc
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Blocks:
|
56
|
+
# allow multi-line blocks like expect { }
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
WordArray:
|
60
|
+
# %w vs. [ '', ... ]
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
CyclomaticComplexity:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
DoubleNegation:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
PredicateName:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2014-09-26 16:00:47 -0400 using RuboCop version 0.26.1.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: Exclude.
|
10
|
+
Style/FileName:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# Offense count: 3
|
14
|
+
# Configuration parameters: MaxSlashes.
|
15
|
+
Style/RegexpLiteral:
|
16
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -3,22 +3,18 @@ env:
|
|
3
3
|
global:
|
4
4
|
- "JRUBY_OPTS=-Xcext.enabled=true"
|
5
5
|
rvm:
|
6
|
-
- 2.1.
|
6
|
+
- 2.1.2
|
7
7
|
- 2.0.0
|
8
8
|
- 1.9.3
|
9
|
-
- 1.9.2
|
10
|
-
- 1.8.7
|
11
|
-
- jruby-18mode
|
12
9
|
- jruby-19mode
|
13
|
-
- rbx
|
10
|
+
- rbx-2.2.10
|
14
11
|
- ruby-head
|
15
12
|
- jruby-head
|
16
13
|
- ree
|
17
14
|
matrix:
|
18
15
|
allow_failures:
|
19
|
-
- rvm: 1.8.7
|
20
16
|
- rvm: ree
|
17
|
+
- rvm: ruby-head
|
21
18
|
- rvm: jruby-18mode
|
22
|
-
- rvm: jruby-19mode
|
23
19
|
- rvm: jruby-head
|
24
20
|
fast_finish: true
|
data/README.md
CHANGED
@@ -6,12 +6,6 @@
|
|
6
6
|
[](https://coveralls.io/r/bhaberer/faraday-digestauth?branch=m aster)
|
7
7
|
[](https://codeclimate.com/github/bhaberer/faraday-digestauth)
|
8
8
|
|
9
|
-
This gem started as a direct copy of a gist belonging to @kapkaev
|
10
|
-
|
11
|
-
It is located at https://gist.github.com/kapkaev/5088751
|
12
|
-
|
13
|
-
I merely gemmed it up so that I could use it in multiple places.
|
14
|
-
|
15
9
|
## Installation
|
16
10
|
|
17
11
|
Add this line to your application's Gemfile:
|
@@ -47,3 +41,11 @@ end
|
|
47
41
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
42
|
4. Push to the branch (`git push origin my-new-feature`)
|
49
43
|
5. Create new Pull Request
|
44
|
+
|
45
|
+
## History
|
46
|
+
|
47
|
+
This gem was extracted from [Hyperclient](https://github.com/codegram/hyperclient) by [@oriolgual](https://github.com/oriolgual).
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
MIT License, see [LICENSE](LICENSE.txt) for details.
|
data/Rakefile
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
RSpec::Core::RakeTask.new
|
5
5
|
|
6
|
-
task :
|
7
|
-
|
6
|
+
task test: :spec
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
|
11
|
+
task default: [:rubocop, :spec]
|
data/faraday-digestauth.gemspec
CHANGED
@@ -6,14 +6,14 @@ require 'faraday/digestauth/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'faraday-digestauth'
|
8
8
|
spec.version = Faraday::DigestAuth::VERSION
|
9
|
-
spec.authors = ['Brian Haberer', '
|
10
|
-
spec.email = ['bhaberer@gmail.com', '
|
11
|
-
spec.description =
|
12
|
-
spec.summary =
|
9
|
+
spec.authors = ['Brian Haberer', 'Oriol Gual']
|
10
|
+
spec.email = ['bhaberer@gmail.com', 'oriol.gual@gmail.com']
|
11
|
+
spec.description = 'Faraday extension to enable digest auth'
|
12
|
+
spec.summary = 'Digest Auth for Faraday'
|
13
13
|
spec.homepage = 'https://github.com/bhaberer/faraday-digestauth'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split(
|
16
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rake', '~> 10'
|
25
25
|
spec.add_development_dependency 'rspec', '~> 3'
|
26
26
|
spec.add_development_dependency 'coveralls', '~> 0.1'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.26.1'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 1'
|
27
29
|
end
|
data/lib/faraday/digestauth.rb
CHANGED
@@ -7,9 +7,9 @@ require 'faraday/request/digestauth'
|
|
7
7
|
|
8
8
|
# Register the middleware as a Request middleware with the name :digest
|
9
9
|
if Faraday.respond_to?(:register_middleware) # Faraday 0.8
|
10
|
-
Faraday.register_middleware :request, :
|
10
|
+
Faraday.register_middleware :request, digest: Faraday::Request::DigestAuth
|
11
11
|
elsif Faraday::Request.respond_to?(:register_middleware) # Faraday 0.9
|
12
|
-
Faraday::Request.register_middleware :
|
12
|
+
Faraday::Request.register_middleware digest: Faraday::Request::DigestAuth
|
13
13
|
elsif Faraday::Request.respond_to?(:register_lookup_modules) # Faraday 0.7
|
14
|
-
Faraday::Request.register_lookup_modules :
|
14
|
+
Faraday::Request.register_lookup_modules digest: :DigestAuth
|
15
15
|
end
|
@@ -26,9 +26,13 @@ module Faraday
|
|
26
26
|
# app - The Faraday app.
|
27
27
|
# user - A String with the user to authentication the connection.
|
28
28
|
# password - A String with the password to authentication the connection.
|
29
|
-
|
29
|
+
# opts - A hash with options
|
30
|
+
# - keep_body_on_handshake: if set to truthy, will also send
|
31
|
+
# the original request body
|
32
|
+
def initialize(app, user, password, opts = {})
|
30
33
|
super(app)
|
31
34
|
@user, @password = user, password
|
35
|
+
@opts = opts
|
32
36
|
end
|
33
37
|
|
34
38
|
# Public: Sends a first request with an empty body to get the
|
@@ -55,7 +59,7 @@ module Faraday
|
|
55
59
|
# Returns a Faraday::Response.
|
56
60
|
def handshake(env)
|
57
61
|
env_without_body = env.dup
|
58
|
-
env_without_body.delete(:body)
|
62
|
+
env_without_body.delete(:body) unless @opts[:keep_body_on_handshake]
|
59
63
|
@app.call(env_without_body)
|
60
64
|
end
|
61
65
|
|
@@ -1,13 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Faraday::Request::DigestAuth do
|
4
|
+
let(:connection) do
|
5
|
+
Faraday.new('http://api.example.org/') do |builder|
|
6
|
+
builder.request :digest, 'USER', 'PASS'
|
7
|
+
builder.adapter :net_http
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'when the server does not return a 401' do
|
12
|
+
it 'does nothing' do
|
13
|
+
stub_request(:get, 'http://api.example.org/productions/1')
|
14
|
+
.to_return(status: 500, body: 'Foo body')
|
15
|
+
|
16
|
+
response = connection.get('/productions/1')
|
17
|
+
expect(response.body).to eq 'Foo body'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'when the server returns a 401' do
|
22
|
+
let(:first_call_headers) { 'Digest realm="MyApp", algorithm=MD5' }
|
23
|
+
let(:second_call_headers) { 'Digest username="USER", realm="MyApp", uri="/", algorithm="MD5"' }
|
24
|
+
it 'authenticates using digest' do
|
25
|
+
stub_request(:get, 'http://api.example.org/productions/1')
|
26
|
+
.with(body: nil)
|
27
|
+
.to_return(status: 401, headers: { 'www-authenticate' => first_call_headers })
|
4
28
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
29
|
+
stub_request(:get, 'http://api.example.org/productions/1')
|
30
|
+
.with(body: "{\"foo\":1}",
|
31
|
+
headers: { 'Authorization' => %r{second_call_headers} })
|
32
|
+
.to_return(body: '{"resource": "This is the resource"}',
|
33
|
+
headers: { content_type: 'application/json' })
|
11
34
|
|
35
|
+
connection.get('/productions/1')
|
36
|
+
end
|
12
37
|
end
|
13
38
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-digestauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Haberer
|
8
|
-
-
|
8
|
+
- Oriol Gual
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -95,15 +95,46 @@ dependencies:
|
|
95
95
|
- - ~>
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0.1'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.26.1
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.26.1
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '1'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1'
|
98
126
|
description: Faraday extension to enable digest auth
|
99
127
|
email:
|
100
128
|
- bhaberer@gmail.com
|
101
|
-
-
|
129
|
+
- oriol.gual@gmail.com
|
102
130
|
executables: []
|
103
131
|
extensions: []
|
104
132
|
extra_rdoc_files: []
|
105
133
|
files:
|
106
134
|
- .gitignore
|
135
|
+
- .rspec
|
136
|
+
- .rubocop.yml
|
137
|
+
- .rubocop_todo.yml
|
107
138
|
- .travis.yml
|
108
139
|
- Gemfile
|
109
140
|
- LICENSE.txt
|
@@ -136,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
167
|
version: '0'
|
137
168
|
requirements: []
|
138
169
|
rubyforge_project:
|
139
|
-
rubygems_version: 2.
|
170
|
+
rubygems_version: 2.4.4
|
140
171
|
signing_key:
|
141
172
|
specification_version: 4
|
142
173
|
summary: Digest Auth for Faraday
|