api-auth 1.2.6 → 1.3.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.
- checksums.yaml +7 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +5 -2
- data/README.md +2 -1
- data/VERSION +1 -1
- data/api_auth.gemspec +1 -0
- data/gemfiles/rails_23.gemfile.lock +5 -2
- data/gemfiles/rails_30.gemfile.lock +5 -2
- data/gemfiles/rails_31.gemfile.lock +5 -2
- data/gemfiles/rails_32.gemfile.lock +5 -2
- data/gemfiles/rails_4.gemfile.lock +5 -2
- data/gemfiles/rails_41.gemfile.lock +5 -2
- data/lib/api_auth.rb +1 -0
- data/lib/api_auth/base.rb +2 -2
- data/lib/api_auth/headers.rb +2 -0
- data/lib/api_auth/request_drivers/faraday.rb +86 -0
- data/spec/api_auth_spec.rb +96 -0
- data/spec/railtie_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +48 -63
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: ee9363c952d199ecc16cd1f3395e5ac5bb6637b5
|
|
4
|
+
data.tar.gz: 13ebba43bab52e75146b91ff0d81a3e876a8ac1b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fbd418e5584e7b84feb9070efac57c2a4215c011065884ef60e9d2a276f93d2c40b59f4c2eca22e1313aefaa6929726af3517d7f92353212c544f01e58c02770
|
|
7
|
+
data.tar.gz: 3052ae92cca8d52d3d40f53ba030266e0273b72679cf568e4ccbdb447efed94020b1b2d33f7a3426a54e825d6c32c4f4c6657af216debaaad18491ce0ccc6955
|
data/.travis.yml
CHANGED
|
@@ -2,6 +2,8 @@ language: ruby
|
|
|
2
2
|
rvm:
|
|
3
3
|
- 1.8.7-p374
|
|
4
4
|
- 1.9.3
|
|
5
|
+
- 2.1.5
|
|
6
|
+
- 2.2.1
|
|
5
7
|
gemfile:
|
|
6
8
|
- gemfiles/rails_23.gemfile
|
|
7
9
|
- gemfiles/rails_30.gemfile
|
|
@@ -15,6 +17,20 @@ matrix:
|
|
|
15
17
|
gemfile: gemfiles/rails_4.gemfile
|
|
16
18
|
- rvm: 1.8.7-p374
|
|
17
19
|
gemfile: gemfiles/rails_41.gemfile
|
|
20
|
+
- rvm: 2.1.5
|
|
21
|
+
gemfile: gemfiles/rails_23.gemfile
|
|
22
|
+
- rvm: 2.1.5
|
|
23
|
+
gemfile: gemfiles/rails_30.gemfile
|
|
24
|
+
- rvm: 2.1.5
|
|
25
|
+
gemfile: gemfiles/rails_31.gemfile
|
|
26
|
+
- rvm: 2.2.1
|
|
27
|
+
gemfile: gemfiles/rails_23.gemfile
|
|
28
|
+
- rvm: 2.2.1
|
|
29
|
+
gemfile: gemfiles/rails_30.gemfile
|
|
30
|
+
- rvm: 2.2.1
|
|
31
|
+
gemfile: gemfiles/rails_31.gemfile
|
|
32
|
+
- rvm: 2.2.1
|
|
33
|
+
gemfile: gemfiles/rails_32.gemfile
|
|
18
34
|
|
|
19
35
|
notifications:
|
|
20
36
|
email: false
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -31,10 +31,12 @@ GEM
|
|
|
31
31
|
bundler
|
|
32
32
|
rake
|
|
33
33
|
builder (2.1.2)
|
|
34
|
-
curb (0.8.
|
|
34
|
+
curb (0.8.6)
|
|
35
35
|
diff-lcs (1.1.3)
|
|
36
36
|
erubis (2.6.6)
|
|
37
37
|
abstract (>= 1.0.0)
|
|
38
|
+
faraday (0.9.1)
|
|
39
|
+
multipart-post (>= 1.2, < 3)
|
|
38
40
|
httpi (2.1.0)
|
|
39
41
|
rack
|
|
40
42
|
rubyntlm (~> 0.3.2)
|
|
@@ -72,6 +74,7 @@ DEPENDENCIES
|
|
|
72
74
|
api-auth!
|
|
73
75
|
appraisal
|
|
74
76
|
curb (~> 0.8.1)
|
|
77
|
+
faraday
|
|
75
78
|
httpi
|
|
76
79
|
multipart-post (~> 2.0)
|
|
77
80
|
rake
|
data/README.md
CHANGED
|
@@ -23,7 +23,7 @@ have to be written in the same language as the clients.
|
|
|
23
23
|
content-type, content-MD5, request URI and the timestamp. If content-type or
|
|
24
24
|
content-MD5 are not present, then a blank string is used in their place. If the
|
|
25
25
|
timestamp isn't present, a valid HTTP date is automatically added to the
|
|
26
|
-
request. The canonical string
|
|
26
|
+
request. The canonical string is computed as follows:
|
|
27
27
|
|
|
28
28
|
canonical_string = 'content-type,content-MD5,request URI,timestamp'
|
|
29
29
|
|
|
@@ -69,6 +69,7 @@ Here is the current list of supported request objects:
|
|
|
69
69
|
* ActionDispatch::Request
|
|
70
70
|
* Curb (Curl::Easy)
|
|
71
71
|
* RestClient
|
|
72
|
+
* Faraday
|
|
72
73
|
|
|
73
74
|
### HTTP Client Objects
|
|
74
75
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.3.0
|
data/api_auth.gemspec
CHANGED
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
s.add_development_dependency "rest-client", "~> 1.6.0"
|
|
21
21
|
s.add_development_dependency "curb", "~> 0.8.1"
|
|
22
22
|
s.add_development_dependency "httpi"
|
|
23
|
+
s.add_development_dependency "faraday"
|
|
23
24
|
s.add_development_dependency "multipart-post", "~> 2.0"
|
|
24
25
|
|
|
25
26
|
s.files = `git ls-files`.split("\n")
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -18,8 +18,10 @@ GEM
|
|
|
18
18
|
bundler
|
|
19
19
|
rake
|
|
20
20
|
thor (>= 0.14.0)
|
|
21
|
-
curb (0.8.
|
|
21
|
+
curb (0.8.6)
|
|
22
22
|
diff-lcs (1.1.3)
|
|
23
|
+
faraday (0.9.1)
|
|
24
|
+
multipart-post (>= 1.2, < 3)
|
|
23
25
|
httpi (2.1.0)
|
|
24
26
|
rack
|
|
25
27
|
rubyntlm (~> 0.3.2)
|
|
@@ -52,6 +54,7 @@ DEPENDENCIES
|
|
|
52
54
|
api-auth!
|
|
53
55
|
appraisal
|
|
54
56
|
curb (~> 0.8.1)
|
|
57
|
+
faraday
|
|
55
58
|
httpi
|
|
56
59
|
multipart-post (~> 2.0)
|
|
57
60
|
rake
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -32,10 +32,12 @@ GEM
|
|
|
32
32
|
rake
|
|
33
33
|
thor (>= 0.14.0)
|
|
34
34
|
builder (2.1.2)
|
|
35
|
-
curb (0.8.
|
|
35
|
+
curb (0.8.6)
|
|
36
36
|
diff-lcs (1.1.3)
|
|
37
37
|
erubis (2.6.6)
|
|
38
38
|
abstract (>= 1.0.0)
|
|
39
|
+
faraday (0.9.1)
|
|
40
|
+
multipart-post (>= 1.2, < 3)
|
|
39
41
|
httpi (2.1.0)
|
|
40
42
|
rack
|
|
41
43
|
rubyntlm (~> 0.3.2)
|
|
@@ -74,6 +76,7 @@ DEPENDENCIES
|
|
|
74
76
|
api-auth!
|
|
75
77
|
appraisal
|
|
76
78
|
curb (~> 0.8.1)
|
|
79
|
+
faraday
|
|
77
80
|
httpi
|
|
78
81
|
multipart-post (~> 2.0)
|
|
79
82
|
rake
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -32,9 +32,11 @@ GEM
|
|
|
32
32
|
bundler
|
|
33
33
|
rake
|
|
34
34
|
builder (3.0.4)
|
|
35
|
-
curb (0.8.
|
|
35
|
+
curb (0.8.6)
|
|
36
36
|
diff-lcs (1.1.3)
|
|
37
37
|
erubis (2.7.0)
|
|
38
|
+
faraday (0.9.1)
|
|
39
|
+
multipart-post (>= 1.2, < 3)
|
|
38
40
|
hike (1.2.3)
|
|
39
41
|
httpi (2.1.0)
|
|
40
42
|
rack
|
|
@@ -80,6 +82,7 @@ DEPENDENCIES
|
|
|
80
82
|
api-auth!
|
|
81
83
|
appraisal
|
|
82
84
|
curb (~> 0.8.1)
|
|
85
|
+
faraday
|
|
83
86
|
httpi
|
|
84
87
|
multipart-post (~> 2.0)
|
|
85
88
|
rake
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -31,9 +31,11 @@ GEM
|
|
|
31
31
|
bundler
|
|
32
32
|
rake
|
|
33
33
|
builder (3.0.4)
|
|
34
|
-
curb (0.8.
|
|
34
|
+
curb (0.8.6)
|
|
35
35
|
diff-lcs (1.1.3)
|
|
36
36
|
erubis (2.7.0)
|
|
37
|
+
faraday (0.9.1)
|
|
38
|
+
multipart-post (>= 1.2, < 3)
|
|
37
39
|
hike (1.2.3)
|
|
38
40
|
httpi (2.1.0)
|
|
39
41
|
rack
|
|
@@ -79,6 +81,7 @@ DEPENDENCIES
|
|
|
79
81
|
api-auth!
|
|
80
82
|
appraisal
|
|
81
83
|
curb (~> 0.8.1)
|
|
84
|
+
faraday
|
|
82
85
|
httpi
|
|
83
86
|
multipart-post (~> 2.0)
|
|
84
87
|
rake
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -32,9 +32,11 @@ GEM
|
|
|
32
32
|
rake
|
|
33
33
|
atomic (1.1.16)
|
|
34
34
|
builder (3.1.4)
|
|
35
|
-
curb (0.8.
|
|
35
|
+
curb (0.8.6)
|
|
36
36
|
diff-lcs (1.1.3)
|
|
37
37
|
erubis (2.7.0)
|
|
38
|
+
faraday (0.9.1)
|
|
39
|
+
multipart-post (>= 1.2, < 3)
|
|
38
40
|
httpi (2.1.0)
|
|
39
41
|
rack
|
|
40
42
|
rubyntlm (~> 0.3.2)
|
|
@@ -76,6 +78,7 @@ DEPENDENCIES
|
|
|
76
78
|
api-auth!
|
|
77
79
|
appraisal
|
|
78
80
|
curb (~> 0.8.1)
|
|
81
|
+
faraday
|
|
79
82
|
httpi
|
|
80
83
|
multipart-post (~> 2.0)
|
|
81
84
|
rake
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: ../
|
|
3
3
|
specs:
|
|
4
|
-
api-auth (1.
|
|
4
|
+
api-auth (1.3.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -35,9 +35,11 @@ GEM
|
|
|
35
35
|
rake
|
|
36
36
|
thor (>= 0.14.0)
|
|
37
37
|
builder (3.2.2)
|
|
38
|
-
curb (0.8.
|
|
38
|
+
curb (0.8.6)
|
|
39
39
|
diff-lcs (1.1.3)
|
|
40
40
|
erubis (2.7.0)
|
|
41
|
+
faraday (0.9.1)
|
|
42
|
+
multipart-post (>= 1.2, < 3)
|
|
41
43
|
httpi (2.1.0)
|
|
42
44
|
rack
|
|
43
45
|
rubyntlm (~> 0.3.2)
|
|
@@ -80,6 +82,7 @@ DEPENDENCIES
|
|
|
80
82
|
api-auth!
|
|
81
83
|
appraisal
|
|
82
84
|
curb (~> 0.8.1)
|
|
85
|
+
faraday
|
|
83
86
|
httpi
|
|
84
87
|
multipart-post (~> 2.0)
|
|
85
88
|
rake
|
data/lib/api_auth.rb
CHANGED
|
@@ -11,6 +11,7 @@ require 'api_auth/request_drivers/action_controller'
|
|
|
11
11
|
require 'api_auth/request_drivers/action_dispatch'
|
|
12
12
|
require 'api_auth/request_drivers/rack'
|
|
13
13
|
require 'api_auth/request_drivers/httpi'
|
|
14
|
+
require 'api_auth/request_drivers/faraday'
|
|
14
15
|
|
|
15
16
|
require 'api_auth/headers'
|
|
16
17
|
require 'api_auth/base'
|
data/lib/api_auth/base.rb
CHANGED
|
@@ -17,7 +17,7 @@ module ApiAuth
|
|
|
17
17
|
# Returns the HTTP request object with the modified headers.
|
|
18
18
|
#
|
|
19
19
|
# request: The request can be a Net::HTTP, ActionDispatch::Request,
|
|
20
|
-
# Curb (Curl::Easy)
|
|
20
|
+
# Curb (Curl::Easy), RestClient object or Faraday::Request.
|
|
21
21
|
#
|
|
22
22
|
# access_id: The public unique identifier for the client
|
|
23
23
|
#
|
|
@@ -61,7 +61,7 @@ module ApiAuth
|
|
|
61
61
|
def request_too_old?(request)
|
|
62
62
|
headers = Headers.new(request)
|
|
63
63
|
# 900 seconds is 15 minutes
|
|
64
|
-
begin
|
|
64
|
+
begin
|
|
65
65
|
Time.httpdate(headers.timestamp).utc < (Time.now.utc - 900)
|
|
66
66
|
rescue ArgumentError
|
|
67
67
|
true
|
data/lib/api_auth/headers.rb
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module ApiAuth
|
|
2
|
+
|
|
3
|
+
module RequestDrivers # :nodoc:
|
|
4
|
+
|
|
5
|
+
class FaradayRequest # :nodoc:
|
|
6
|
+
|
|
7
|
+
include ApiAuth::Helpers
|
|
8
|
+
|
|
9
|
+
def initialize(request)
|
|
10
|
+
@request = request
|
|
11
|
+
@headers = fetch_headers
|
|
12
|
+
true
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def set_auth_header(header)
|
|
16
|
+
@request.headers.merge!({ "Authorization" => header })
|
|
17
|
+
@headers = fetch_headers
|
|
18
|
+
@request
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def calculated_md5
|
|
22
|
+
if @request.body
|
|
23
|
+
body = @request.body
|
|
24
|
+
else
|
|
25
|
+
body = ''
|
|
26
|
+
end
|
|
27
|
+
md5_base64digest(body)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def populate_content_md5
|
|
31
|
+
if ['POST', 'PUT'].include?(@request.method.to_s.upcase)
|
|
32
|
+
@request.headers["Content-MD5"] = calculated_md5
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def md5_mismatch?
|
|
37
|
+
if ['POST', 'PUT'].include?(@request.method.to_s.upcase)
|
|
38
|
+
calculated_md5 != content_md5
|
|
39
|
+
else
|
|
40
|
+
false
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def fetch_headers
|
|
45
|
+
capitalize_keys @request.headers
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def content_type
|
|
49
|
+
value = find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
|
|
50
|
+
value.nil? ? "" : value
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def content_md5
|
|
54
|
+
value = find_header(%w(CONTENT-MD5 CONTENT_MD5 HTTP-CONTENT-MD5 HTTP_CONTENT_MD5))
|
|
55
|
+
value.nil? ? "" : value
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def request_uri
|
|
59
|
+
uri = URI::HTTP.new(nil, nil, nil, nil, nil, @request.path, nil, @request.params.to_query, nil)
|
|
60
|
+
uri.to_s
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def set_date
|
|
64
|
+
@request.headers.merge!({ "DATE" => Time.now.utc.httpdate })
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def timestamp
|
|
68
|
+
value = find_header(%w(DATE HTTP_DATE))
|
|
69
|
+
value.nil? ? "" : value
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def authorization_header
|
|
73
|
+
find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def find_header(keys)
|
|
79
|
+
keys.map {|key| @headers[key] }.compact.first
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
data/spec/api_auth_spec.rb
CHANGED
|
@@ -565,6 +565,102 @@ describe "ApiAuth" do
|
|
|
565
565
|
ApiAuth.access_id(@signed_request).should == "1044"
|
|
566
566
|
end
|
|
567
567
|
end
|
|
568
|
+
|
|
569
|
+
describe "with Faraday::Request" do
|
|
570
|
+
before(:each) do
|
|
571
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
|
572
|
+
stub.put('/resource.xml?foo=bar&bar=foo') { [200, {}, ''] }
|
|
573
|
+
end
|
|
574
|
+
|
|
575
|
+
@faraday_conn = Faraday.new do |builder|
|
|
576
|
+
builder.adapter :test, stubs do |stub|
|
|
577
|
+
end
|
|
578
|
+
end
|
|
579
|
+
|
|
580
|
+
@faraday_conn.put '/resource.xml?foo=bar&bar=foo' do |request|
|
|
581
|
+
@request = request
|
|
582
|
+
@request.headers.merge!({'Content-MD5' => "1B2M2Y8AsgTpgAmY7PhCfg==",
|
|
583
|
+
'content-type' => 'text/plain',
|
|
584
|
+
'DATE' => Time.now.utc.httpdate})
|
|
585
|
+
end
|
|
586
|
+
|
|
587
|
+
@headers = ApiAuth::Headers.new(@request)
|
|
588
|
+
@signed_request = ApiAuth.sign!(@request, @access_id, @secret_key)
|
|
589
|
+
end
|
|
590
|
+
|
|
591
|
+
it "should return a Faraday::Request object after signing it" do
|
|
592
|
+
ApiAuth.sign!(@request, @access_id, @secret_key).class.to_s.should match("Faraday::Request")
|
|
593
|
+
end
|
|
594
|
+
|
|
595
|
+
describe "md5 header" do
|
|
596
|
+
context "not already provided" do
|
|
597
|
+
it "should calculate for empty string" do
|
|
598
|
+
@faraday_conn.put '/resource.xml?foo=bar&bar=foo' do |request|
|
|
599
|
+
request.headers.merge!({'content-type' => 'text/plain',
|
|
600
|
+
'DATE' => 'Mon, 23 Jan 1984 03:29:56 GMT'})
|
|
601
|
+
|
|
602
|
+
signed_request = ApiAuth.sign!(request, @access_id, @secret_key)
|
|
603
|
+
signed_request['Content-MD5'].should == "1B2M2Y8AsgTpgAmY7PhCfg=="
|
|
604
|
+
end
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
it "should calculate for real content" do
|
|
608
|
+
@faraday_conn.put '/resource.xml?foo=bar&bar=foo' do |request|
|
|
609
|
+
request.headers.merge!({'content-type' => 'text/plain',
|
|
610
|
+
'DATE' => 'Mon, 23 Jan 1984 03:29:56 GMT'})
|
|
611
|
+
request.body = "hello\nworld"
|
|
612
|
+
|
|
613
|
+
signed_request = ApiAuth.sign!(request, @access_id, @secret_key)
|
|
614
|
+
signed_request['Content-MD5'].should == "kZXQvrKoieG+Be1rsZVINw=="
|
|
615
|
+
end
|
|
616
|
+
end
|
|
617
|
+
end
|
|
618
|
+
|
|
619
|
+
it "should leave the content-md5 alone if provided" do
|
|
620
|
+
@signed_request.headers['Content-MD5'].should == '1B2M2Y8AsgTpgAmY7PhCfg=='
|
|
621
|
+
end
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
it "should sign the request" do
|
|
625
|
+
@signed_request.headers['Authorization'].should == "APIAuth 1044:#{hmac(@secret_key, @request)}"
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
it "should authenticate a valid request" do
|
|
629
|
+
ApiAuth.authentic?(@signed_request, @secret_key).should be_true
|
|
630
|
+
end
|
|
631
|
+
|
|
632
|
+
it "should NOT authenticate a non-valid request" do
|
|
633
|
+
ApiAuth.authentic?(@signed_request, @secret_key+'j').should be_false
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
it "should NOT authenticate a mismatched content-md5 when body has changed" do
|
|
637
|
+
@faraday_conn.put '/resource.xml?foo=bar&bar=foo' do |request|
|
|
638
|
+
request.headers.merge!({'content-type' => 'text/plain',
|
|
639
|
+
'DATE' => 'Mon, 23 Jan 1984 03:29:56 GMT'})
|
|
640
|
+
request.body = "hello\nworld"
|
|
641
|
+
|
|
642
|
+
signed_request = ApiAuth.sign!(request, @access_id, @secret_key)
|
|
643
|
+
signed_request.body = 'goodbye'
|
|
644
|
+
ApiAuth.authentic?(signed_request, @secret_key).should be_false
|
|
645
|
+
end
|
|
646
|
+
end
|
|
647
|
+
|
|
648
|
+
it "should NOT authenticate an expired request" do
|
|
649
|
+
@request.headers['DATE'] = 16.minutes.ago.utc.httpdate
|
|
650
|
+
signed_request = ApiAuth.sign!(@request, @access_id, @secret_key)
|
|
651
|
+
ApiAuth.authentic?(signed_request, @secret_key).should be_false
|
|
652
|
+
end
|
|
653
|
+
|
|
654
|
+
it "should NOT authenticate a request with an invalid date" do
|
|
655
|
+
@request.headers['DATE'] = "٢٠١٤-٠٩-٠٨ ١٦:٣١:١٤ +٠٣٠٠"
|
|
656
|
+
signed_request = ApiAuth.sign!(@request, @access_id, @secret_key)
|
|
657
|
+
ApiAuth.authentic?(signed_request, @secret_key).should be_false
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
it "should retrieve the access_id" do
|
|
661
|
+
ApiAuth.access_id(@signed_request).should == "1044"
|
|
662
|
+
end
|
|
663
|
+
end
|
|
568
664
|
end
|
|
569
665
|
|
|
570
666
|
end
|
data/spec/railtie_spec.rb
CHANGED
|
@@ -18,7 +18,7 @@ describe "Rails integration" do
|
|
|
18
18
|
respond_to do |format|
|
|
19
19
|
format.xml { render :xml => "You are unauthorized to perform this action.", :status => 401 }
|
|
20
20
|
format.json { render :json => "You are unauthorized to perform this action.", :status => 401 }
|
|
21
|
-
|
|
21
|
+
format.html { render :text => "You are unauthorized to perform this action", :status => 401 }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -6,6 +6,7 @@ require 'amatch'
|
|
|
6
6
|
require 'rest_client'
|
|
7
7
|
require 'curb'
|
|
8
8
|
require 'httpi'
|
|
9
|
+
require 'faraday'
|
|
9
10
|
require 'net/http/post/multipart'
|
|
10
11
|
|
|
11
12
|
require 'active_support'
|
|
@@ -20,5 +21,5 @@ require 'active_resource/http_mock'
|
|
|
20
21
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
21
22
|
|
|
22
23
|
RSpec.configure do |config|
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
end
|
metadata
CHANGED
|
@@ -1,190 +1,181 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: api-auth
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 1.3.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Mauricio Gomes
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: appraisal
|
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
none: false
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - ">="
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
19
|
version: '0'
|
|
22
20
|
type: :development
|
|
23
21
|
prerelease: false
|
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
-
none: false
|
|
26
23
|
requirements:
|
|
27
|
-
- -
|
|
24
|
+
- - ">="
|
|
28
25
|
- !ruby/object:Gem::Version
|
|
29
26
|
version: '0'
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
|
31
28
|
name: rake
|
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
|
33
|
-
none: false
|
|
34
30
|
requirements:
|
|
35
|
-
- -
|
|
31
|
+
- - ">="
|
|
36
32
|
- !ruby/object:Gem::Version
|
|
37
33
|
version: '0'
|
|
38
34
|
type: :development
|
|
39
35
|
prerelease: false
|
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
-
none: false
|
|
42
37
|
requirements:
|
|
43
|
-
- -
|
|
38
|
+
- - ">="
|
|
44
39
|
- !ruby/object:Gem::Version
|
|
45
40
|
version: '0'
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
|
47
42
|
name: amatch
|
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
|
49
|
-
none: false
|
|
50
44
|
requirements:
|
|
51
|
-
- -
|
|
45
|
+
- - ">="
|
|
52
46
|
- !ruby/object:Gem::Version
|
|
53
47
|
version: '0'
|
|
54
48
|
type: :development
|
|
55
49
|
prerelease: false
|
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
51
|
requirements:
|
|
59
|
-
- -
|
|
52
|
+
- - ">="
|
|
60
53
|
- !ruby/object:Gem::Version
|
|
61
54
|
version: '0'
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
|
63
56
|
name: rspec
|
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
|
65
|
-
none: false
|
|
66
58
|
requirements:
|
|
67
|
-
- - ~>
|
|
59
|
+
- - "~>"
|
|
68
60
|
- !ruby/object:Gem::Version
|
|
69
61
|
version: 2.4.0
|
|
70
62
|
type: :development
|
|
71
63
|
prerelease: false
|
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
none: false
|
|
74
65
|
requirements:
|
|
75
|
-
- - ~>
|
|
66
|
+
- - "~>"
|
|
76
67
|
- !ruby/object:Gem::Version
|
|
77
68
|
version: 2.4.0
|
|
78
69
|
- !ruby/object:Gem::Dependency
|
|
79
70
|
name: actionpack
|
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
|
81
|
-
none: false
|
|
82
72
|
requirements:
|
|
83
|
-
- - ~>
|
|
73
|
+
- - "~>"
|
|
84
74
|
- !ruby/object:Gem::Version
|
|
85
75
|
version: 3.0.0
|
|
86
76
|
type: :development
|
|
87
77
|
prerelease: false
|
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
89
|
-
none: false
|
|
90
79
|
requirements:
|
|
91
|
-
- - ~>
|
|
80
|
+
- - "~>"
|
|
92
81
|
- !ruby/object:Gem::Version
|
|
93
82
|
version: 3.0.0
|
|
94
83
|
- !ruby/object:Gem::Dependency
|
|
95
84
|
name: activesupport
|
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
|
97
|
-
none: false
|
|
98
86
|
requirements:
|
|
99
|
-
- - ~>
|
|
87
|
+
- - "~>"
|
|
100
88
|
- !ruby/object:Gem::Version
|
|
101
89
|
version: 3.0.0
|
|
102
90
|
type: :development
|
|
103
91
|
prerelease: false
|
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
105
|
-
none: false
|
|
106
93
|
requirements:
|
|
107
|
-
- - ~>
|
|
94
|
+
- - "~>"
|
|
108
95
|
- !ruby/object:Gem::Version
|
|
109
96
|
version: 3.0.0
|
|
110
97
|
- !ruby/object:Gem::Dependency
|
|
111
98
|
name: activeresource
|
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
|
113
|
-
none: false
|
|
114
100
|
requirements:
|
|
115
|
-
- - ~>
|
|
101
|
+
- - "~>"
|
|
116
102
|
- !ruby/object:Gem::Version
|
|
117
103
|
version: 3.0.0
|
|
118
104
|
type: :development
|
|
119
105
|
prerelease: false
|
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
-
none: false
|
|
122
107
|
requirements:
|
|
123
|
-
- - ~>
|
|
108
|
+
- - "~>"
|
|
124
109
|
- !ruby/object:Gem::Version
|
|
125
110
|
version: 3.0.0
|
|
126
111
|
- !ruby/object:Gem::Dependency
|
|
127
112
|
name: rest-client
|
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
|
129
|
-
none: false
|
|
130
114
|
requirements:
|
|
131
|
-
- - ~>
|
|
115
|
+
- - "~>"
|
|
132
116
|
- !ruby/object:Gem::Version
|
|
133
117
|
version: 1.6.0
|
|
134
118
|
type: :development
|
|
135
119
|
prerelease: false
|
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
137
|
-
none: false
|
|
138
121
|
requirements:
|
|
139
|
-
- - ~>
|
|
122
|
+
- - "~>"
|
|
140
123
|
- !ruby/object:Gem::Version
|
|
141
124
|
version: 1.6.0
|
|
142
125
|
- !ruby/object:Gem::Dependency
|
|
143
126
|
name: curb
|
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
|
145
|
-
none: false
|
|
146
128
|
requirements:
|
|
147
|
-
- - ~>
|
|
129
|
+
- - "~>"
|
|
148
130
|
- !ruby/object:Gem::Version
|
|
149
131
|
version: 0.8.1
|
|
150
132
|
type: :development
|
|
151
133
|
prerelease: false
|
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
153
|
-
none: false
|
|
154
135
|
requirements:
|
|
155
|
-
- - ~>
|
|
136
|
+
- - "~>"
|
|
156
137
|
- !ruby/object:Gem::Version
|
|
157
138
|
version: 0.8.1
|
|
158
139
|
- !ruby/object:Gem::Dependency
|
|
159
140
|
name: httpi
|
|
160
141
|
requirement: !ruby/object:Gem::Requirement
|
|
161
|
-
none: false
|
|
162
142
|
requirements:
|
|
163
|
-
- -
|
|
143
|
+
- - ">="
|
|
164
144
|
- !ruby/object:Gem::Version
|
|
165
145
|
version: '0'
|
|
166
146
|
type: :development
|
|
167
147
|
prerelease: false
|
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
169
|
-
none: false
|
|
170
149
|
requirements:
|
|
171
|
-
- -
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: faraday
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - ">="
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '0'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - ">="
|
|
172
165
|
- !ruby/object:Gem::Version
|
|
173
166
|
version: '0'
|
|
174
167
|
- !ruby/object:Gem::Dependency
|
|
175
168
|
name: multipart-post
|
|
176
169
|
requirement: !ruby/object:Gem::Requirement
|
|
177
|
-
none: false
|
|
178
170
|
requirements:
|
|
179
|
-
- - ~>
|
|
171
|
+
- - "~>"
|
|
180
172
|
- !ruby/object:Gem::Version
|
|
181
173
|
version: '2.0'
|
|
182
174
|
type: :development
|
|
183
175
|
prerelease: false
|
|
184
176
|
version_requirements: !ruby/object:Gem::Requirement
|
|
185
|
-
none: false
|
|
186
177
|
requirements:
|
|
187
|
-
- - ~>
|
|
178
|
+
- - "~>"
|
|
188
179
|
- !ruby/object:Gem::Version
|
|
189
180
|
version: '2.0'
|
|
190
181
|
description: Full HMAC auth implementation for use in your gems and Rails apps.
|
|
@@ -193,10 +184,10 @@ executables: []
|
|
|
193
184
|
extensions: []
|
|
194
185
|
extra_rdoc_files: []
|
|
195
186
|
files:
|
|
196
|
-
- .document
|
|
197
|
-
- .gitignore
|
|
198
|
-
- .rspec
|
|
199
|
-
- .travis.yml
|
|
187
|
+
- ".document"
|
|
188
|
+
- ".gitignore"
|
|
189
|
+
- ".rspec"
|
|
190
|
+
- ".travis.yml"
|
|
200
191
|
- Appraisals
|
|
201
192
|
- CHANGELOG.md
|
|
202
193
|
- Gemfile
|
|
@@ -228,6 +219,7 @@ files:
|
|
|
228
219
|
- lib/api_auth/request_drivers/action_controller.rb
|
|
229
220
|
- lib/api_auth/request_drivers/action_dispatch.rb
|
|
230
221
|
- lib/api_auth/request_drivers/curb.rb
|
|
222
|
+
- lib/api_auth/request_drivers/faraday.rb
|
|
231
223
|
- lib/api_auth/request_drivers/httpi.rb
|
|
232
224
|
- lib/api_auth/request_drivers/net_http.rb
|
|
233
225
|
- lib/api_auth/request_drivers/rack.rb
|
|
@@ -242,33 +234,26 @@ files:
|
|
|
242
234
|
- spec/test_helper.rb
|
|
243
235
|
homepage: https://github.com/mgomes/api_auth
|
|
244
236
|
licenses: []
|
|
237
|
+
metadata: {}
|
|
245
238
|
post_install_message:
|
|
246
239
|
rdoc_options: []
|
|
247
240
|
require_paths:
|
|
248
241
|
- lib
|
|
249
242
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
250
|
-
none: false
|
|
251
243
|
requirements:
|
|
252
|
-
- -
|
|
244
|
+
- - ">="
|
|
253
245
|
- !ruby/object:Gem::Version
|
|
254
246
|
version: '0'
|
|
255
|
-
segments:
|
|
256
|
-
- 0
|
|
257
|
-
hash: -882451281331760104
|
|
258
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
|
-
none: false
|
|
260
248
|
requirements:
|
|
261
|
-
- -
|
|
249
|
+
- - ">="
|
|
262
250
|
- !ruby/object:Gem::Version
|
|
263
251
|
version: '0'
|
|
264
|
-
segments:
|
|
265
|
-
- 0
|
|
266
|
-
hash: -882451281331760104
|
|
267
252
|
requirements: []
|
|
268
253
|
rubyforge_project:
|
|
269
|
-
rubygems_version:
|
|
254
|
+
rubygems_version: 2.2.2
|
|
270
255
|
signing_key:
|
|
271
|
-
specification_version:
|
|
256
|
+
specification_version: 4
|
|
272
257
|
summary: Simple HMAC authentication for your APIs
|
|
273
258
|
test_files:
|
|
274
259
|
- spec/api_auth_spec.rb
|