aggcat 0.1.9 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/lib/aggcat/base.rb +7 -6
- data/lib/aggcat/client.rb +18 -9
- data/lib/aggcat/configurable.rb +2 -2
- data/lib/aggcat/version.rb +1 -1
- data/test/aggcat/client_test.rb +22 -0
- metadata +2 -2
data/.travis.yml
CHANGED
data/lib/aggcat/base.rb
CHANGED
@@ -21,7 +21,8 @@ module Aggcat
|
|
21
21
|
TIME_FORMAT = '%Y-%m-%dT%T.%LZ'
|
22
22
|
DATE_FORMAT = '%Y-%m-%d'
|
23
23
|
|
24
|
-
|
24
|
+
OPEN_TIMEOUT = 15
|
25
|
+
READ_TIMEOUT = 120
|
25
26
|
|
26
27
|
protected
|
27
28
|
|
@@ -30,12 +31,12 @@ module Aggcat
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def oauth_consumer
|
33
|
-
@oauth_consumer ||= OAuth::Consumer.new(@consumer_key, @consumer_secret, {:
|
34
|
+
@oauth_consumer ||= OAuth::Consumer.new(@consumer_key, @consumer_secret, {timeout: READ_TIMEOUT, open_timeout: OPEN_TIMEOUT, verbose: @verbose})
|
34
35
|
end
|
35
36
|
|
36
|
-
def oauth_token
|
37
|
+
def oauth_token(force=false)
|
37
38
|
now = Time.now
|
38
|
-
if @oauth_token.nil? || @oauth_token_expire_at <= now
|
39
|
+
if force || @oauth_token.nil? || @oauth_token_expire_at <= now
|
39
40
|
@oauth_token = new_token(saml_message(@customer_id))
|
40
41
|
@oauth_token_expire_at = now + 9 * 60 # 9 minutes
|
41
42
|
end
|
@@ -50,7 +51,7 @@ module Aggcat
|
|
50
51
|
request.set_form_data({:saml_assertion => message})
|
51
52
|
http.use_ssl = true
|
52
53
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
53
|
-
|
54
|
+
http.set_debug_output($stdout) if @verbose
|
54
55
|
response = http.request(request)
|
55
56
|
params = CGI::parse(response.body)
|
56
57
|
[params['oauth_token'][0], params['oauth_token_secret'][0]]
|
@@ -63,7 +64,7 @@ module Aggcat
|
|
63
64
|
digest = Base64.encode64(OpenSSL::Digest::SHA1.digest(assertion)).strip
|
64
65
|
signed_info = %[<ds:SignedInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod><ds:Reference URI="#_#{reference_id}"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:Transform></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod><ds:DigestValue>#{digest}</ds:DigestValue></ds:Reference></ds:SignedInfo>]
|
65
66
|
key = OpenSSL::PKey::RSA.new(File.read(@certificate_path))
|
66
|
-
signature_value = Base64.encode64(key.sign(OpenSSL::Digest::SHA1.new, signed_info)).gsub(/\n/, '')
|
67
|
+
signature_value = Base64.encode64(key.sign(OpenSSL::Digest::SHA1.new(nil), signed_info)).gsub(/\n/, '')
|
67
68
|
signature = %[<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="#_#{reference_id}"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>#{digest}</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>#{signature_value}</ds:SignatureValue></ds:Signature>]
|
68
69
|
assertion_with_signature = assertion.sub(/saml2:Issuer\>\<saml2:Subject/, "saml2:Issuer>#{signature}<saml2:Subject")
|
69
70
|
Base64.encode64(assertion_with_signature)
|
data/lib/aggcat/client.rb
CHANGED
@@ -5,8 +5,9 @@ module Aggcat
|
|
5
5
|
|
6
6
|
def initialize(options={})
|
7
7
|
raise ArgumentError.new('customer_id is required for scoping all requests') if options[:customer_id].nil? || options[:customer_id].to_s.empty?
|
8
|
+
options[:verbose] ||= false
|
8
9
|
Aggcat::Configurable::KEYS.each do |key|
|
9
|
-
instance_variable_set(:"@#{key}", options[key]
|
10
|
+
instance_variable_set(:"@#{key}", !options[key].nil? ? options[key] : Aggcat.instance_variable_get(:"@#{key}"))
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -90,14 +91,22 @@ module Aggcat
|
|
90
91
|
|
91
92
|
private
|
92
93
|
|
93
|
-
def request(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
result
|
98
|
-
|
99
|
-
|
100
|
-
|
94
|
+
def request(http_method, path, *options)
|
95
|
+
tries = 0
|
96
|
+
begin
|
97
|
+
response = oauth_client.send(http_method, BASE_URL + path, *options)
|
98
|
+
result = {:status_code => response.code, :result => parse_xml(response.body)}
|
99
|
+
if response['challengeSessionId']
|
100
|
+
result[:challenge_session_id] = response['challengeSessionId']
|
101
|
+
result[:challenge_node_id] = response['challengeNodeId']
|
102
|
+
end
|
103
|
+
return result
|
104
|
+
rescue => e
|
105
|
+
raise e if tries >= 1
|
106
|
+
puts "failed to make API call - #{e.message}, retrying"
|
107
|
+
oauth_token(true)
|
108
|
+
tries += 1
|
109
|
+
end while tries == 1
|
101
110
|
end
|
102
111
|
|
103
112
|
def validate(args)
|
data/lib/aggcat/configurable.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Aggcat
|
2
2
|
module Configurable
|
3
3
|
|
4
|
-
attr_writer :issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id
|
4
|
+
attr_writer :issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id, :verbose
|
5
5
|
|
6
|
-
KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id]
|
6
|
+
KEYS = [:issuer_id, :consumer_key, :consumer_secret, :certificate_path, :customer_id, :verbose]
|
7
7
|
|
8
8
|
def configure
|
9
9
|
yield self
|
data/lib/aggcat/version.rb
CHANGED
data/test/aggcat/client_test.rb
CHANGED
@@ -14,6 +14,15 @@ class ClientTest < Test::Unit::TestCase
|
|
14
14
|
)
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_arguments
|
18
|
+
assert_equal 'issuer_id', @client.instance_variable_get(:'@issuer_id')
|
19
|
+
assert_equal 'consumer_key', @client.instance_variable_get(:'@consumer_key')
|
20
|
+
assert_equal 'consumer_secret', @client.instance_variable_get(:'@consumer_secret')
|
21
|
+
assert_equal "#{fixture_path}/cert.key", @client.instance_variable_get(:'@certificate_path')
|
22
|
+
assert_equal 'default', @client.instance_variable_get(:'@customer_id')
|
23
|
+
assert_equal false, @client.instance_variable_get(:'@verbose')
|
24
|
+
end
|
25
|
+
|
17
26
|
def test_institutions
|
18
27
|
stub_get('/institutions').to_return(:body => fixture('institutions.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
|
19
28
|
response = @client.institutions
|
@@ -191,4 +200,17 @@ class ClientTest < Test::Unit::TestCase
|
|
191
200
|
@client.update_login_confirmation(login_id, challenge_session_id, challenge_node_id, answer)
|
192
201
|
end
|
193
202
|
|
203
|
+
def test_retry_success
|
204
|
+
institution_id = '100000'
|
205
|
+
stub_get("/institutions/#{institution_id}").to_timeout.times(1).then.to_return(:body => fixture('institution.xml'), :headers => {:content_type => 'application/xml; charset=utf-8'})
|
206
|
+
response = @client.institution(institution_id)
|
207
|
+
assert_equal institution_id, response[:result][:institution_detail][:institution_id]
|
208
|
+
end
|
209
|
+
|
210
|
+
def test_retry_failure
|
211
|
+
institution_id = '100000'
|
212
|
+
stub_get("/institutions/#{institution_id}").to_timeout.times(2)
|
213
|
+
assert_raise(Timeout::Error) { @client.institution(institution_id) }
|
214
|
+
end
|
215
|
+
|
194
216
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aggcat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
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: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|