kent-rpx_now 0.6.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe RPXNow::ContactsCollection do
4
+ before do
5
+ data = JSON.parse(File.read('spec/fixtures/get_contacts_response.json'))['response']
6
+ @collection = RPXNow::ContactsCollection.new(data)
7
+ end
8
+
9
+ it "behaves like an array" do
10
+ @collection.size.should == 5
11
+ @collection[0] = "1"
12
+ @collection[0].should == "1"
13
+ end
14
+
15
+ it "parses entry to items" do
16
+ @collection[0]['displayName'].should == "Bob Johnson"
17
+ end
18
+
19
+ it "parses emails to list" do
20
+ @collection[0]['emails'].should == ["bob@example.com"]
21
+ end
22
+
23
+ it "parses emails to list with multiple emails" do
24
+ @collection[2]['emails'].should == ["fred.williams@example.com","fred@example.com"]
25
+ end
26
+
27
+ it "holds additional_info" do
28
+ @collection.additional_info['startIndex'].should == 1
29
+ @collection.additional_info['itemsPerPage'].should == 5
30
+ @collection.additional_info['totalResults'].should == 5
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec/spec_helper'
2
+ require 'rpx_now/user_integration'
3
+
4
+ class User
5
+ include RPXNow::UserIntegration
6
+
7
+ def id
8
+ 5
9
+ end
10
+ end
11
+
12
+ describe RPXNow::UserProxy do
13
+ before { @user = User.new }
14
+
15
+ it "has a proxy" do
16
+ @user.rpx.class.should == RPXNow::UserProxy
17
+ end
18
+
19
+ it "has identifiers" do
20
+ RPXNow.should_receive(:mappings).with(@user.id).and_return(['identifiers'])
21
+ @user.rpx.identifiers.should == ['identifiers']
22
+ end
23
+
24
+ it "can map" do
25
+ RPXNow.should_receive(:map).with('identifier', @user.id)
26
+ @user.rpx.map('identifier')
27
+ end
28
+
29
+ it "can unmap" do
30
+ RPXNow.should_receive(:unmap).with('identifier', @user.id)
31
+ @user.rpx.unmap('identifier')
32
+ end
33
+ end
@@ -0,0 +1,333 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe RPXNow do
4
+ def fake_response(replace={})
5
+ body = {'stat' => 'ok'}.merge(replace)
6
+ mock({:code => "200", :body => body.to_json})
7
+ end
8
+
9
+ describe :api_key= do
10
+ before do
11
+ RPXNow.api_key='XX'
12
+ end
13
+
14
+ it "is stored" do
15
+ RPXNow.api_key.should == 'XX'
16
+ end
17
+
18
+ it "stores the api key, so i do not have to supply everytime" do
19
+ RPXNow::Api.should_receive(:request).
20
+ with(anything, hash_including(:apiKey => 'XX')).
21
+ and_return fake_response
22
+ RPXNow.mappings(1)
23
+ end
24
+
25
+ it "is not overwritten when overwriting for a single request" do
26
+ RPXNow::Api.should_receive(:request).
27
+ with(anything, hash_including(:apiKey => 'YY')).
28
+ and_return fake_response
29
+ RPXNow.mappings(1, :apiKey => 'YY')
30
+ RPXNow.api_key.should == 'XX'
31
+ end
32
+ end
33
+
34
+ describe :api_version= do
35
+ it "is 2 by default" do
36
+ RPXNow.api_version.should == 2
37
+ end
38
+
39
+ it "is stored" do
40
+ RPXNow.api_version='XX'
41
+ RPXNow.api_version.should == 'XX'
42
+ end
43
+
44
+ it "used for every request" do
45
+ RPXNow.api_version='XX'
46
+ RPXNow::Api.should_receive(:request).
47
+ with('/api/vXX/mappings', anything).
48
+ and_return fake_response
49
+ RPXNow.mappings(1)
50
+ end
51
+
52
+ it "is not overwritten when overwriting for a single request" do
53
+ RPXNow.api_version='XX'
54
+ RPXNow::Api.should_receive(:request).
55
+ with('/api/vYY/mappings', anything).
56
+ and_return fake_response
57
+ RPXNow.mappings(1, :api_version => 'YY')
58
+ RPXNow.api_version.should == 'XX'
59
+ end
60
+
61
+ it "is not passed in data for request" do
62
+ RPXNow.api_version='XX'
63
+ RPXNow::Api.should_receive(:request).
64
+ with(anything, hash_not_including(:api_version => 'YY')).
65
+ and_return fake_response
66
+ RPXNow.mappings(1, :api_version => 'YY')
67
+ end
68
+ end
69
+
70
+ describe :embed_code do
71
+ it "contains the subdomain" do
72
+ RPXNow.embed_code('xxx','my_url').should =~ /xxx/
73
+ end
74
+
75
+ it "contains the url" do
76
+ RPXNow.embed_code('xxx','my_url').should =~ /token_url=my_url/
77
+ end
78
+
79
+ it "defaults to no language" do
80
+ RPXNow.embed_code('xxx', 'my_url').should_not =~ /language_preference/
81
+ end
82
+
83
+ it "has a changeable language" do
84
+ RPXNow.embed_code('xxx', 'my_url', :language => 'es').should =~ /language_preference=es/
85
+ end
86
+
87
+ it "defaults to 400px width" do
88
+ RPXNow.embed_code('xxx', 'my_url').should =~ /width:400px;/
89
+ end
90
+
91
+ it "has a changeable width" do
92
+ RPXNow.embed_code('xxx', 'my_url', :width => '300').should =~ /width:300px;/
93
+ end
94
+
95
+ it "defaults to 240px height" do
96
+ RPXNow.embed_code('xxx', 'my_url').should =~ /height:240px;/
97
+ end
98
+
99
+ it "has a changeable height" do
100
+ RPXNow.embed_code('xxx', 'my_url', :height => '500').should =~ /height:500px;/
101
+ end
102
+ end
103
+
104
+ describe :popup_code do
105
+ it "defaults to obtrusive output" do
106
+ RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/').should =~ /script src=/
107
+ end
108
+
109
+ it "does not change supplied options" do
110
+ options = {:xxx => 1}
111
+ RPXNow.popup_code('a','b','c', options)
112
+ options.should == {:xxx => 1}
113
+ end
114
+
115
+ describe 'unobstrusive' do
116
+ it "can build an unobtrusive widget" do
117
+ expected = %Q(<a class="rpxnow" href="https://subdomain.rpxnow.com/openid/v2/signin?token_url=http://fake.domain.com/">sign on</a>)
118
+ actual = RPXNow.popup_code('sign on', 'subdomain', 'http://fake.domain.com/', :unobtrusive => true)
119
+ actual.should == expected
120
+ end
121
+
122
+ it "can change api version" do
123
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :api_version => 'XX').should include("openid/vXX/signin?")
124
+ end
125
+
126
+ it "can change language" do
127
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :language => 'XX').should include("language_preference=XX")
128
+ end
129
+
130
+ it "can add flags" do
131
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :flags => 'test').should include("flags=test")
132
+ end
133
+
134
+ it "can add default_provider" do
135
+ RPXNow.popup_code('x', 'y', 'z', :unobtrusive => true, :default_provider => 'test').should include("default_provider=test")
136
+ end
137
+ end
138
+
139
+ it "allows to specify the version of the widget" do
140
+ RPXNow.popup_code('x','y','z', :api_version => 300).should =~ %r(/openid/v300/signin)
141
+ end
142
+
143
+ it "defaults to widget version 2" do
144
+ RPXNow.popup_code('x','y','z').should =~ %r(/openid/v2/signin)
145
+ end
146
+
147
+ describe 'language' do
148
+ it "defaults to no language" do
149
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.language_preference/
150
+ end
151
+
152
+ it "has a changeable language" do
153
+ RPXNow.popup_code('x','y','z', :language=>'de').should =~ /RPXNOW.language_preference = 'de'/
154
+ end
155
+ end
156
+
157
+ describe 'flags' do
158
+ it "defaults to no language" do
159
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.flags/
160
+ end
161
+
162
+ it "can have flags" do
163
+ RPXNow.popup_code('x','y','z', :flags=>'test').should =~ /RPXNOW.flags = 'test'/
164
+ end
165
+ end
166
+
167
+ describe 'default_provider' do
168
+ it "defaults to no provider" do
169
+ RPXNow.popup_code('x','y','z').should_not =~ /RPXNOW.default_provider/
170
+ end
171
+
172
+ it "can have default_provider" do
173
+ RPXNow.popup_code('x','y','z', :default_provider=>'test').should =~ /RPXNOW.default_provider = 'test'/
174
+ end
175
+ end
176
+ end
177
+
178
+ describe :user_data do
179
+ before do
180
+ @response_body = {
181
+ "profile" => {
182
+ "verifiedEmail" => "grosser.michael@googlemail.com",
183
+ "displayName" => "Michael Grosser",
184
+ "preferredUsername" => "grosser.michael",
185
+ "identifier" => "https:\/\/www.google.com\/accounts\/o8\/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM",
186
+ "email" => "grosser.michael@gmail.com"
187
+ }
188
+ }
189
+ @response = fake_response(@response_body)
190
+ @fake_user_data = {'profile'=>{}}
191
+ end
192
+
193
+ it "raises ApiError when used with an invalid token" do
194
+ lambda{
195
+ RPXNow.user_data('xxxx')
196
+ }.should raise_error(RPXNow::ApiError)
197
+ end
198
+
199
+ it "is empty when used with an unknown token" do
200
+ RPXNow.user_data('60d8c6374f4e9d290a7b55f39da7cc6435aef3d3').should == nil
201
+ end
202
+
203
+ it "parses JSON response to user data" do
204
+ expected = {
205
+ :name => 'Michael Grosser',
206
+ :email => 'grosser.michael@googlemail.com',
207
+ :identifier => 'https://www.google.com/accounts/o8/id?id=AItOawmaOlyYezg_WfbgP_qjaUyHjmqZD9qNIVM',
208
+ :username => 'grosser.michael',
209
+ }
210
+ RPXNow::Api.should_receive(:request).and_return @response
211
+ RPXNow.user_data('').should == expected
212
+ end
213
+
214
+ it "adds a :id when primaryKey was returned" do
215
+ @response_body['profile']['primaryKey'] = "2"
216
+ response = fake_response(@response_body)
217
+ RPXNow::Api.should_receive(:request).and_return response
218
+ RPXNow.user_data('')[:id].should == '2'
219
+ end
220
+
221
+ it "handles primaryKeys that are not numeric" do
222
+ @response_body['profile']['primaryKey'] = "dbalatero"
223
+ response = fake_response(@response_body)
224
+ RPXNow::Api.should_receive(:request).and_return response
225
+ RPXNow.user_data('')[:id].should == 'dbalatero'
226
+ end
227
+
228
+ it "can fetch additional fields" do
229
+ @response_body['profile']['xxxy'] = "test"
230
+ response = fake_response(@response_body)
231
+ RPXNow::Api.should_receive(:request).and_return response
232
+ RPXNow.user_data('', :additional => [:xxxy])[:xxxy].should == 'test'
233
+ end
234
+
235
+ it "hands JSON response to supplied block" do
236
+ RPXNow::Api.should_receive(:request).and_return @response
237
+ response = nil
238
+ RPXNow.user_data(''){|data| response = data}
239
+ response.delete('stat') # dunno why it happens, but is not important...
240
+ response.should == @response_body
241
+ end
242
+
243
+ it "returns what the supplied block returned" do
244
+ RPXNow::Api.should_receive(:request).and_return @response
245
+ RPXNow.user_data(''){|data| "x"}.should == 'x'
246
+ end
247
+
248
+ it "can send additional parameters" do
249
+ RPXNow::Api.should_receive(:request).
250
+ with(anything, hash_including(:extended => 'true')).
251
+ and_return @response
252
+ RPXNow.user_data('',:extended=>'true')
253
+ end
254
+
255
+ # these 2 tests are kind of duplicates of the api_version/key tests,
256
+ # but i want to be extra-sure user_data works
257
+ it "works with api version as option" do
258
+ RPXNow::Api.should_receive(:request).
259
+ with('/api/v123/auth_info', anything).
260
+ and_return @response
261
+ RPXNow.user_data('id', :extended=>'abc', :api_version=>123)
262
+ RPXNow.api_version.should == API_VERSION
263
+ end
264
+
265
+ it "works with apiKey as option" do
266
+ RPXNow::Api.should_receive(:request).
267
+ with('/api/v2/auth_info', hash_including(:apiKey=>'THE KEY')).
268
+ and_return @response
269
+ RPXNow.user_data('id', :extended=>'abc', :apiKey=>'THE KEY')
270
+ RPXNow.api_key.should == API_KEY
271
+ end
272
+ end
273
+
274
+ describe :set_status do
275
+ it "sets the status" do
276
+ RPXNow::Api.should_receive(:request).
277
+ with("/api/v2/set_status", :identifier=>"identifier", :status=>"Chillen...", :apiKey=>API_KEY).
278
+ and_return fake_response
279
+ RPXNow.set_status('identifier', 'Chillen...')
280
+ end
281
+ end
282
+
283
+ describe :parse_user_data do
284
+ it "reads secondary names" do
285
+ RPXNow.send(:parse_user_data,{'profile'=>{'preferredUsername'=>'1'}}, {})[:name].should == '1'
286
+ end
287
+
288
+ it "parses email when no name is found" do
289
+ RPXNow.send(:parse_user_data,{'profile'=>{'email'=>'1@xxx.com'}}, {})[:name].should == '1'
290
+ end
291
+ end
292
+
293
+ describe :contacts do
294
+ it "finds all contacts" do
295
+ response = fake_response(JSON.parse(File.read('spec/fixtures/get_contacts_response.json')))
296
+ RPXNow::Api.should_receive(:request).
297
+ with('/api/v2/get_contacts',:identifier=>'xx', :apiKey=>API_KEY).
298
+ and_return response
299
+ RPXNow.contacts('xx').size.should == 5
300
+ end
301
+ end
302
+
303
+ describe :mappings do
304
+ it "shows all mappings" do
305
+ RPXNow::Api.should_receive(:request).
306
+ with("/api/v2/mappings", :apiKey=>API_KEY, :primaryKey=>1).
307
+ and_return fake_response("identifiers" => ["http://test.myopenid.com/"])
308
+ RPXNow.mappings(1).should == ["http://test.myopenid.com/"]
309
+ end
310
+ end
311
+
312
+ describe :map do
313
+ it "maps a identifier" do
314
+ RPXNow::Api.should_receive(:request).
315
+ with("/api/v2/map", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
316
+ and_return fake_response
317
+ RPXNow.map('http://test.myopenid.com',1)
318
+ end
319
+ end
320
+
321
+ describe :unmap do
322
+ it "unmaps a indentifier" do
323
+ RPXNow::Api.should_receive(:request).
324
+ with("/api/v2/unmap", :apiKey=>API_KEY, :primaryKey=>1, :identifier=>"http://test.myopenid.com").
325
+ and_return fake_response
326
+ RPXNow.unmap('http://test.myopenid.com', 1)
327
+ end
328
+ end
329
+
330
+ it "has a VERSION" do
331
+ RPXNow::VERSION.should =~ /^\d+\.\d+\.\d+$/
332
+ end
333
+ end
@@ -0,0 +1,18 @@
1
+ # ---- requirements
2
+ require 'rubygems'
3
+ require 'spec'
4
+
5
+ $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
6
+
7
+ # ---- setup environment/plugin
8
+ require File.expand_path("../init", File.dirname(__FILE__))
9
+ API_KEY = '4b339169026742245b754fa338b9b0aebbd0a733'
10
+ API_VERSION = RPXNow.api_version
11
+
12
+ # ---- rspec
13
+ Spec::Runner.configure do |config|
14
+ config.before :each do
15
+ RPXNow.api_key = API_KEY
16
+ RPXNow.api_version = API_VERSION
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kent-rpx_now
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.11
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ - Kent Fenwick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-12-22 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: json_pure
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ version:
26
+ description:
27
+ email: kent.fenwick@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README.markdown
34
+ files:
35
+ - .gitignore
36
+ - CHANGELOG
37
+ - MIGRATION
38
+ - README.markdown
39
+ - Rakefile
40
+ - VERSION
41
+ - certs/ssl_cert.pem
42
+ - init.rb
43
+ - lib/rpx_now.rb
44
+ - lib/rpx_now/api.rb
45
+ - lib/rpx_now/contacts_collection.rb
46
+ - lib/rpx_now/user_integration.rb
47
+ - lib/rpx_now/user_proxy.rb
48
+ - rpx_now.gemspec
49
+ - spec/fixtures/get_contacts_response.json
50
+ - spec/integration/mapping_spec.rb
51
+ - spec/rpx_now/api_spec.rb
52
+ - spec/rpx_now/contacts_collection_spec.rb
53
+ - spec/rpx_now/user_proxy_spec.rb
54
+ - spec/rpx_now_spec.rb
55
+ - spec/spec_helper.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/kent/rpx_now
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.5
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Helper to simplify RPX Now user login/creation based on Michael Grosser's rpx_now gem
84
+ test_files:
85
+ - spec/integration/mapping_spec.rb
86
+ - spec/rpx_now/api_spec.rb
87
+ - spec/rpx_now/contacts_collection_spec.rb
88
+ - spec/rpx_now/user_proxy_spec.rb
89
+ - spec/rpx_now_spec.rb
90
+ - spec/spec_helper.rb