touchpass 0.0.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,319 @@
1
+ # Geodica Touchpass
2
+ # (C) Copyright 2009-2012 Geodica, a Carpadium Pty Ltd Venture
3
+ # All rights reserved
4
+
5
+ require 'spec_helper'
6
+
7
+ describe "Touchpass Client" do
8
+
9
+ # Assume localhost unless TPC_HOST is passed in an ENV variable
10
+ TPC_HOSTNAME = ENV['TPC_HOST'].nil? ? "https://localhost:3000" : ENV['TPC_HOST']
11
+ TPC_DEBUG = ENV['TPC_DEBUG'].nil? ? false : ENV['TPC_DEBUG']
12
+
13
+ # Instatiate a Touchpass client instance that can be used across all specs
14
+ let(:tpclient) { Touchpass::Client.new(TPC_HOSTNAME, TPC_DEBUG) }
15
+ let(:tpclient_default) { Touchpass::Client.new }
16
+
17
+ # Check that defaulting of hostname and output output works
18
+ context "Setup" do
19
+ it "should have a default value for hostname" do
20
+ tpclient.hostname.should eql(TPC_HOSTNAME)
21
+ tpclient.debug.should eql(TPC_DEBUG)
22
+ end
23
+ it "should have a populated value for hostname" do
24
+ tpclient_default.hostname.should eql(Touchpass::Client::DFT_HOSTNAME)
25
+ tpclient_default.debug.should eql(Touchpass::Client::DFT_DEBUG)
26
+ end
27
+ end
28
+
29
+ # Ensure that we can register a new party
30
+ context "Register Party" do
31
+ it "should allow a party to register with valid username, email and password" do
32
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
33
+ email = "#{username}@geodica.com"
34
+ password = "#{username}"
35
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
36
+ new_party['id' ].should_not be nil
37
+ new_party['username'].should == username
38
+ new_party['email' ].should == email
39
+ new_party['state' ].should == 'created'
40
+ new_party['api_key' ].should_not be nil
41
+ end
42
+ it "should not allow a party to register with an empty username" do
43
+ username = ""
44
+ email = "#{username}@geodica.com"
45
+ password = "password"
46
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
47
+ new_party['id' ].should be nil
48
+ new_party['username'].should == ["can't be blank", "is too short (minimum is 4 characters)"]
49
+ new_party['email' ].should == ['is invalid']
50
+ new_party['state' ].should be nil
51
+ new_party['api_key' ].should be nil
52
+ end
53
+ it "should not allow a party to register with an username > 15" do
54
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)}"
55
+ username.length.should be >= 15
56
+ email = "#{username}@geodica.com"
57
+ password = "password"
58
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
59
+ new_party['id' ].should be nil
60
+ new_party['username'].should == ["is too long (maximum is 15 characters)"]
61
+ new_party['email' ].should be nil
62
+ new_party['state' ].should be nil
63
+ new_party['api_key' ].should be nil
64
+ end
65
+ it "should not allow a party to register with an empty email address" do
66
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
67
+ email = ""
68
+ password = "#{username}"
69
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
70
+ new_party['id' ].should be nil
71
+ new_party['username'].should be nil
72
+ new_party['email' ].should == ['can\'t be blank']
73
+ new_party['state' ].should be nil
74
+ new_party['api_key' ].should be nil
75
+ end
76
+ it "should not allow a party to register with an empty password" do
77
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
78
+ email = "#{username}@geodica.com"
79
+ password = ""
80
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
81
+ new_party['id' ].should be nil
82
+ new_party['username'].should be nil
83
+ new_party['email' ].should be nil
84
+ new_party['state' ].should be nil
85
+ new_party['api_key' ].should be nil
86
+ end
87
+ end
88
+
89
+ # Check that a new rego provides an API key and that we can use the API key to access info
90
+ context "Validate api_key for newly registered user" do
91
+ it "should provide a valid API key that can be used to access the party record" do
92
+ # create a new party and get that party's api_key
93
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
94
+ email = "#{username}@geodica.com"
95
+ password = "#{username}"
96
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
97
+ new_party['id' ].should_not be nil
98
+ new_party['username'].should == username
99
+ new_party['email' ].should == email
100
+ new_party['state' ].should == 'created'
101
+ new_party['api_key' ].should_not be nil
102
+ # Use the api key to access info for that party
103
+ authenticated_party = tpclient.authenticate_party(:login => username, :password => password)
104
+ authenticated_party['api_key'].should_not be nil
105
+ authenticated_party['id' ].should_not be nil
106
+
107
+ shown_party1 = tpclient.get_party(:id => new_party['id']) # by api_key and id
108
+ shown_party1['id'].should == new_party['id']
109
+ shown_party1['username'].should == new_party['username']
110
+ shown_party1['email'].should == new_party['email']
111
+ shown_party1['state'].should == new_party['state']
112
+ shown_party2 = tpclient.get_party(:username => new_party['username']) # by api_key and username
113
+ shown_party2['id'].should == new_party['id']
114
+ shown_party2['username'].should == new_party['username']
115
+ shown_party2['email'].should == new_party['email']
116
+ shown_party2['state'].should == new_party['state']
117
+ end
118
+ end
119
+
120
+ # Check that party details can be updated
121
+ context "Make changes to a registered party" do
122
+ it "should allow changes to be made to a party" do
123
+ # create a new party and get that party's api_key
124
+ username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
125
+ email = "#{username}@geodica.com"
126
+ password = "#{username}"
127
+ new_party = tpclient.register_party(:email => email, :username => username, :password => password)
128
+ new_party['id' ].should_not be nil
129
+ new_party['api_key' ].should_not be nil
130
+ # Set the party's first_name and last_name
131
+ updated_party = tpclient.update_party(:username => new_party['username'], :first_name => username, :last_name => 'Hemplworth')
132
+ updated_party['first_name'].should == username
133
+ updated_party['last_name'].should == 'Hemplworth'
134
+ # Set the party's email address
135
+ updated_party = tpclient.update_party(:username => new_party['username'], :email => "#{username}@hemplworth.com")
136
+ updated_party['email'].should == "#{username}@hemplworth.com"
137
+ end
138
+ end
139
+
140
+ # Validate addition of new devices
141
+ context "Add, get and update a device" do
142
+ before(:each) do
143
+ @username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
144
+ @email = "#{@username}@geodica.com"
145
+ @password = "#{@username}"
146
+ @new_party = tpclient.register_party(:email => @email, :username => @username, :password => @password)
147
+ end
148
+
149
+ it "should create a new party first" do
150
+ @new_party['id' ].should_not be nil
151
+ @new_party['api_key' ].should_not be nil
152
+ end
153
+
154
+ it "should allow for the addition and retrieval of a new device" do
155
+ # create a new device for this party
156
+ udid = Touchpass::Crypt.encrypt(Touchpass::Crypt.salt) # a random string
157
+ messaging_value = Touchpass::Crypt.encrypt(Touchpass::Crypt.salt) # another random string
158
+ new_device = tpclient.register_device(:username => @new_party['username'],
159
+ :udid => udid,
160
+ :name => "#{@username}'s Device",
161
+ :messaging_type => 'apn-development',
162
+ :messaging_value => messaging_value )
163
+
164
+ new_device['id' ].should_not be nil
165
+ new_device['udid' ].should == udid
166
+ new_device['name' ].should == "#{@username}'s Device"
167
+ new_device['pub_key'].should_not be nil
168
+
169
+ # retrieve the newly created device
170
+ retrieved_devices = tpclient.get_devices(:username => @username)
171
+ retrieved_devices['devices'].should_not be nil
172
+ retrieved_devices['devices'].size.should_not be 0
173
+ retrieved_devices['devices'][0].should_not be nil
174
+ retrieved_devices['devices'][0]['id' ].should_not be nil
175
+ retrieved_devices['devices'][0]['udid' ].should_not be nil
176
+ retrieved_devices['devices'][0]['name' ].should_not be nil
177
+ retrieved_devices['devices'][0]['pub_key'].should_not be nil
178
+
179
+ # retrieve the new device to be retrieved by id
180
+ retrieved_device = tpclient.get_device(:username => @username, :id => new_device['id'])
181
+ retrieved_device.should_not be nil
182
+ retrieved_device['id' ].should == new_device['id' ]
183
+ retrieved_device['udid' ].should == new_device['udid' ]
184
+ retrieved_device['name' ].should == new_device['name' ]
185
+ retrieved_device['pub_key'].should == new_device['pub_key']
186
+ end
187
+
188
+ it "should allow for removal of a device by id" do
189
+ udid = Touchpass::Crypt.encrypt(Touchpass::Crypt.salt) # a random string
190
+ messaging_value = Touchpass::Crypt.encrypt(Touchpass::Crypt.salt) # another random string
191
+
192
+ new_device = tpclient.register_device(:username => @new_party['username'],
193
+ :udid => udid,
194
+ :name => "#{@username}'s Device",
195
+ :messaging_type => 'apn-development',
196
+ :messaging_value => messaging_value )
197
+
198
+ remove_device = tpclient.remove_device(:username => @new_party['username'],
199
+ :id => new_device['id'] )
200
+
201
+ retrieved_devices = tpclient.get_devices(:username => @username)
202
+
203
+ retrieved_devices['devices'].should_not be nil
204
+ retrieved_devices['devices'].size.should be 0
205
+
206
+ retrieved_device = tpclient.get_device(:username => @username, :id => new_device['id'])
207
+ retrieved_device['errors'].should_not be nil
208
+ end
209
+
210
+ end
211
+
212
+ # Work with verifications
213
+ context "Work with verifications" do
214
+ before(:each) do
215
+ @vp_client = Touchpass::Client.new(TPC_HOSTNAME, TPC_DEBUG)
216
+ @rp_client = Touchpass::Client.new(TPC_HOSTNAME, TPC_DEBUG)
217
+
218
+ # create a new verifying party
219
+ @vp_username = "tp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
220
+ @vp_email = "#{@vp_username}@geodica.com"
221
+ @vp_password = "#{@vp_username}"
222
+ @new_vp = @vp_client.register_party(:email => @vp_email, :username => @vp_username, :password => @vp_password)
223
+
224
+ # create a new relying party
225
+ @rp_username = "rp#{Touchpass::Crypt.encrypt(Touchpass::Crypt.salt)[0..12]}"
226
+ @rp_email = "#{@rp_username}@geodica.com"
227
+ @rp_password = "#{@rp_username}"
228
+ @new_rp = @rp_client.register_party(:email => @rp_email, :username => @rp_username, :password => @rp_password)
229
+
230
+ # add a device to the VP
231
+ @new_device = @vp_client.register_device(:username => @new_vp['username'],
232
+ :udid => Touchpass::Crypt.encrypt(Touchpass::Crypt.salt),
233
+ :name => "#{@username}'s Device",
234
+ :messaging_type => 'apn-development',
235
+ :messaging_value => Touchpass::Crypt.encrypt(Touchpass::Crypt.salt) )
236
+ end
237
+
238
+ it "should create the new rp and vp to work with" do
239
+ @new_vp.should_not be nil
240
+ @new_vp['id' ].should_not be nil
241
+ @new_vp['username'].should == @vp_username
242
+ @new_vp['email' ].should == @vp_email
243
+ @new_rp.should_not be nil
244
+ @new_rp['id' ].should_not be nil
245
+ @new_rp['username'].should == @rp_username
246
+ @new_rp['email' ].should == @rp_email
247
+ @new_device.should_not be nil
248
+ @new_device['id' ].should_not be nil
249
+ end
250
+
251
+ it "should allow for a relying party to create a simple (non-location) verification" do
252
+ # create the verification as the rp
253
+ verification = @rp_client.create_verification(:to_party => @new_vp['username'])
254
+
255
+ verification.should_not be nil
256
+ verification['crypted_tokens' ].should_not be nil
257
+ verification['id' ].should_not be nil
258
+ verification['reference' ].should_not be nil
259
+ verification['requested_at' ].should_not be nil
260
+ verification['responded_at' ].should_not be nil
261
+ verification['from_party']['id' ].should == @new_rp['id' ]
262
+ verification['from_party']['username' ].should == @new_rp['username']
263
+ verification['to_party' ]['id' ].should == @new_vp['id' ]
264
+ verification['to_party' ]['username' ].should == @new_vp['username']
265
+ verification['location_verification' ].should be nil
266
+ verification['resolution' ].should == ""
267
+ verification['location_verified' ].should be nil
268
+ verification['crypted_tokens' ].size().should be 1
269
+ verification['crypted_tokens'][0]['device_id'].should be == @new_device['id']
270
+ verification['crypted_tokens'][0]['value' ].should_not be nil
271
+ verification['crypted_salts' ].size().should be 0
272
+ verification['crypted_messages' ].size().should be 0
273
+ verification['state' ].should == "created"
274
+
275
+ # Get the list of verifications for the vp and make sure that our new one is in it
276
+ verifications_response = @vp_client.get_verifications(:username => @vp_username)
277
+ verifications_response.should_not be nil
278
+ verifications_response.size.should be > 0
279
+ verifications_response['total_entries'].should == 1
280
+ verifications_response['total_pages' ].should == 1
281
+ verifications_response['current_page' ].should == 1
282
+ verifications_response['next_page' ].should be_nil
283
+ verifications_response['previous_page'].should be_nil
284
+ verifications_response['verifications'].size.should == 1
285
+
286
+ # This can be an array of verifications in general but will only be one in this case
287
+ got_verification = verifications_response['verifications'][0]
288
+ got_verification.should_not be nil
289
+
290
+ # Run through the returned hash and make sure that it is the same as the original verification
291
+ got_verification.each_key do |key|
292
+ got_verification[key].should == verification[key]
293
+ end
294
+
295
+ # Also check that we can get the specific verification directly
296
+ got_specific_verification = @vp_client.get_verification(:id => verification['id'])
297
+ got_specific_verification.should_not be nil
298
+
299
+ got_specific_verification.each_key do |key|
300
+ got_specific_verification[key].should == verification[key]
301
+ end
302
+
303
+ # Validate that we can update it so that it is completed
304
+ updated_verification = @vp_client.update_verification(:id => verification['id'], :device_id => @new_device['id'])
305
+
306
+ updated_verification['state' ].should == 'verified'
307
+ updated_verification['responded_at'].should_not be nil
308
+
309
+ # We should *not* be able to canel or reject this verification since it's already been validated
310
+ cancelled_verification = @vp_client.cancel_verification(:id => verification['id'])
311
+
312
+ cancelled_verification['base'][0].should == "Verification has already been responded"
313
+ rejected_verification = @vp_client.reject_verification(:id => verification['id'])
314
+
315
+ rejected_verification['base'][0].should == "Verification has already been responded"
316
+ end
317
+ end
318
+
319
+ end
data/touchpass.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "touchpass/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "touchpass"
7
+ s.version = Touchpass::VERSION
8
+ s.authors = ["Geodica"]
9
+ s.email = ["info@geodica.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Touchpass}
12
+ s.description = %q{Geodica Touchpass}
13
+
14
+ s.rubyforge_project = "touchpass"
15
+
16
+ s.files = `git ls-files | grep -v pkg`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib", "app"]
20
+
21
+ # Gem dependencies
22
+ s.add_dependency("httparty", "~> 0.8.0")
23
+ s.add_dependency("json", "~> 1.6.5")
24
+ s.add_dependency("thor", "~> 0.14.6")
25
+ s.add_dependency("geocoder", "~> 1.1.0")
26
+ s.add_dependency("xml-simple", "~> 1.1.1")
27
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: touchpass
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Geodica
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-03 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70262118260300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70262118260300
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70262118259800 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.5
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70262118259800
36
+ - !ruby/object:Gem::Dependency
37
+ name: thor
38
+ requirement: &70262118259340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.14.6
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70262118259340
47
+ - !ruby/object:Gem::Dependency
48
+ name: geocoder
49
+ requirement: &70262118258880 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.1.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70262118258880
58
+ - !ruby/object:Gem::Dependency
59
+ name: xml-simple
60
+ requirement: &70262118258420 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.1.1
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70262118258420
69
+ description: Geodica Touchpass
70
+ email:
71
+ - info@geodica.com
72
+ executables:
73
+ - tpcli.rb
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - Guardfile
82
+ - Rakefile
83
+ - app/controllers/touchpass/verifications_controller.rb
84
+ - bin/tpcli.rb
85
+ - config/routes.rb
86
+ - lib/engine.rb
87
+ - lib/generators/templates/config/initializers/devise.rb
88
+ - lib/generators/templates/config/initializers/touchpass.rb
89
+ - lib/generators/templates/config/locales/devise.en.yml
90
+ - lib/generators/touchpass/install_generator.rb
91
+ - lib/touchpass.rb
92
+ - lib/touchpass/client.rb
93
+ - lib/touchpass/crypt.rb
94
+ - lib/touchpass/device.rb
95
+ - lib/touchpass/key_file_creator.rb
96
+ - lib/touchpass/prp.rb
97
+ - lib/touchpass/verification.rb
98
+ - lib/touchpass/version.rb
99
+ - spec/bounding_box_spec.rb
100
+ - spec/geocode_spec.rb
101
+ - spec/helpers/client_spec_helper.rb
102
+ - spec/helpers/gtp_spec_helper.rb
103
+ - spec/key_file_creator_spec.rb
104
+ - spec/proximity_spec.rb
105
+ - spec/prp_spec.rb
106
+ - spec/resolution_spec.rb
107
+ - spec/spec_helper.rb
108
+ - spec/touchpass_client_spec.rb
109
+ - touchpass.gemspec
110
+ homepage: ''
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ - app
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project: touchpass
131
+ rubygems_version: 1.8.16
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: Touchpass
135
+ test_files:
136
+ - spec/bounding_box_spec.rb
137
+ - spec/geocode_spec.rb
138
+ - spec/helpers/client_spec_helper.rb
139
+ - spec/helpers/gtp_spec_helper.rb
140
+ - spec/key_file_creator_spec.rb
141
+ - spec/proximity_spec.rb
142
+ - spec/prp_spec.rb
143
+ - spec/resolution_spec.rb
144
+ - spec/spec_helper.rb
145
+ - spec/touchpass_client_spec.rb
146
+ has_rdoc: