soteria 1.0.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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +2 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +77 -0
  9. data/Rakefile +5 -0
  10. data/bin/bundler +17 -0
  11. data/bin/console +17 -0
  12. data/bin/htmldiff +17 -0
  13. data/bin/ldiff +17 -0
  14. data/bin/nokogiri +17 -0
  15. data/bin/rackup +17 -0
  16. data/bin/rake +17 -0
  17. data/bin/rspec +17 -0
  18. data/bin/setup +17 -0
  19. data/bin/socksify_ruby +17 -0
  20. data/lib/soteria.rb +10 -0
  21. data/lib/soteria/client.rb +326 -0
  22. data/lib/soteria/credential.rb +154 -0
  23. data/lib/soteria/credential_types.rb +13 -0
  24. data/lib/soteria/push.rb +141 -0
  25. data/lib/soteria/sms.rb +81 -0
  26. data/lib/soteria/user.rb +409 -0
  27. data/lib/soteria/utilities.rb +45 -0
  28. data/lib/soteria/version.rb +4 -0
  29. data/soteria.gemspec +26 -0
  30. data/spec/credential_spec.rb +121 -0
  31. data/spec/fixtures/credential/authenticate_credentials_response.xml +13 -0
  32. data/spec/fixtures/credential/credential_fail.xml +11 -0
  33. data/spec/fixtures/credential/credential_success.xml +12 -0
  34. data/spec/fixtures/credential/get_cred_info_response.xml +40 -0
  35. data/spec/fixtures/credential/get_server_time_response.xml +11 -0
  36. data/spec/fixtures/credential/register_sms_response.xml +12 -0
  37. data/spec/fixtures/push/authenticate_with_push_error.xml +9 -0
  38. data/spec/fixtures/push/authenticate_with_push_response.xml +14 -0
  39. data/spec/fixtures/sms/check_otp_success_response.xml +13 -0
  40. data/spec/fixtures/sms/send_sms_success_response.xml +10 -0
  41. data/spec/fixtures/user/add_credential_response.xml +9 -0
  42. data/spec/fixtures/user/clear_temp_password_response.xml +10 -0
  43. data/spec/fixtures/user/clear_user_pin_response.xml +10 -0
  44. data/spec/fixtures/user/create_user_response.xml +9 -0
  45. data/spec/fixtures/user/delete_user_response.xml +10 -0
  46. data/spec/fixtures/user/get_temp_pass_attr_response.xml +14 -0
  47. data/spec/fixtures/user/remove_credential_response.xml +10 -0
  48. data/spec/fixtures/user/set_temp_pass_attr_response.xml +10 -0
  49. data/spec/fixtures/user/set_temp_pass_response.xml +11 -0
  50. data/spec/fixtures/user/update_credential_response.xml +10 -0
  51. data/spec/fixtures/user/update_user_response.xml +10 -0
  52. data/spec/fixtures/wsdl/vipuserservices-1.7.xsd +1015 -0
  53. data/spec/fixtures/wsdl/vipuserservices-auth-1.7.wsdl +155 -0
  54. data/spec/fixtures/wsdl/vipuserservices-mgmt-1.7.wsdl +246 -0
  55. data/spec/fixtures/wsdl/vipuserservices-query-1.7.wsdl +114 -0
  56. data/spec/push_spec.rb +148 -0
  57. data/spec/sms_spec.rb +84 -0
  58. data/spec/soteria_spec.rb +8 -0
  59. data/spec/spec_helper.rb +2 -0
  60. data/spec/user_spec.rb +245 -0
  61. metadata +206 -0
data/spec/push_spec.rb ADDED
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+ require 'savon/mock/spec_helper'
3
+
4
+ describe Soteria::Push do
5
+
6
+ include Savon::SpecHelper
7
+
8
+ before :all do
9
+ savon.mock!
10
+
11
+ @push = Soteria::Push.new
12
+
13
+ auth_client_wsdl = File.read('spec/fixtures/wsdl/vipuserservices-auth-1.7.wsdl')
14
+ @auth_client = Savon.client(wsdl: auth_client_wsdl)
15
+
16
+ query_client_wsdl = File.read('spec/fixtures/wsdl/vipuserservices-query-1.7.wsdl')
17
+ @query_client = Savon.client(wsdl: query_client_wsdl)
18
+ end
19
+
20
+ after :all do
21
+ savon.unmock!
22
+ end
23
+
24
+ it 'sends the push with success' do
25
+ body = File.read('spec/fixtures/push/authenticate_with_push_response.xml')
26
+ savon.expects(:authenticate_user_with_push).with(message: :any).returns(body)
27
+ res = @push.send_push(@auth_client, '', nil)
28
+
29
+ expect(res[:id]).to eq 'send_push_request_20161021152920'
30
+ expect(res[:success]).to eq true
31
+ expect(res[:transaction_id]).to eq '8d70d18461cc9093'
32
+ expect(res[:message]).to eq 'Mobile push request sent'
33
+
34
+ end
35
+
36
+ it 'sends the push with failure' do
37
+ body = File.read('spec/fixtures/push/authenticate_with_push_error.xml')
38
+ savon.expects(:authenticate_user_with_push).with(message: :any).returns(body)
39
+ res = @push.send_push(@auth_client, '', nil)
40
+
41
+ expect(res[:id]).to eq 'send_push_request_20161021152920'
42
+ expect(res[:success]).to eq false
43
+ expect(res[:transaction_id]).to eq nil
44
+ expect(res[:message]).to eq 'User does not exist.'
45
+
46
+ end
47
+
48
+ it 'polls for a response' do
49
+
50
+ end
51
+
52
+ context 'with no additional options passed' do
53
+
54
+ it 'forms the request body with only required fields' do
55
+ result_hash = @push.get_push_request_body('test_user', nil)
56
+ result_hash[:'vip:requestId'] = nil
57
+
58
+ expected_hash = {
59
+ 'vip:requestId': nil,
60
+ 'vip:userId': 'test_user',
61
+ 'vip:pushAuthData': ''
62
+ }
63
+
64
+ expect(result_hash).to match expected_hash
65
+ end
66
+
67
+ end
68
+
69
+ context 'with title and message passed' do
70
+
71
+ it 'forms the request body with required fields and title and message' do
72
+ options = {title: 'push title', message: 'this is a test push'}
73
+ result_hash = @push.get_push_request_body('test_user', options)
74
+ result_hash[:'vip:requestId'] = nil
75
+
76
+ expected_hash = {
77
+ 'vip:requestId': nil,
78
+ 'vip:userId': 'test_user',
79
+ 'vip:pushAuthData': {
80
+ 'vip:displayParameters': [
81
+ {'vip:Key': 'display.message.title', 'vip:Value': options[:title]},
82
+ {'vip:Key': 'display.message.text', 'vip:Value': options[:message]}
83
+ ]
84
+ }
85
+ }
86
+
87
+ expect(result_hash).to match expected_hash
88
+ end
89
+
90
+ end
91
+
92
+ context 'with a timeout and no title or message' do
93
+
94
+ it 'forms the request body with required fields and timeout' do
95
+ options = {time_out: 120}
96
+
97
+ result_hash = @push.get_push_request_body('test_user', options)
98
+ result_hash[:'vip:requestId'] = nil
99
+
100
+ expected_hash = {
101
+ 'vip:requestId': nil,
102
+ 'vip:userId': 'test_user',
103
+ 'vip:pushAuthData': {
104
+ 'vip:displayParameters': [],
105
+ 'vip:requestParameters':
106
+ {
107
+ 'vip:Key': 'request.timeout',
108
+ 'vip:Value': options[:time_out]
109
+ }
110
+ }
111
+ }
112
+
113
+ expect(result_hash).to match expected_hash
114
+ end
115
+
116
+ end
117
+
118
+ context 'with a timeout and a title and a message' do
119
+
120
+ it 'forms the request body with required fields along with the title, message and timeout' do
121
+ options = {time_out: 120, title: 'push title', message: 'this is a test push'}
122
+
123
+ result_hash = @push.get_push_request_body('test_user', options)
124
+ result_hash[:'vip:requestId'] = nil
125
+
126
+ expected_hash = {
127
+ 'vip:requestId': nil,
128
+ 'vip:userId': 'test_user',
129
+ 'vip:pushAuthData': {
130
+ 'vip:displayParameters': [
131
+ {'vip:Key': 'display.message.title', 'vip:Value': options[:title]},
132
+ {'vip:Key': 'display.message.text', 'vip:Value': options[:message]}
133
+ ],
134
+ 'vip:requestParameters':
135
+ {
136
+ 'vip:Key': 'request.timeout',
137
+ 'vip:Value': options[:time_out]
138
+ }
139
+ }
140
+ }
141
+
142
+ expect(result_hash).to match expected_hash
143
+ end
144
+
145
+ end
146
+
147
+ end
148
+
data/spec/sms_spec.rb ADDED
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'savon/mock/spec_helper'
3
+
4
+ describe Soteria::SMS do
5
+
6
+ include Savon::SpecHelper
7
+
8
+ before :all do
9
+ savon.mock!
10
+
11
+ @sms = Soteria::SMS.new
12
+
13
+ auth_client_wsdl = File.read('spec/fixtures/wsdl/vipuserservices-auth-1.7.wsdl')
14
+ @auth_client = Savon.client(wsdl: auth_client_wsdl)
15
+
16
+ mgmt_client_wsdl = File.read('spec/fixtures/wsdl/vipuserservices-mgmt-1.7.wsdl')
17
+ @mgmt_client = Savon.client(wsdl: mgmt_client_wsdl)
18
+ end
19
+
20
+ after :all do
21
+ savon.unmock!
22
+ end
23
+
24
+ it 'creates the request body to send an sms' do
25
+ result_hash = @sms.create_send_sms_body('test1', 123456789)
26
+ result_hash[:'vip:requestId'] = nil
27
+
28
+ expected_hash = {
29
+ 'vip:requestId': nil,
30
+ 'vip:userId': 'test1',
31
+ 'vip:smsDeliveryInfo':
32
+ {
33
+ 'vip:phoneNumber': 123456789
34
+ }
35
+ }
36
+
37
+ expect(result_hash). to match expected_hash
38
+ end
39
+
40
+ it 'creates the request body to check an otp' do
41
+ result_hash = @sms.create_check_otp_body('test1', 'otp123')
42
+ result_hash[:'vip:requestId'] = nil
43
+
44
+ expected_hash = {
45
+ 'vip:requestId': nil,
46
+ 'vip:userId': 'test1',
47
+ 'vip:otpAuthData':
48
+ {
49
+ 'vip:otp': 'otp123'
50
+ }
51
+ }
52
+
53
+ expect(result_hash). to match expected_hash
54
+ end
55
+
56
+ it 'sends a sms otp' do
57
+ body = File.read('spec/fixtures/sms/send_sms_success_response.xml')
58
+ savon.expects(:send_otp).with(message: :any).returns(body)
59
+ result_hash = @sms.send_sms(@mgmt_client, '', '')
60
+
61
+ expected_hash = {
62
+ success: true,
63
+ id: 'test123',
64
+ message: 'Success'
65
+ }
66
+
67
+ expect(result_hash). to match expected_hash
68
+ end
69
+
70
+ it 'checks if a otp is valid' do
71
+ body = File.read('spec/fixtures/sms/check_otp_success_response.xml')
72
+ savon.expects(:check_otp).with(message: :any).returns(body)
73
+ result_hash = @sms.check_otp(@auth_client, '', '')
74
+
75
+ expected_hash = {
76
+ success: true,
77
+ id: 'test123',
78
+ message: 'Success'
79
+ }
80
+
81
+ expect(result_hash). to match expected_hash
82
+ end
83
+ end
84
+
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+ require 'savon/mock/spec_helper'
3
+
4
+ describe Soteria do
5
+ it "has a version number" do
6
+ expect(Soteria::VERSION).not_to be nil
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "soteria"
data/spec/user_spec.rb ADDED
@@ -0,0 +1,245 @@
1
+ require_relative '../lib/soteria/user'
2
+ require 'spec_helper'
3
+ require 'savon/mock/spec_helper'
4
+ require 'date'
5
+
6
+ describe Soteria::User do
7
+ # include the helper module
8
+ include Savon::SpecHelper
9
+
10
+ before :all do
11
+ savon.mock!
12
+
13
+ @user = Soteria::User.new
14
+ @mgmt_client = Savon.client(wsdl: File.read("spec/fixtures/wsdl/vipuserservices-mgmt-1.7.wsdl"))
15
+ @query_client = Savon.client(wsdl: File.read("spec/fixtures/wsdl/vipuserservices-query-1.7.wsdl"))
16
+ end
17
+
18
+ after :all do
19
+ savon.unmock!
20
+ end
21
+ context 'makes a hash with the right return values' do
22
+ it 'makes a hash when the call succeed' do
23
+ h = {status: '0000', status_message: 'Success', request_id: 'test1234'}
24
+ res = @user.get_return_hash(h)
25
+ expect(res[:success]).to eq true
26
+ expect(res[:message]).to eq 'Success'
27
+ expect(res[:id]).to eq 'test1234'
28
+ end
29
+
30
+ it 'makes a hash when the call has errors' do
31
+ h = {status: '6002', status_message: 'User already exists.', request_id: 'test1234'}
32
+ res = @user.get_return_hash(h)
33
+ expect(res[:success]).to eq false
34
+ expect(res[:message]).to eq 'User already exists.'
35
+ expect(res[:id]).to eq 'test1234'
36
+ end
37
+ end
38
+
39
+ it 'creates a user' do
40
+ body = File.read("spec/fixtures/user/create_user_response.xml")
41
+ savon.expects(:create_user).with(message: :any).returns(body)
42
+ res = @user.create(@mgmt_client, '', nil)
43
+
44
+ expect(res[:success]).to be true
45
+ expect(res[:message]).to eq 'Success'
46
+ expect(res[:id]).to eq 'test1234'
47
+ end
48
+
49
+ it 'deletes a user' do
50
+ body = File.read("spec/fixtures/user/delete_user_response.xml")
51
+ savon.expects(:delete_user).with(message: :any).returns(body)
52
+ res = @user.delete(@mgmt_client, '')
53
+
54
+ expect(res[:success]).to be true
55
+ expect(res[:message]).to eq 'Success'
56
+ expect(res[:id]).to eq 'test1234'
57
+ end
58
+
59
+ it 'adds a credential to a user' do
60
+
61
+ body = File.read("spec/fixtures/user/add_credential_response.xml")
62
+ savon.expects(:add_credential).with(message: :any).returns(body)
63
+ res = @user.add_credential(@mgmt_client, '', '', '', nil)
64
+
65
+ expect(res[:success]).to be true
66
+ expect(res[:message]).to eq 'Success'
67
+ expect(res[:id]).to eq '4ACCDv2rtj'
68
+
69
+ end
70
+
71
+ context 'gets the request body for adding a credential' do
72
+
73
+ it 'gets the body with no options' do
74
+ result_hash = @user.get_add_credential_message('user1', 'credential', 'STANDARD_OTP', nil)
75
+
76
+ result_hash[:'vip:requestId'] = nil
77
+
78
+ expected_hash = {
79
+ 'vip:requestId': nil,
80
+ 'vip:userId': 'user1',
81
+ 'vip:credentialDetail': {
82
+ 'vip:credentialId': 'credential',
83
+ 'vip:credentialType': 'STANDARD_OTP'
84
+ }
85
+ }
86
+
87
+ expect(result_hash).to match expected_hash
88
+
89
+ end
90
+
91
+ it 'gets the body with a friendly name and otp' do
92
+
93
+ options = {name: 'testCredential', otp: '123456'}
94
+ result_hash = @user.get_add_credential_message('user1', 'credential', 'STANDARD_OTP', options)
95
+
96
+ # TODO: this is a hack until we mock the utilities class to set the request id
97
+ result_hash[:'vip:requestId'] = nil
98
+
99
+ expected_hash = {
100
+ 'vip:requestId': nil,
101
+ 'vip:userId': 'user1',
102
+ 'vip:otpAuthData': {
103
+ 'vip:otp': '123456'
104
+ },
105
+ 'vip:credentialDetail': {
106
+ 'vip:credentialId': 'credential',
107
+ 'vip:credentialType': 'STANDARD_OTP',
108
+ 'vip:friendlyName': 'testCredential'
109
+ }
110
+ }
111
+
112
+ expect(result_hash).to match expected_hash
113
+
114
+ end
115
+
116
+ it 'removes a credential from a user' do
117
+
118
+ body = File.read("spec/fixtures/user/remove_credential_response.xml")
119
+ savon.expects(:remove_credential).with(message: :any).returns(body)
120
+
121
+ result_hash = @user.remove_credential(@mgmt_client, '', '', '')
122
+
123
+ expected_hash = {
124
+ success: true,
125
+ message: 'Success',
126
+ id: '1234abcd'
127
+ }
128
+
129
+ expect(result_hash).to match expected_hash
130
+
131
+ end
132
+
133
+ it 'updates a user' do
134
+ body = File.read("spec/fixtures/user/update_user_response.xml")
135
+ savon.expects(:update_user).with(message: :any).returns(body)
136
+
137
+ result_hash = @user.update_user(@mgmt_client, '', nil)
138
+
139
+ expected_hash = {
140
+ success: true,
141
+ message: 'Success',
142
+ id: '123456'
143
+ }
144
+
145
+ expect(result_hash).to match expected_hash
146
+ end
147
+
148
+ it 'clears a users pin' do
149
+ body = File.read("spec/fixtures/user/clear_user_pin_response.xml")
150
+ savon.expects(:clear_user_pin).with(message: :any).returns(body)
151
+
152
+ result_hash = @user.clear_user_pin(@mgmt_client, '')
153
+
154
+ expected_hash = {
155
+ success: true,
156
+ message: 'Success',
157
+ id: '123edabc'
158
+ }
159
+
160
+ expect(result_hash).to match expected_hash
161
+ end
162
+
163
+ it 'sets temporary password attributes' do
164
+ body = File.read("spec/fixtures/user/set_temp_pass_attr_response.xml")
165
+ savon.expects(:set_temporary_password_attributes).with(message: :any).returns(body)
166
+
167
+ result_hash = @user.set_temp_pass_attr(@mgmt_client, '', nil)
168
+
169
+ expected_hash = {
170
+ success: true,
171
+ message: 'Success',
172
+ id: 'KSOfaUFH52'
173
+ }
174
+
175
+ expect(result_hash).to match expected_hash
176
+ end
177
+
178
+ it 'gets temporary password attributes' do
179
+ body = File.read("spec/fixtures/user/get_temp_pass_attr_response.xml")
180
+ savon.expects(:get_temporary_password_attributes).with(message: :any).returns(body)
181
+
182
+ result_hash = @user.get_temp_pass_attr(@query_client, '')
183
+
184
+ expected_hash = {
185
+ success: true,
186
+ message: 'Success',
187
+ id: '123456',
188
+ oneTime: true,
189
+ expiration: Date.parse('2011-04-08T08:17:50.000Z')
190
+ }
191
+
192
+ expect(result_hash).to match expected_hash
193
+ end
194
+
195
+ it 'sets a temporary password' do
196
+ body = File.read("spec/fixtures/user/set_temp_pass_response.xml")
197
+ savon.expects(:set_temporary_password).with(message: :any).returns(body)
198
+
199
+ result_hash = @user.set_temp_password(@mgmt_client, '', '', nil)
200
+
201
+ expected_hash = {
202
+ success: true,
203
+ message: 'Success',
204
+ id: '1234abcd',
205
+ password: '321345'
206
+ }
207
+
208
+ expect(result_hash).to match expected_hash
209
+ end
210
+
211
+ it 'clears a temporary password' do
212
+ body = File.read("spec/fixtures/user/clear_temp_password_response.xml")
213
+ savon.expects(:clear_temporary_password).with(message: :any).returns(body)
214
+
215
+ result_hash = @user.clear_temp_pass(@mgmt_client, '')
216
+
217
+ expected_hash = {
218
+ success: true,
219
+ message: 'Success',
220
+ id: '0HaNgjq7z9'
221
+ }
222
+
223
+ expect(result_hash).to match expected_hash
224
+ end
225
+
226
+ it 'updates a users credential' do
227
+
228
+ body = File.read("spec/fixtures/user/update_credential_response.xml")
229
+ savon.expects(:update_credential).with(message: :any).returns(body)
230
+
231
+ result_hash = @user.update_credential(@mgmt_client, '', '', '', '')
232
+
233
+ expected_hash = {
234
+ success: true,
235
+ message: 'Success',
236
+ id: '6dtFnd3qpK'
237
+ }
238
+
239
+ expect(result_hash).to match expected_hash
240
+
241
+ end
242
+
243
+ end
244
+
245
+ end