jimmyz-fs-communicator 0.1.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.
- data/VERSION.yml +4 -0
- data/lib/assets/entrust-ca.crt +104 -0
- data/lib/fs_communicator.rb +66 -0
- data/spec/fs_communicator_spec.rb +117 -0
- data/spec/spec_helper.rb +7 -0
- metadata +59 -0
data/VERSION.yml
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
##
|
2
|
+
## $Id: ca-bundle.crt,v 1.2 2003/03/24 11:06:57 bagder Exp $
|
3
|
+
##
|
4
|
+
## ca-bundle.crt -- Bundle of CA Root Certificates
|
5
|
+
## Last Modified: Thu Mar 2 09:32:46 CET 2000
|
6
|
+
##
|
7
|
+
## This is a bundle of X.509 certificates of public
|
8
|
+
## Certificate Authorities (CA). These were automatically
|
9
|
+
## extracted from Netscape Communicator 4.72's certificate database
|
10
|
+
## (the file `cert7.db'). It contains the certificates in both
|
11
|
+
## plain text and PEM format and therefore can be directly used
|
12
|
+
## with an Apache+mod_ssl webserver for SSL client authentication.
|
13
|
+
## Just configure this file as the SSLCACertificateFile.
|
14
|
+
##
|
15
|
+
## (SKIPME)
|
16
|
+
##
|
17
|
+
|
18
|
+
|
19
|
+
Entrust.net Secure Server CA
|
20
|
+
============================
|
21
|
+
MD5 Fingerprint: DF:F2:80:73:CC:F1:E6:61:73:FC:F5:42:E9:C5:7C:EE
|
22
|
+
PEM Data:
|
23
|
+
-----BEGIN CERTIFICATE-----
|
24
|
+
MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMC
|
25
|
+
VVMxFDASBgNVBAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5u
|
26
|
+
ZXQvQ1BTIGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMc
|
27
|
+
KGMpIDE5OTkgRW50cnVzdC5uZXQgT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|
+
b24gQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMCmgJ6AlhiNodHRwOi8vd3d3LmVu
|
43
|
+
dHJ1c3QubmV0L0NSTC9uZXQxLmNybDArBgNVHRAEJDAigA8xOTk5MDUyNTE2MDk0
|
44
|
+
MFqBDzIwMTkwNTI1MTYwOTQwWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAU8Bdi
|
45
|
+
E1U9s/8KAGv7UISX8+1i0BowHQYDVR0OBBYEFPAXYhNVPbP/CgBr+1CEl/PtYtAa
|
46
|
+
MAwGA1UdEwQFMAMBAf8wGQYJKoZIhvZ9B0EABAwwChsEVjQuMAMCBJAwDQYJKoZI
|
47
|
+
hvcNAQEFBQADgYEAkNwwAvpkdMKnCqV8IY00F6j7Rw7/JXyNEwr75Ji174z4xRAN
|
48
|
+
95K+8cPV1ZVqBLssziY2ZcgxxufuP+NXdYR6Ee9GTxj005i7qIcyunL2POI9n9cd
|
49
|
+
2cNgQ4xYDiKWL2KjLB+6rQXvqzJ4h6BUcxm1XAX5Uj5tLUUL9wqT6u0G+bI=
|
50
|
+
-----END CERTIFICATE-----
|
51
|
+
Certificate Ingredients:
|
52
|
+
Data:
|
53
|
+
Version: 3 (0x2)
|
54
|
+
Serial Number: 927650371 (0x374ad243)
|
55
|
+
Signature Algorithm: sha1WithRSAEncryption
|
56
|
+
Issuer: C=US, O=Entrust.net, OU=www.entrust.net/CPS incorp. by ref. (limits liab.), OU=(c) 1999 Entrust.net Limited, CN=Entrust.net Secure Server Certification Authority
|
57
|
+
Validity
|
58
|
+
Not Before: May 25 16:09:40 1999 GMT
|
59
|
+
Not After : May 25 16:39:40 2019 GMT
|
60
|
+
Subject: C=US, O=Entrust.net, OU=www.entrust.net/CPS incorp. by ref. (limits liab.), OU=(c) 1999 Entrust.net Limited, CN=Entrust.net Secure Server Certification Authority
|
61
|
+
Subject Public Key Info:
|
62
|
+
Public Key Algorithm: rsaEncryption
|
63
|
+
RSA Public Key: (1024 bit)
|
64
|
+
Modulus (1024 bit):
|
65
|
+
00:cd:28:83:34:54:1b:89:f3:0f:af:37:91:31:ff:
|
66
|
+
af:31:60:c9:a8:e8:b2:10:68:ed:9f:e7:93:36:f1:
|
67
|
+
0a:64:bb:47:f5:04:17:3f:23:47:4d:c5:27:19:81:
|
68
|
+
26:0c:54:72:0d:88:2d:d9:1f:9a:12:9f:bc:b3:71:
|
69
|
+
d3:80:19:3f:47:66:7b:8c:35:28:d2:b9:0a:df:24:
|
70
|
+
da:9c:d6:50:79:81:7a:5a:d3:37:f7:c2:4a:d8:29:
|
71
|
+
92:26:64:d1:e4:98:6c:3a:00:8a:f5:34:9b:65:f8:
|
72
|
+
ed:e3:10:ff:fd:b8:49:58:dc:a0:de:82:39:6b:81:
|
73
|
+
b1:16:19:61:b9:54:b6:e6:43
|
74
|
+
Exponent: 3 (0x3)
|
75
|
+
X509v3 extensions:
|
76
|
+
Netscape Cert Type:
|
77
|
+
SSL CA, S/MIME CA, Object Signing CA
|
78
|
+
X509v3 CRL Distribution Points:
|
79
|
+
DirName:/C=US/O=Entrust.net/OU=www.entrust.net/CPS incorp. by ref. (limits liab.)/OU=(c) 1999 Entrust.net Limited/CN=Entrust.net Secure Server Certification Authority/CN=CRL1
|
80
|
+
URI:http://www.entrust.net/CRL/net1.crl
|
81
|
+
|
82
|
+
X509v3 Private Key Usage Period:
|
83
|
+
Not Before: May 25 16:09:40 1999 GMT, Not After: May 25 16:09:40 2019 GMT
|
84
|
+
X509v3 Key Usage:
|
85
|
+
Certificate Sign, CRL Sign
|
86
|
+
X509v3 Authority Key Identifier:
|
87
|
+
keyid:F0:17:62:13:55:3D:B3:FF:0A:00:6B:FB:50:84:97:F3:ED:62:D0:1A
|
88
|
+
|
89
|
+
X509v3 Subject Key Identifier:
|
90
|
+
F0:17:62:13:55:3D:B3:FF:0A:00:6B:FB:50:84:97:F3:ED:62:D0:1A
|
91
|
+
X509v3 Basic Constraints:
|
92
|
+
CA:TRUE
|
93
|
+
1.2.840.113533.7.65.0:
|
94
|
+
0
|
95
|
+
..V4.0....
|
96
|
+
Signature Algorithm: sha1WithRSAEncryption
|
97
|
+
90:dc:30:02:fa:64:74:c2:a7:0a:a5:7c:21:8d:34:17:a8:fb:
|
98
|
+
47:0e:ff:25:7c:8d:13:0a:fb:e4:98:b5:ef:8c:f8:c5:10:0d:
|
99
|
+
f7:92:be:f1:c3:d5:d5:95:6a:04:bb:2c:ce:26:36:65:c8:31:
|
100
|
+
c6:e7:ee:3f:e3:57:75:84:7a:11:ef:46:4f:18:f4:d3:98:bb:
|
101
|
+
a8:87:32:ba:72:f6:3c:e2:3d:9f:d7:1d:d9:c3:60:43:8c:58:
|
102
|
+
0e:22:96:2f:62:a3:2c:1f:ba:ad:05:ef:ab:32:78:87:a0:54:
|
103
|
+
73:19:b5:5c:05:f9:52:3e:6d:2d:45:0b:f7:0a:93:ea:ed:06:
|
104
|
+
f9:b2
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
class FsCommunicator
|
5
|
+
attr_accessor :domain, :key, :user_agent, :session
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
# merge default options with options hash
|
9
|
+
o = {
|
10
|
+
:domain => 'http://www.dev.usys.org',
|
11
|
+
:key => '',
|
12
|
+
:user_agent => 'FsCommunicator/0.1 (Ruby)',
|
13
|
+
:session => nil
|
14
|
+
}.merge(options)
|
15
|
+
@domain = o[:domain]
|
16
|
+
@key = o[:key]
|
17
|
+
@user_agent = o[:user_agent]
|
18
|
+
@session = o[:session]
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(url,credentials = {})
|
22
|
+
uri = URI.parse(self.domain+url)
|
23
|
+
full_url = set_extra_params(uri,credentials)
|
24
|
+
request = Net::HTTP::Get.new(full_url)
|
25
|
+
if credentials[:username] && credentials[:password]
|
26
|
+
request.basic_auth credentials[:username], credentials[:password]
|
27
|
+
request['User-Agent'] = self.user_agent
|
28
|
+
end
|
29
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
30
|
+
if uri.scheme == 'https'
|
31
|
+
http.use_ssl = true
|
32
|
+
http.ca_file = File.join File.dirname(__FILE__), 'assets','entrust-ca.crt'
|
33
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
34
|
+
end
|
35
|
+
res = http.start do |ht|
|
36
|
+
ht.request(request)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def set_extra_params(uri,credentials)
|
42
|
+
if credentials[:username] && credentials[:password]
|
43
|
+
sessionized_url = add_key(uri)
|
44
|
+
else
|
45
|
+
sessionized_url = add_session(uri)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_session(uri)
|
50
|
+
if uri.query
|
51
|
+
uri.query << '&sessionId=' + self.session
|
52
|
+
else
|
53
|
+
uri.query = 'sessionId=' + self.session
|
54
|
+
end
|
55
|
+
uri.request_uri
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_key(uri)
|
59
|
+
if uri.query
|
60
|
+
uri.query << '&key=' + self.key
|
61
|
+
else
|
62
|
+
uri.query = 'key=' + self.key
|
63
|
+
end
|
64
|
+
uri.request_uri
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module HttpCommunicatorHelper
|
4
|
+
|
5
|
+
def stub_net_objects
|
6
|
+
@request = mock("Net::HTTP::Get")
|
7
|
+
# @request.stub!(:[]=)
|
8
|
+
@http = mock("Net::HTTP")
|
9
|
+
Net::HTTP.stub!(:new).and_return(@http)
|
10
|
+
Net::HTTP::Get.stub!(:new).and_return(@request)
|
11
|
+
@http.stub!(:use_ssl=)
|
12
|
+
@http.stub!(:ca_file=)
|
13
|
+
@http.stub!(:verify_mode=)
|
14
|
+
@http.stub!(:start)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe FsCommunicator do
|
20
|
+
include HttpCommunicatorHelper
|
21
|
+
describe "initializing" do
|
22
|
+
it "should accept a hash of options" do
|
23
|
+
lambda {
|
24
|
+
com = FsCommunicator.new :domain => 'https://api.familysearch.org', :key => '1111-1111', :user_agent => "FsCommunicator/0.1"
|
25
|
+
}.should_not raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should set defaults to the Reference System" do
|
29
|
+
com = FsCommunicator.new
|
30
|
+
com.domain.should == 'http://www.dev.usys.org'
|
31
|
+
com.key.should == ''
|
32
|
+
com.user_agent.should == 'FsCommunicator/0.1 (Ruby)'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should set the domain, key, and user_agent to options hash" do
|
36
|
+
options = {
|
37
|
+
:domain => 'https://api.familysearch.org',
|
38
|
+
:key => '1111-1111',
|
39
|
+
:user_agent => "RSpecTest/0.1",
|
40
|
+
:session => 'SESSID'
|
41
|
+
}
|
42
|
+
com = FsCommunicator.new options
|
43
|
+
com.domain.should == options[:domain]
|
44
|
+
com.key.should == options[:key]
|
45
|
+
com.user_agent.should == options[:user_agent]
|
46
|
+
com.session.should == options[:session]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "GET on a URL" do
|
51
|
+
before(:each) do
|
52
|
+
options = {
|
53
|
+
:domain => 'https://api.familysearch.org',
|
54
|
+
:key => '1111-1111',
|
55
|
+
:user_agent => "FsCommunicator/0.1",
|
56
|
+
:session => 'SESSID'
|
57
|
+
}
|
58
|
+
@com = FsCommunicator.new options
|
59
|
+
stub_net_objects
|
60
|
+
@url = '/familytree/v1/person/KWQS-BBQ'
|
61
|
+
@session_url = @url + "?sessionId=#{@com.session}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def do_get(url, credentials = {})
|
65
|
+
@com.get(url, credentials)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should initialize a Net::HTTP object to make the request" do
|
69
|
+
Net::HTTP.should_receive(:new).with('api.familysearch.org',443).and_return(@http)
|
70
|
+
do_get(@url)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should create a GET request with url containing a session" do
|
74
|
+
Net::HTTP::Get.should_receive(:new).with(@session_url).and_return(@request)
|
75
|
+
do_get(@url)
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should tack a sessionId as an additional parameter if params already set" do
|
79
|
+
url = "/familytree/v1/person/KWQS-BBQ?view=summary"
|
80
|
+
Net::HTTP::Get.should_receive(:new).with(url+"&sessionId=#{@com.session}").and_return(@request)
|
81
|
+
do_get(url)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should set the http object to use ssl if https" do
|
85
|
+
@http.should_receive(:use_ssl=).with(true)
|
86
|
+
do_get(@url)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not set the http object to use ssl if no http" do
|
90
|
+
@com.domain = 'http://www.dev.usys.org'
|
91
|
+
@http.should_not_receive(:use_ssl=)
|
92
|
+
do_get(@url)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should set the ca file to the entrust certificate (for FamilySearch systems)" do
|
96
|
+
@http.should_receive(:ca_file=).with(File.join(File.dirname(__FILE__),'..','lib','assets','entrust-ca.crt'))
|
97
|
+
do_get(@url)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should set the basic_authentication if the credentials passed as parameters" do
|
101
|
+
@request.should_receive(:basic_auth).with('user','pass')
|
102
|
+
@request.should_receive(:[]=).with('User-Agent',@com.user_agent)
|
103
|
+
Net::HTTP::Get.should_receive(:new).with(@url+"?key=#{@com.key}").and_return(@request)
|
104
|
+
do_get(@url,:username => 'user',:password => 'pass')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should make the request" do
|
108
|
+
block = lambda{ |ht|
|
109
|
+
ht.request('something')
|
110
|
+
}
|
111
|
+
@http.should_receive(:start)
|
112
|
+
do_get(@url)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jimmyz-fs-communicator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jimmy Zimmerman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-02 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: TODO
|
17
|
+
email: jimmy.zimmerman@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- VERSION.yml
|
26
|
+
- lib/assets
|
27
|
+
- lib/assets/entrust-ca.crt
|
28
|
+
- lib/fs_communicator.rb
|
29
|
+
- spec/fs_communicator_spec.rb
|
30
|
+
- spec/spec_helper.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/jimmyz/fs-communicator
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options:
|
35
|
+
- --inline-source
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.2.0
|
55
|
+
signing_key:
|
56
|
+
specification_version: 2
|
57
|
+
summary: TODO
|
58
|
+
test_files: []
|
59
|
+
|