omnicontacts 0.3.4 → 0.3.5
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/.gitignore +1 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +24 -18
- data/README.md +100 -23
- data/lib/omnicontacts.rb +5 -2
- data/lib/omnicontacts/http_utils.rb +1 -1
- data/lib/omnicontacts/importer/facebook.rb +35 -8
- data/lib/omnicontacts/importer/gmail.rb +147 -11
- data/lib/omnicontacts/importer/hotmail.rb +40 -9
- data/lib/omnicontacts/importer/yahoo.rb +107 -14
- data/lib/omnicontacts/middleware/base_oauth.rb +18 -3
- data/lib/omnicontacts/middleware/oauth1.rb +4 -2
- data/lib/omnicontacts/middleware/oauth2.rb +3 -2
- data/lib/omnicontacts/parse_utils.rb +15 -1
- data/omnicontacts.gemspec +2 -2
- data/spec/omnicontacts/authorization/oauth1_spec.rb +2 -2
- data/spec/omnicontacts/http_utils_spec.rb +6 -0
- data/spec/omnicontacts/importer/facebook_spec.rb +68 -6
- data/spec/omnicontacts/importer/gmail_spec.rb +97 -4
- data/spec/omnicontacts/importer/hotmail_spec.rb +53 -3
- data/spec/omnicontacts/importer/yahoo_spec.rb +62 -6
- data/spec/omnicontacts/middleware/base_oauth_spec.rb +12 -6
- data/spec/omnicontacts/middleware/oauth1_spec.rb +11 -5
- data/spec/omnicontacts/middleware/oauth2_spec.rb +7 -2
- data/spec/omnicontacts/parse_utils_spec.rb +53 -0
- data/spec/spec_helper.rb +2 -0
- metadata +52 -33
@@ -5,6 +5,19 @@ describe OmniContacts::Importer::Gmail do
|
|
5
5
|
|
6
6
|
let(:gmail) { OmniContacts::Importer::Gmail.new({}, "client_id", "client_secret") }
|
7
7
|
|
8
|
+
let(:self_response) {
|
9
|
+
'{
|
10
|
+
"id":"16482944006464829443",
|
11
|
+
"email":"chrisjohnson@gmail.com",
|
12
|
+
"name":"Chris Johnson",
|
13
|
+
"given_name":"Chris",
|
14
|
+
"family_name":"Johnson",
|
15
|
+
"picture":"https://lh3.googleusercontent.com/-b8aFbTBM/AAAAAAI/IWA/vsek/photo.jpg",
|
16
|
+
"gender":"male",
|
17
|
+
"birthday":"1982-06-21"
|
18
|
+
}'
|
19
|
+
}
|
20
|
+
|
8
21
|
let(:contacts_as_json) {
|
9
22
|
'{"version":"1.0","encoding":"UTF-8",
|
10
23
|
"feed":{
|
@@ -31,7 +44,7 @@ describe OmniContacts::Importer::Gmail do
|
|
31
44
|
{"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full?alt\u003djson\u0026max-results\u003d1"},
|
32
45
|
{"rel":"next","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full?alt\u003djson\u0026start-index\u003d2\u0026max-results\u003d1"}
|
33
46
|
],
|
34
|
-
"author":[{"name":{"$t":"
|
47
|
+
"author":[{"name":{"$t":"Edward"},"email":{"$t":"logged_in_user@gmail.com"}}],
|
35
48
|
"generator":{"version":"1.0","uri":"http://www.google.com/m8/feeds","$t":"Contacts"},
|
36
49
|
"openSearch$totalResults":{"$t":"1007"},
|
37
50
|
"openSearch$startIndex":{"$t":"1"},
|
@@ -54,10 +67,37 @@ describe OmniContacts::Importer::Gmail do
|
|
54
67
|
"gd$givenName":{"$t":"Edward"},
|
55
68
|
"gd$familyName":{"$t":"Bennet"}
|
56
69
|
},
|
70
|
+
"gd$organization":[{"rel":"http://schemas.google.com/g/2005#other","gd$orgName":{"$t":"Google"},"gd$orgTitle":{"$t":"Master Developer"}}],
|
57
71
|
"gContact$birthday":{"when":"1954-07-02"},
|
58
72
|
"gContact$relation":{"rel":"father"},
|
59
73
|
"gContact$gender":{"value":"male"},
|
74
|
+
"gContact$event":[{"rel":"anniversary","gd$when":{"startTime":"1983-04-21"}},{"label":"New Job","gd$when":{"startTime":"2014-12-01"}}],
|
60
75
|
"gd$email":[{"rel":"http://schemas.google.com/g/2005#other","address":"bennet@gmail.com","primary":"true"}],
|
76
|
+
"gContact$groupMembershipInfo":[{"deleted":"false","href":"http://www.google.com/m8/feeds/groups/logged_in_user%40gmail.com/base/6"}],
|
77
|
+
"gd$structuredPostalAddress":[{"rel":"http://schemas.google.com/g/2005#home","gd$formattedAddress":{"$t":"1313 Trashview Court\nApt. 13\nNowheresville, OK 66666"},"gd$street":{"$t":"1313 Trashview Court\nApt. 13"},"gd$postcode":{"$t":"66666"},"gd$country":{"code":"VA","$t":"Valoran"},"gd$city":{"$t":"Nowheresville"},"gd$region":{"$t":"OK"}}],
|
78
|
+
"gd$phoneNumber":[{"rel":"http://schemas.google.com/g/2005#mobile","uri":"tel:+34-653-15-76-88","$t":"653157688"}]
|
79
|
+
},
|
80
|
+
{
|
81
|
+
"gd$etag":"\"R3oyfDVSLyt7I2A9WhBTSEULRA0.\"",
|
82
|
+
"id":{"$t":"http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1"},
|
83
|
+
"updated":{"$t":"2013-02-15T22:36:36.494Z"},
|
84
|
+
"app$edited":{"xmlns$app":"http://www.w3.org/2007/app","$t":"2013-02-15T22:36:36.494Z"},
|
85
|
+
"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/contact/2008#contact"}],
|
86
|
+
"title":{"$t":"Emilia Fox"},
|
87
|
+
"link":[
|
88
|
+
{"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*","href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/1"},
|
89
|
+
{"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"},
|
90
|
+
{"rel":"edit","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"}
|
91
|
+
],
|
92
|
+
"gd$name":{
|
93
|
+
"gd$fullName":{"$t":"Emilia Fox"},
|
94
|
+
"gd$givenName":{"$t":"Emilia"},
|
95
|
+
"gd$familyName":{"$t":"Fox"}
|
96
|
+
},
|
97
|
+
"gContact$birthday":{"when":"1974-02-10"},
|
98
|
+
"gContact$relation":[{"rel":"spouse"}],
|
99
|
+
"gContact$gender":{"value":"female"},
|
100
|
+
"gd$email":[{"rel":"http://schemas.google.com/g/2005#other","address":"emilia.fox@gmail.com","primary":"true"}],
|
61
101
|
"gContact$groupMembershipInfo":[{"deleted":"false","href":"http://www.google.com/m8/feeds/groups/logged_in_user%40gmail.com/base/6"}]
|
62
102
|
}]
|
63
103
|
}
|
@@ -68,7 +108,16 @@ describe OmniContacts::Importer::Gmail do
|
|
68
108
|
let(:token) { "token" }
|
69
109
|
let(:token_type) { "token_type" }
|
70
110
|
|
111
|
+
before(:each) do
|
112
|
+
gmail.instance_variable_set(:@env, {})
|
113
|
+
end
|
114
|
+
|
71
115
|
it "should request the contacts by specifying version and code in the http headers" do
|
116
|
+
gmail.should_receive(:https_get) do |host, path, params, headers|
|
117
|
+
headers["GData-Version"].should eq("3.0")
|
118
|
+
headers["Authorization"].should eq("#{token_type} #{token}")
|
119
|
+
self_response
|
120
|
+
end
|
72
121
|
gmail.should_receive(:https_get) do |host, path, params, headers|
|
73
122
|
headers["GData-Version"].should eq("3.0")
|
74
123
|
headers["Authorization"].should eq("#{token_type} #{token}")
|
@@ -77,10 +126,12 @@ describe OmniContacts::Importer::Gmail do
|
|
77
126
|
gmail.fetch_contacts_using_access_token token, token_type
|
78
127
|
end
|
79
128
|
|
80
|
-
it "should correctly parse id, name,email,gender, birthday,
|
129
|
+
it "should correctly parse id, name, email, gender, birthday, profile picture and relation for 1st contact" do
|
130
|
+
gmail.should_receive(:https_get)
|
81
131
|
gmail.should_receive(:https_get).and_return(contacts_as_json)
|
82
132
|
result = gmail.fetch_contacts_using_access_token token, token_type
|
83
|
-
|
133
|
+
|
134
|
+
result.size.should be(2)
|
84
135
|
result.first[:id].should eq('http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1')
|
85
136
|
result.first[:first_name].should eq('Edward')
|
86
137
|
result.first[:last_name].should eq('Bennet')
|
@@ -89,7 +140,49 @@ describe OmniContacts::Importer::Gmail do
|
|
89
140
|
result.first[:gender].should eq("male")
|
90
141
|
result.first[:birthday].should eq({:day=>02, :month=>07, :year=>1954})
|
91
142
|
result.first[:relation].should eq('father')
|
143
|
+
result.first[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/bennet")
|
144
|
+
result.first[:dates][0][:name].should eq("anniversary")
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should correctly parse id, name, email, gender, birthday, profile picture, snailmail address, phone and relation for 2nd contact" do
|
148
|
+
gmail.should_receive(:https_get)
|
149
|
+
gmail.should_receive(:https_get).and_return(contacts_as_json)
|
150
|
+
result = gmail.fetch_contacts_using_access_token token, token_type
|
151
|
+
result.size.should be(2)
|
152
|
+
result.last[:id].should eq('http://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/base/1')
|
153
|
+
result.last[:first_name].should eq('Emilia')
|
154
|
+
result.last[:last_name].should eq('Fox')
|
155
|
+
result.last[:name].should eq("Emilia Fox")
|
156
|
+
result.last[:email].should eq("emilia.fox@gmail.com")
|
157
|
+
result.last[:gender].should eq("female")
|
158
|
+
result.last[:birthday].should eq({:day=>10, :month=>02, :year=>1974})
|
159
|
+
result.last[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/emilia.fox")
|
160
|
+
result.last[:relation].should eq('spouse')
|
161
|
+
result.first[:address_1].should eq('1313 Trashview Court')
|
162
|
+
result.first[:address_2].should eq('Apt. 13')
|
163
|
+
result.first[:city].should eq('Nowheresville')
|
164
|
+
result.first[:region].should eq('OK')
|
165
|
+
result.first[:country].should eq('VA')
|
166
|
+
result.first[:postcode].should eq('66666')
|
167
|
+
result.first[:phone_number].should eq('653157688')
|
92
168
|
end
|
93
169
|
|
170
|
+
it "should correctly parse and set logged in user information" do
|
171
|
+
gmail.should_receive(:https_get).and_return(self_response)
|
172
|
+
gmail.should_receive(:https_get).and_return(contacts_as_json)
|
173
|
+
|
174
|
+
gmail.fetch_contacts_using_access_token token, token_type
|
175
|
+
|
176
|
+
user = gmail.instance_variable_get(:@env)["omnicontacts.user"]
|
177
|
+
user.should_not be_nil
|
178
|
+
user[:id].should eq("16482944006464829443")
|
179
|
+
user[:first_name].should eq("Chris")
|
180
|
+
user[:last_name].should eq("Johnson")
|
181
|
+
user[:name].should eq("Chris Johnson")
|
182
|
+
user[:email].should eq("chrisjohnson@gmail.com")
|
183
|
+
user[:gender].should eq("male")
|
184
|
+
user[:birthday].should eq({:day=>21, :month=>06, :year=>1982})
|
185
|
+
user[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/16482944006464829443")
|
186
|
+
end
|
94
187
|
end
|
95
|
-
end
|
188
|
+
end
|
@@ -3,7 +3,22 @@ require "omnicontacts/importer/hotmail"
|
|
3
3
|
|
4
4
|
describe OmniContacts::Importer::Hotmail do
|
5
5
|
|
6
|
-
let(:
|
6
|
+
let(:permissions) { "perm1, perm2" }
|
7
|
+
let(:hotmail) { OmniContacts::Importer::Hotmail.new({}, "client_id", "client_secret", {:permissions => permissions}) }
|
8
|
+
|
9
|
+
let(:self_response) {
|
10
|
+
'{
|
11
|
+
"id": "4502de12390223d0",
|
12
|
+
"name": "Chris Johnson",
|
13
|
+
"first_name": "Chris",
|
14
|
+
"last_name": "Johnson",
|
15
|
+
"birth_day": 21,
|
16
|
+
"birth_month": 6,
|
17
|
+
"birth_year": 1982,
|
18
|
+
"gender": null,
|
19
|
+
"emails": {"preferred":"chrisjohnson@gmail.com", "account":"chrisjohn@gmail.com", "personal":null, "business":null}
|
20
|
+
}'
|
21
|
+
}
|
7
22
|
|
8
23
|
let(:contacts_as_json) {
|
9
24
|
'{
|
@@ -19,7 +34,8 @@ describe OmniContacts::Importer::Hotmail do
|
|
19
34
|
"is_favorite": false,
|
20
35
|
"birth_day": 5,
|
21
36
|
"birth_month": 6,
|
22
|
-
"birth_year":1952
|
37
|
+
"birth_year":1952,
|
38
|
+
"email_hashes":["1234567890"]
|
23
39
|
}
|
24
40
|
]}'
|
25
41
|
}
|
@@ -29,7 +45,16 @@ describe OmniContacts::Importer::Hotmail do
|
|
29
45
|
let(:token) { "token" }
|
30
46
|
let(:token_type) { "token_type" }
|
31
47
|
|
48
|
+
before(:each) do
|
49
|
+
hotmail.instance_variable_set(:@env, {"HTTP_HOST" => "http://example.com"})
|
50
|
+
end
|
51
|
+
|
32
52
|
it "should request the contacts by providing the token in the url" do
|
53
|
+
hotmail.should_receive(:https_get) do |host, path, params, headers|
|
54
|
+
params[:access_token].should eq(token)
|
55
|
+
self_response
|
56
|
+
end
|
57
|
+
|
33
58
|
hotmail.should_receive(:https_get) do |host, path, params, headers|
|
34
59
|
params[:access_token].should eq(token)
|
35
60
|
contacts_as_json
|
@@ -37,9 +62,15 @@ describe OmniContacts::Importer::Hotmail do
|
|
37
62
|
hotmail.fetch_contacts_using_access_token token, token_type
|
38
63
|
end
|
39
64
|
|
40
|
-
it "should
|
65
|
+
it "should set requested permissions in the authorization url" do
|
66
|
+
hotmail.authorization_url.should match(/scope=#{Regexp.quote(CGI.escape(permissions))}/)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should correctly parse id, name, email, gender, birthday, profile picture, relation and email hashes" do
|
70
|
+
hotmail.should_receive(:https_get).and_return(self_response)
|
41
71
|
hotmail.should_receive(:https_get).and_return(contacts_as_json)
|
42
72
|
result = hotmail.fetch_contacts_using_access_token token, token_type
|
73
|
+
|
43
74
|
result.size.should be(1)
|
44
75
|
result.first[:id].should eq('123456')
|
45
76
|
result.first[:first_name].should eq("John")
|
@@ -50,6 +81,25 @@ describe OmniContacts::Importer::Hotmail do
|
|
50
81
|
result.first[:birthday].should eq({:day=>5, :month=>6, :year=>1952})
|
51
82
|
result.first[:profile_picture].should eq('https://apis.live.net/v5.0/123456/picture')
|
52
83
|
result.first[:relation].should be_nil
|
84
|
+
result.first[:email_hashes].should eq(["1234567890"])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should correctly parse and set logged in user information" do
|
88
|
+
hotmail.should_receive(:https_get).and_return(self_response)
|
89
|
+
hotmail.should_receive(:https_get).and_return(contacts_as_json)
|
90
|
+
|
91
|
+
hotmail.fetch_contacts_using_access_token token, token_type
|
92
|
+
|
93
|
+
user = hotmail.instance_variable_get(:@env)["omnicontacts.user"]
|
94
|
+
user.should_not be_nil
|
95
|
+
user[:id].should eq('4502de12390223d0')
|
96
|
+
user[:first_name].should eq('Chris')
|
97
|
+
user[:last_name].should eq('Johnson')
|
98
|
+
user[:name].should eq('Chris Johnson')
|
99
|
+
user[:gender].should be_nil
|
100
|
+
user[:birthday].should eq({:day=>21, :month=>06, :year=>1982})
|
101
|
+
user[:email].should eq('chrisjohn@gmail.com')
|
102
|
+
user[:profile_picture].should eq('https://apis.live.net/v5.0/4502de12390223d0/picture')
|
53
103
|
end
|
54
104
|
end
|
55
105
|
|
@@ -4,6 +4,19 @@ require "omnicontacts/importer/yahoo"
|
|
4
4
|
describe OmniContacts::Importer::Yahoo do
|
5
5
|
|
6
6
|
describe "fetch_contacts_from_token_and_verifier" do
|
7
|
+
let(:self_response) {
|
8
|
+
'{"profile":{
|
9
|
+
"guid":"PCLASP523T3E2R5TFMHDW9KWQQ",
|
10
|
+
"birthdate": "06/21",
|
11
|
+
"emails":[{"handle":"chrisjohnson@gmail.com", "id":10, "primary":true, "type":"HOME"}, {"handle":"xyz@xyz.com", "id":11, "type":"HOME"}],
|
12
|
+
"familyName": "Johnson",
|
13
|
+
"gender":"M",
|
14
|
+
"givenName":"Chris",
|
15
|
+
"image":{"imageUrl":"https://avatars.zenfs.com/users/23T3E2R5TFMHDW-AFE-I7lUpIsGQ==.large.png"}
|
16
|
+
}
|
17
|
+
}'
|
18
|
+
}
|
19
|
+
|
7
20
|
let(:contacts_as_json) {
|
8
21
|
'{
|
9
22
|
"contacts": {
|
@@ -16,7 +29,8 @@ describe OmniContacts::Importer::Yahoo do
|
|
16
29
|
{"id":819, "type":"email", "value":"johnny@yahoo.com"},
|
17
30
|
{"id":806,"type":"name","value":{"givenName":"John","middleName":"","familyName":"Smith"},"editedBy":"OWNER","categories":[]},
|
18
31
|
{"id":33555343,"type":"guid","value":"7ET6MYV2UQ6VR6CBSNMCLFJIVI"},
|
19
|
-
{"id":946,"type":"birthday","value":{"day":"22","month":"2","year":"1952"},"editedBy":"OWNER","categories":[]}
|
32
|
+
{"id":946,"type":"birthday","value":{"day":"22","month":"2","year":"1952"},"editedBy":"OWNER","categories":[]},
|
33
|
+
{"id":21, "type":"address", "value":{"street":"1313 Trashview Court\nApt. 13", "city":"Nowheresville", "stateOrProvince":"OK", "postalCode":"66666", "country":"", "countryCode":""}, "editedBy":"OWNER", "flags":["HOME"], "categories":[]}
|
20
34
|
]
|
21
35
|
}
|
22
36
|
]
|
@@ -25,9 +39,25 @@ describe OmniContacts::Importer::Yahoo do
|
|
25
39
|
|
26
40
|
let(:yahoo) { OmniContacts::Importer::Yahoo.new({}, "consumer_key", "consumer_secret") }
|
27
41
|
|
42
|
+
before(:each) do
|
43
|
+
yahoo.instance_variable_set(:@env, {})
|
44
|
+
end
|
45
|
+
|
28
46
|
it "should request the contacts by specifying all required parameters" do
|
29
47
|
yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"])
|
30
|
-
|
48
|
+
|
49
|
+
yahoo.should_receive(:https_get) do |host, path, params|
|
50
|
+
params[:format].should eq("json")
|
51
|
+
params[:oauth_consumer_key].should eq("consumer_key")
|
52
|
+
params[:oauth_nonce].should_not be_nil
|
53
|
+
params[:oauth_signature_method].should eq("HMAC-SHA1")
|
54
|
+
params[:oauth_timestamp].should_not be_nil
|
55
|
+
params[:oauth_token].should eq("access_token")
|
56
|
+
params[:oauth_version].should eq("1.0")
|
57
|
+
self_response
|
58
|
+
end
|
59
|
+
|
60
|
+
yahoo.should_receive(:https_get) do |host, path, params|
|
31
61
|
params[:format].should eq("json")
|
32
62
|
params[:oauth_consumer_key].should eq("consumer_key")
|
33
63
|
params[:oauth_nonce].should_not be_nil
|
@@ -35,16 +65,17 @@ describe OmniContacts::Importer::Yahoo do
|
|
35
65
|
params[:oauth_timestamp].should_not be_nil
|
36
66
|
params[:oauth_token].should eq("access_token")
|
37
67
|
params[:oauth_version].should eq("1.0")
|
38
|
-
params[:view].should eq("compact")
|
39
68
|
contacts_as_json
|
40
69
|
end
|
41
70
|
yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier"
|
42
71
|
end
|
43
72
|
|
44
|
-
it "should correctly parse id, name,email,gender, birthday, image source and relation" do
|
73
|
+
it "should correctly parse id, name,email,gender, birthday, snailmail address, image source and relation for contact and logged in user" do
|
45
74
|
yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"])
|
46
|
-
yahoo.should_receive(:
|
75
|
+
yahoo.should_receive(:https_get).and_return(self_response)
|
76
|
+
yahoo.should_receive(:https_get).and_return(contacts_as_json)
|
47
77
|
result = yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier"
|
78
|
+
|
48
79
|
result.size.should be(1)
|
49
80
|
result.first[:id].should eq('10')
|
50
81
|
result.first[:first_name].should eq('John')
|
@@ -53,16 +84,41 @@ describe OmniContacts::Importer::Yahoo do
|
|
53
84
|
result.first[:email].should eq("johnny@yahoo.com")
|
54
85
|
result.first[:gender].should be_nil
|
55
86
|
result.first[:birthday].should eq({:day=>22, :month=>2, :year=>1952})
|
87
|
+
result.first[:address_1].should eq('1313 Trashview Court')
|
88
|
+
result.first[:address_2].should eq('Apt. 13')
|
89
|
+
result.first[:city].should eq('Nowheresville')
|
90
|
+
result.first[:region].should eq('OK')
|
91
|
+
result.first[:postcode].should eq('66666')
|
56
92
|
result.first[:relation].should be_nil
|
57
93
|
end
|
58
94
|
|
59
95
|
it "should return an empty list of contacts" do
|
60
96
|
empty_contacts_list = '{"contacts": {"start":0, "count":0}}'
|
61
97
|
yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"])
|
62
|
-
yahoo.should_receive(:
|
98
|
+
yahoo.should_receive(:https_get).and_return(self_response)
|
99
|
+
yahoo.should_receive(:https_get).and_return(empty_contacts_list)
|
63
100
|
result = yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier"
|
101
|
+
|
64
102
|
result.should be_empty
|
65
103
|
end
|
66
104
|
|
105
|
+
it "should correctly parse and set logged in user information" do
|
106
|
+
yahoo.should_receive(:fetch_access_token).and_return(["access_token", "access_token_secret", "guid"])
|
107
|
+
yahoo.should_receive(:https_get).and_return(self_response)
|
108
|
+
yahoo.should_receive(:https_get).and_return(contacts_as_json)
|
109
|
+
yahoo.fetch_contacts_from_token_and_verifier "auth_token", "auth_token_secret", "oauth_verifier"
|
110
|
+
|
111
|
+
user = yahoo.instance_variable_get(:@env)["omnicontacts.user"]
|
112
|
+
user.should_not be_nil
|
113
|
+
user[:id].should eq('PCLASP523T3E2R5TFMHDW9KWQQ')
|
114
|
+
user[:first_name].should eq('Chris')
|
115
|
+
user[:last_name].should eq('Johnson')
|
116
|
+
user[:name].should eq('Chris Johnson')
|
117
|
+
user[:gender].should eq('male')
|
118
|
+
user[:birthday].should eq({:day=>21, :month=>06, :year=>nil})
|
119
|
+
user[:email].should eq('chrisjohnson@gmail.com')
|
120
|
+
user[:profile_picture].should eq('https://avatars.zenfs.com/users/23T3E2R5TFMHDW-AFE-I7lUpIsGQ==.large.png')
|
121
|
+
end
|
122
|
+
|
67
123
|
end
|
68
124
|
end
|
@@ -11,7 +11,7 @@ describe OmniContacts::Middleware::BaseOAuth do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def redirect_path
|
14
|
-
"
|
14
|
+
"#{ MOUNT_PATH }testprovider/callback"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
OmniContacts.integration_test.enabled = true
|
@@ -26,17 +26,23 @@ describe OmniContacts::Middleware::BaseOAuth do
|
|
26
26
|
|
27
27
|
it "should return a preconfigured list of contacts" do
|
28
28
|
OmniContacts.integration_test.mock(:testprovider, :email => "user@example.com")
|
29
|
-
get "
|
30
|
-
get "
|
29
|
+
get "#{ MOUNT_PATH }testprovider"
|
30
|
+
get "#{ MOUNT_PATH }testprovider/callback"
|
31
31
|
last_request.env["omnicontacts.contacts"].first[:email].should eq("user@example.com")
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should redurect to failure url" do
|
35
35
|
OmniContacts.integration_test.mock(:testprovider, "some_error" )
|
36
|
-
get "
|
37
|
-
get "
|
36
|
+
get "#{ MOUNT_PATH }testprovider"
|
37
|
+
get "#{MOUNT_PATH }testprovider/callback"
|
38
38
|
last_response.should be_redirect
|
39
|
-
last_response.headers["location"].should eq("
|
39
|
+
last_response.headers["location"].should eq("#{ MOUNT_PATH }failure?error_message=internal_error&importer=testprovider")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should pass through state query params to the failure url" do
|
43
|
+
OmniContacts.integration_test.mock(:testprovider, "some_error" )
|
44
|
+
get "#{MOUNT_PATH }testprovider/callback?state=/parent/resource/id"
|
45
|
+
last_response.headers["location"].should eq("#{ MOUNT_PATH }failure?error_message=internal_error&importer=testprovider&state=/parent/resource/id")
|
40
46
|
end
|
41
47
|
|
42
48
|
after(:all) do
|
@@ -41,32 +41,38 @@ describe OmniContacts::Middleware::OAuth1 do
|
|
41
41
|
context "visiting the listening path" do
|
42
42
|
it "should save the authorization token and redirect to the authorization url" do
|
43
43
|
OAuth1Middleware.mock_auth_token_resp.should_receive(:body).and_return(["auth_token", "auth_token_secret"])
|
44
|
-
get "
|
44
|
+
get "#{ MOUNT_PATH }oauth1middleware"
|
45
45
|
last_response.should be_redirect
|
46
46
|
last_response.headers['location'].should eq("http://www.example.com")
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should pass through state query params visiting the listening path" do
|
50
|
+
OAuth1Middleware.mock_auth_token_resp.should_receive(:body).and_return(["auth_token", "auth_token_secret"])
|
51
|
+
get "#{ MOUNT_PATH }oauth1middleware?state=/parent/resource/id"
|
52
|
+
last_response.headers['location'].should eq("http://www.example.com?state=/parent/resource/id")
|
53
|
+
end
|
54
|
+
|
49
55
|
it "should redirect to failure url if fetching the request token does not succeed" do
|
50
56
|
OAuth1Middleware.mock_auth_token_resp.should_receive(:body).and_raise("Request failed")
|
51
57
|
get "contacts/oauth1middleware"
|
52
58
|
last_response.should be_redirect
|
53
|
-
last_response.headers["location"].should eq("
|
59
|
+
last_response.headers["location"].should eq("#{ MOUNT_PATH }failure?error_message=internal_error&importer=oauth1middleware")
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
57
63
|
context "visiting the callback url after authorization" do
|
58
64
|
it "should return the list of contacts" do
|
59
65
|
OAuth1Middleware.mock_session.should_receive(:[]).and_return("oauth_token_secret")
|
60
|
-
get "
|
66
|
+
get "#{ MOUNT_PATH }oauth1middleware/callback?oauth_token=token&oauth_verifier=verifier"
|
61
67
|
last_response.should be_ok
|
62
68
|
last_request.env["omnicontacts.contacts"].size.should be(1)
|
63
69
|
end
|
64
70
|
|
65
71
|
it "should redirect to failure url if oauth_token_secret is not found in the session" do
|
66
72
|
OAuth1Middleware.mock_session.should_receive(:[]).and_return(nil)
|
67
|
-
get "
|
73
|
+
get "#{ MOUNT_PATH }oauth1middleware/callback?oauth_token=token&oauth_verifier=verifier"
|
68
74
|
last_response.should be_redirect
|
69
|
-
last_response.headers["location"].should eq("
|
75
|
+
last_response.headers["location"].should eq("#{ MOUNT_PATH }failure?error_message=not_authorized&importer=oauth1middleware")
|
70
76
|
end
|
71
77
|
end
|
72
78
|
end
|
@@ -40,10 +40,15 @@ describe OmniContacts::Middleware::OAuth2 do
|
|
40
40
|
|
41
41
|
context "visiting the listening path" do
|
42
42
|
it "should redirect to authorization site when visiting the listening path" do
|
43
|
-
get "
|
43
|
+
get "#{ MOUNT_PATH }oauth2middleware"
|
44
44
|
last_response.should be_redirect
|
45
45
|
last_response.headers['location'].should eq("http://www.example.com")
|
46
46
|
end
|
47
|
+
|
48
|
+
it "should pass through state query params visiting the listening path" do
|
49
|
+
get "#{ MOUNT_PATH }oauth2middleware?state=/parent/resource/id"
|
50
|
+
last_response.headers['location'].should eq("http://www.example.com?state=/parent/resource/id")
|
51
|
+
end
|
47
52
|
end
|
48
53
|
|
49
54
|
context "visiting the callback url after authorization" do
|
@@ -56,7 +61,7 @@ describe OmniContacts::Middleware::OAuth2 do
|
|
56
61
|
it "should redirect to failure page because user did not allow access to contacts list" do
|
57
62
|
get '/redirect_path?error=not_authorized'
|
58
63
|
last_response.should be_redirect
|
59
|
-
last_response.headers["location"].should eq("
|
64
|
+
last_response.headers["location"].should eq("#{ MOUNT_PATH }failure?error_message=not_authorized&importer=oauth2middleware")
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|