authy 2.7.4 → 3.0.1
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 +4 -4
- data/.github/workflows/build.yml +21 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +21 -0
- data/Gemfile +1 -11
- data/LICENSE.txt +1 -1
- data/README.md +59 -184
- data/authy.gemspec +2 -4
- data/examples/Gemfile +6 -0
- data/examples/README.md +48 -0
- data/examples/demo.rb +23 -19
- data/lib/authy/api.rb +67 -61
- data/lib/authy/config.rb +8 -0
- data/lib/authy/onetouch.rb +1 -1
- data/lib/authy/phone_verification.rb +5 -2
- data/lib/authy/url_helpers.rb +0 -4
- data/lib/authy/version.rb +1 -1
- data/lib/authy.rb +2 -2
- data/spec/authy/api_spec.rb +388 -92
- data/spec/authy/config_spec.rb +21 -1
- data/spec/authy/onetouch_spec.rb +86 -30
- data/spec/authy/phone_verification_spec.rb +185 -54
- data/spec/authy/url_helpers_spec.rb +0 -12
- data/spec/spec_helper.rb +1 -2
- data/verify-legacy-v1.md +35 -0
- metadata +14 -17
- data/.travis.yml +0 -4
- data/Gemfile.lock +0 -118
- data/examples/pv-check.rb +0 -9
- data/examples/pv.rb +0 -12
- data/lib/authy/core_ext.rb +0 -26
- data/lib/authy/phone_intelligence.rb +0 -23
- data/spec/authy/phone_intelligence_spec.rb +0 -94
data/spec/authy/api_spec.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class Utils
|
4
|
+
include Authy::URL
|
5
|
+
end
|
2
6
|
|
3
7
|
describe "Authy::API" do
|
8
|
+
let(:headers) { { "X-Authy-API-Key" => Authy.api_key, "User-Agent" => "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})" } }
|
9
|
+
let(:user_id) { 81547 }
|
10
|
+
let(:invalid_api_key) { "invalid_api_key" }
|
11
|
+
|
4
12
|
describe "request headers" do
|
5
|
-
it "contains api key in header" do
|
6
|
-
expect_any_instance_of(HTTPClient).to receive(:request).twice.with(
|
13
|
+
it "contains api key and user agent in header" do
|
14
|
+
expect_any_instance_of(HTTPClient).to receive(:request).twice.with(any_args, hash_including(header: headers)) { double(ok?: true, body: "", status: 200) }
|
7
15
|
|
8
16
|
url = "protected/json/foo/2"
|
9
17
|
Authy::API.get_request(url, {})
|
@@ -12,50 +20,130 @@ describe "Authy::API" do
|
|
12
20
|
end
|
13
21
|
|
14
22
|
describe "Registering users" do
|
15
|
-
|
16
|
-
|
23
|
+
let(:register_user_url) { "#{Authy.api_uri}/protected/json/users/new" }
|
24
|
+
|
25
|
+
it "should register a user successfully" do
|
26
|
+
user_attributes = {
|
17
27
|
email: generate_email,
|
18
28
|
cellphone: generate_cellphone,
|
19
29
|
country_code: 1
|
20
|
-
|
30
|
+
}
|
31
|
+
response_json = {
|
32
|
+
"message" => "User created successfully.",
|
33
|
+
"user" => { "id" => user_id },
|
34
|
+
"success" => true
|
35
|
+
}.to_json
|
36
|
+
expect(Authy::API.http_client).to receive(:request)
|
37
|
+
.once
|
38
|
+
.with(:post, register_user_url, {
|
39
|
+
:body => Utils.escape_query(
|
40
|
+
:user => user_attributes,
|
41
|
+
:send_install_link_via_sms => true
|
42
|
+
),
|
43
|
+
:header => headers
|
44
|
+
})
|
45
|
+
.and_return(double(:status => 200, :body => response_json))
|
46
|
+
|
47
|
+
user = Authy::API.register_user(user_attributes)
|
21
48
|
|
22
49
|
expect(user).to be_kind_of(Authy::Response)
|
23
50
|
expect(user).to be_kind_of(Authy::User)
|
24
51
|
expect(user).to_not be_nil
|
25
52
|
expect(user.id).to_not be_nil
|
26
|
-
expect(user.id).to
|
53
|
+
expect(user.id).to be(user_id)
|
27
54
|
end
|
28
55
|
|
29
56
|
it "should return the error messages as a hash" do
|
30
|
-
|
57
|
+
user_attributes = {
|
31
58
|
email: generate_email,
|
32
59
|
cellphone: "abc-1234",
|
33
60
|
country_code: 1
|
34
|
-
|
61
|
+
}
|
62
|
+
response_json = {
|
63
|
+
"cellphone" => "is invalid",
|
64
|
+
"message" => "User was not valid",
|
65
|
+
"success" => false,
|
66
|
+
"errors" => {
|
67
|
+
"cellphone" => "is invalid",
|
68
|
+
"message" => "User was not valid"
|
69
|
+
},
|
70
|
+
"error_code" => "60027"
|
71
|
+
}.to_json
|
72
|
+
|
73
|
+
expect(Authy::API.http_client).to receive(:request)
|
74
|
+
.once
|
75
|
+
.with(:post, register_user_url, {
|
76
|
+
:body => Utils.escape_query(
|
77
|
+
:user => user_attributes,
|
78
|
+
:send_install_link_via_sms => true
|
79
|
+
),
|
80
|
+
:header => headers
|
81
|
+
})
|
82
|
+
.and_return(double(:status => 400, :body => response_json))
|
83
|
+
|
84
|
+
user = Authy::API.register_user(user_attributes)
|
35
85
|
|
36
86
|
expect(user.errors).to be_kind_of(Hash)
|
37
|
-
expect(user.errors[
|
87
|
+
expect(user.errors["cellphone"]).to include "is invalid"
|
38
88
|
end
|
39
89
|
|
40
90
|
it "should allow to override the API key" do
|
41
|
-
|
91
|
+
response_json = {
|
92
|
+
"error_code" => "60001",
|
93
|
+
"message" => "Invalid API key",
|
94
|
+
"errors" => {"message" => "Invalid API key"},
|
95
|
+
"success" => false
|
96
|
+
}.to_json
|
97
|
+
user_attributes = {
|
42
98
|
email: generate_email,
|
43
99
|
cellphone: generate_cellphone,
|
44
100
|
country_code: 1,
|
45
|
-
api_key:
|
46
|
-
|
101
|
+
api_key: invalid_api_key
|
102
|
+
}
|
103
|
+
|
104
|
+
headers["X-Authy-API-Key"] = invalid_api_key
|
105
|
+
|
106
|
+
expect(Authy::API.http_client).to receive(:request)
|
107
|
+
.once
|
108
|
+
.with(:post, register_user_url, {
|
109
|
+
:body => Utils.escape_query(
|
110
|
+
:user => user_attributes.reject { |k,v| k === :api_key },
|
111
|
+
:send_install_link_via_sms => true
|
112
|
+
),
|
113
|
+
:header => headers
|
114
|
+
})
|
115
|
+
.and_return(double(:status => 401, :body => response_json))
|
116
|
+
|
117
|
+
user = Authy::API.register_user(user_attributes)
|
47
118
|
|
48
119
|
expect(user).to_not be_ok
|
49
|
-
expect(user.errors[
|
120
|
+
expect(user.errors["message"]).to match(/invalid api key/i)
|
50
121
|
end
|
51
122
|
|
52
123
|
it "should allow overriding send_install_link_via_sms default" do
|
53
|
-
|
124
|
+
response_json = {
|
125
|
+
"message" => "User created successfully.",
|
126
|
+
"user" => { "id" => user_id },
|
127
|
+
"success" => true
|
128
|
+
}.to_json
|
129
|
+
user_attributes = {
|
54
130
|
email: generate_email,
|
55
131
|
cellphone: generate_cellphone,
|
56
132
|
country_code: 1,
|
57
|
-
send_install_link_via_sms: false
|
58
|
-
|
133
|
+
send_install_link_via_sms: false
|
134
|
+
}
|
135
|
+
expect(Authy::API.http_client).to receive(:request)
|
136
|
+
.once
|
137
|
+
.with(:post, register_user_url, {
|
138
|
+
:body => Utils.escape_query(
|
139
|
+
:user => user_attributes.reject { |k,v| k === :send_install_link_via_sms },
|
140
|
+
:send_install_link_via_sms => false
|
141
|
+
),
|
142
|
+
:header => headers
|
143
|
+
})
|
144
|
+
.and_return(double(:status => 200, :body => response_json))
|
145
|
+
|
146
|
+
user = Authy::API.register_user(user_attributes)
|
59
147
|
|
60
148
|
expect(user).to be_kind_of(Authy::Response)
|
61
149
|
expect(user).to be_kind_of(Authy::User)
|
@@ -63,90 +151,98 @@ describe "Authy::API" do
|
|
63
151
|
expect(user.id).to_not be_nil
|
64
152
|
expect(user.id).to be_kind_of(Integer)
|
65
153
|
end
|
66
|
-
|
67
154
|
end
|
68
155
|
|
69
|
-
describe "
|
70
|
-
|
71
|
-
|
72
|
-
@cellphone = generate_cellphone
|
73
|
-
@user = Authy::API.register_user(
|
74
|
-
email: @email,
|
75
|
-
cellphone: @cellphone,
|
76
|
-
country_code: 1
|
77
|
-
)
|
78
|
-
expect(@user).to be_ok
|
79
|
-
end
|
156
|
+
describe "verifying tokens" do
|
157
|
+
let(:token) { "123456" }
|
158
|
+
let(:verify_url) { "#{Authy.api_uri}/protected/json/verify/#{token}/#{user_id}" }
|
80
159
|
|
81
|
-
it "should fail to validate a given token if the
|
82
|
-
|
160
|
+
it "should fail to validate a given token if the token is the wrong format" do
|
161
|
+
expect(Authy::API.http_client).to receive(:request).never
|
162
|
+
response = Authy::API.verify(token: "invalid_token", id: user_id)
|
83
163
|
|
84
164
|
expect(response).to be_kind_of(Authy::Response)
|
85
165
|
expect(response.ok?).to be_falsey
|
86
|
-
expect(response.errors[
|
166
|
+
expect(response.errors["message"]).to include "Token format is invalid"
|
87
167
|
end
|
88
168
|
|
89
169
|
it "should allow to override the API key" do
|
90
|
-
|
170
|
+
response_json = {
|
171
|
+
"error_code" => "60001",
|
172
|
+
"message" => "Invalid API key",
|
173
|
+
"errors" => {"message" => "Invalid API key"},
|
174
|
+
"success" => false
|
175
|
+
}.to_json
|
176
|
+
headers["X-Authy-API-Key"] = invalid_api_key
|
177
|
+
expect(Authy::API.http_client).to receive(:request)
|
178
|
+
.once
|
179
|
+
.with(:get, verify_url, {
|
180
|
+
:query => { :force => true },
|
181
|
+
:header => headers,
|
182
|
+
:follow_redirect => nil
|
183
|
+
})
|
184
|
+
.and_return(double(:status => 401, :body => response_json))
|
185
|
+
|
186
|
+
response = Authy::API.verify(token: "123456", id: user_id, api_key: invalid_api_key)
|
91
187
|
|
92
188
|
expect(response).to_not be_ok
|
93
|
-
expect(response.errors[
|
189
|
+
expect(response.errors["message"]).to match(/invalid api key/i)
|
94
190
|
end
|
95
191
|
|
96
192
|
it "should escape the params" do
|
193
|
+
expect(Authy::API.http_client).to receive(:request).never
|
97
194
|
expect do
|
98
|
-
Authy::API.verify(token:
|
195
|
+
Authy::API.verify(token: "[=#%@$&#(!@);.,", id: user_id)
|
99
196
|
end.to_not raise_error
|
100
197
|
end
|
101
198
|
|
102
199
|
it "should escape the params if have white spaces" do
|
200
|
+
expect(Authy::API.http_client).to receive(:request).never
|
103
201
|
expect do
|
104
|
-
Authy::API.verify(token: "token with space", id:
|
202
|
+
Authy::API.verify(token: "token with space", id: user_id)
|
105
203
|
end.to_not raise_error
|
106
204
|
end
|
107
205
|
|
108
206
|
it "should fail if a param is missing" do
|
109
|
-
|
207
|
+
expect(Authy::API.http_client).to receive(:request).never
|
208
|
+
response = Authy::API.verify(id: user_id)
|
110
209
|
expect(response).to be_kind_of(Authy::Response)
|
111
210
|
expect(response).to_not be_ok
|
112
|
-
expect(response["message"]).to include(
|
211
|
+
expect(response["message"]).to include("Token format is invalid")
|
113
212
|
end
|
114
213
|
|
115
|
-
it
|
116
|
-
|
214
|
+
it "fails when token format is invalid" do
|
215
|
+
expect(Authy::API.http_client).to receive(:request).never
|
216
|
+
response = Authy::API.verify(token: "0000", id: user_id)
|
117
217
|
|
118
218
|
expect(response.ok?).to be_falsey
|
119
219
|
expect(response).to be_kind_of(Authy::Response)
|
120
|
-
expect(response.errors[
|
220
|
+
expect(response.errors["message"]).to eq "Token format is invalid"
|
121
221
|
end
|
122
222
|
end
|
123
223
|
|
124
224
|
describe "requesting qr code for other authenticator apps" do
|
125
|
-
before do
|
126
|
-
@user = Authy::API.register_user(email: generate_email, cellphone: generate_cellphone, country_code: 1)
|
127
|
-
expect(@user).to be_ok
|
128
|
-
end
|
129
|
-
|
130
225
|
it "should request qrcode" do
|
131
|
-
url = "#{Authy.api_uri}/protected/json/users/#{
|
132
|
-
expect_any_instance_of(HTTPClient).to receive(:request).with(:post, url, body: "qr_size=300&label=example+app+name", header: {"X-Authy-API-Key" => Authy.api_key}) { double(ok?: true, body: "", status: 200) }
|
133
|
-
response = Authy::API.send("request_qr_code", id:
|
226
|
+
url = "#{Authy.api_uri}/protected/json/users/#{user_id}/secret"
|
227
|
+
expect_any_instance_of(HTTPClient).to receive(:request).with(:post, url, body: "qr_size=300&label=example+app+name", header: { "X-Authy-API-Key" => Authy.api_key, "User-Agent" => "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})" }) { double(ok?: true, body: "", status: 200) }
|
228
|
+
response = Authy::API.send("request_qr_code", id: user_id, qr_size: 300, qr_label: "example app name")
|
134
229
|
expect(response).to be_ok
|
135
230
|
end
|
136
231
|
|
137
|
-
|
138
232
|
context "user id is not a number" do
|
139
233
|
it "should not be ok" do
|
234
|
+
expect(Authy::API.http_client).to receive(:request).never
|
140
235
|
response = Authy::API.send("request_qr_code", id: "tony")
|
141
|
-
expect(response.errors[
|
236
|
+
expect(response.errors["message"]).to eq "User id is invalid"
|
142
237
|
expect(response).to_not be_ok
|
143
238
|
end
|
144
239
|
end
|
145
240
|
|
146
241
|
context "qr size is not a number" do
|
147
242
|
it "should return the right error" do
|
148
|
-
|
149
|
-
|
243
|
+
expect(Authy::API.http_client).to receive(:request).never
|
244
|
+
response = Authy::API.send("request_qr_code", id: user_id, qr_size: "notanumber")
|
245
|
+
expect(response.errors["message"]).to eq "Qr image size is invalid"
|
150
246
|
expect(response).to_not be_ok
|
151
247
|
end
|
152
248
|
end
|
@@ -155,58 +251,215 @@ describe "Authy::API" do
|
|
155
251
|
["sms", "phone_call"].each do |kind|
|
156
252
|
title = kind.upcase
|
157
253
|
describe "Requesting #{title}" do
|
158
|
-
|
159
|
-
|
160
|
-
expect(@user).to be_ok
|
161
|
-
end
|
254
|
+
let(:uri_param) { kind == "phone_call" ? "call" : kind }
|
255
|
+
let(:url) { "#{Authy.api_uri}/protected/json/#{uri_param}/#{user_id}" }
|
162
256
|
|
163
257
|
it "should request a #{title} token" do
|
164
|
-
|
165
|
-
|
166
|
-
expect_any_instance_of(HTTPClient).to receive(:request).with(:get, url, {query:{}, header:{ "X-Authy-API-Key" => Authy.api_key }, follow_redirect:nil}) { double(ok?: true, body: "", status: 200) }
|
167
|
-
response = Authy::API.send("request_#{kind}", id: @user.id)
|
258
|
+
expect_any_instance_of(HTTPClient).to receive(:request).with(:get, url, { query: {}, header: { "X-Authy-API-Key" => Authy.api_key, "User-Agent" => "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})" }, follow_redirect: nil }) { double(ok?: true, body: "", status: 200) }
|
259
|
+
response = Authy::API.send("request_#{kind}", id: user_id)
|
168
260
|
expect(response).to be_ok
|
169
261
|
end
|
170
262
|
|
171
263
|
it "should allow to override the API key" do
|
172
|
-
|
264
|
+
response_json = {
|
265
|
+
"error_code" => "60001",
|
266
|
+
"message" => "Invalid API key",
|
267
|
+
"errors" => {"message" => "Invalid API key"},
|
268
|
+
"success" => false
|
269
|
+
}.to_json
|
270
|
+
headers["X-Authy-API-Key"] = invalid_api_key
|
271
|
+
expect(Authy::API.http_client).to receive(:request)
|
272
|
+
.once
|
273
|
+
.with(:get, url, {
|
274
|
+
:header => headers,
|
275
|
+
:query => {},
|
276
|
+
:follow_redirect => nil
|
277
|
+
})
|
278
|
+
.and_return(double(:status => 401, :body => response_json))
|
279
|
+
response = Authy::API.send("request_#{kind}", id: user_id, api_key: invalid_api_key)
|
173
280
|
expect(response).to_not be_ok
|
174
|
-
expect(response.errors[
|
281
|
+
expect(response.errors["message"]).to match(/invalid api key/i)
|
175
282
|
end
|
176
283
|
|
177
284
|
it "should request a #{title} token using custom actions" do
|
178
|
-
|
285
|
+
response_json = {
|
286
|
+
:success => true
|
287
|
+
}.to_json
|
288
|
+
expect(Authy::API.http_client).to receive(:request)
|
289
|
+
.once
|
290
|
+
.with(:get, url, {
|
291
|
+
:header => headers,
|
292
|
+
:query => {
|
293
|
+
:action => "custom action?",
|
294
|
+
:action_message => "Action message $%^?@#"
|
295
|
+
},
|
296
|
+
:follow_redirect => nil
|
297
|
+
})
|
298
|
+
.and_return(double(:status => 200, :body => response_json))
|
299
|
+
response = Authy::API.send("request_#{kind}", id: user_id, action: "custom action?", action_message: "Action message $%^?@#")
|
179
300
|
expect(response).to be_ok
|
180
301
|
end
|
181
302
|
|
182
303
|
context "user doesn't exist" do
|
183
304
|
it "should not be ok" do
|
305
|
+
url = "#{Authy.api_uri}/protected/json/#{uri_param}/tony"
|
306
|
+
response_json = {
|
307
|
+
"message" => "User not found.",
|
308
|
+
"success" => false,
|
309
|
+
"errors" => { "message" => "User not found." },
|
310
|
+
"error_code" => "60026"
|
311
|
+
}.to_json
|
312
|
+
expect(Authy::API.http_client).to receive(:request)
|
313
|
+
.once
|
314
|
+
.with(:get, url, {
|
315
|
+
:header => headers,
|
316
|
+
:query => { },
|
317
|
+
:follow_redirect => nil
|
318
|
+
})
|
319
|
+
.and_return(double(:status => 404, :body => response_json))
|
184
320
|
response = Authy::API.send("request_#{kind}", id: "tony")
|
185
|
-
expect(response.errors[
|
321
|
+
expect(response.errors["message"]).to eq "User not found."
|
186
322
|
expect(response).to_not be_ok
|
187
323
|
end
|
188
324
|
end
|
189
325
|
end
|
190
326
|
end
|
191
327
|
|
192
|
-
describe "
|
328
|
+
describe "Requesting email" do
|
329
|
+
it "should request an email token" do
|
330
|
+
response_json = {
|
331
|
+
"success" => true,
|
332
|
+
"message" => "Email token was sent",
|
333
|
+
"email" => "recipient@foo.com",
|
334
|
+
"email_id" => "EMa364aa751cc280d8c22772307e2c5760"
|
335
|
+
}.to_json
|
336
|
+
url = "#{Authy.api_uri}/protected/json/email/#{user_id}"
|
337
|
+
|
338
|
+
expect(Authy::API.http_client).to receive(:request)
|
339
|
+
.once
|
340
|
+
.with(:post, url, { body: "", header: headers })
|
341
|
+
.and_return(double(ok?: true, body: response_json, status: 200))
|
342
|
+
response = Authy::API.request_email(id: user_id)
|
343
|
+
expect(response).to be_ok
|
344
|
+
end
|
345
|
+
|
193
346
|
context "user doesn't exist" do
|
194
347
|
it "should not be ok" do
|
195
|
-
|
348
|
+
url = "#{Authy.api_uri}/protected/json/email/tony"
|
349
|
+
response_json = {
|
350
|
+
"message" => "User not found.",
|
351
|
+
"success" => false,
|
352
|
+
"errors" => {
|
353
|
+
"message" => "User not found."
|
354
|
+
},
|
355
|
+
"error_code" => "60026"
|
356
|
+
}.to_json
|
357
|
+
expect(Authy::API.http_client).to receive(:request)
|
358
|
+
.once
|
359
|
+
.with(:post, url, {
|
360
|
+
:header => headers,
|
361
|
+
:body => ""
|
362
|
+
})
|
363
|
+
.and_return(double(:status => 404, :body => response_json))
|
364
|
+
response = Authy::API.request_email(id: "tony")
|
365
|
+
expect(response.errors['message']).to eq "User not found."
|
366
|
+
expect(response).to_not be_ok
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
describe "update user email" do
|
372
|
+
context "user doesn't exist" do
|
373
|
+
it "should not be ok" do
|
374
|
+
url = "#{Authy.api_uri}/protected/json/users/tony/update"
|
375
|
+
response_json = {
|
376
|
+
"message" => "User not found.",
|
377
|
+
"success" => false,
|
378
|
+
"errors" => {
|
379
|
+
"message" => "User not found."
|
380
|
+
},
|
381
|
+
"error_code" => "60026"
|
382
|
+
}.to_json
|
383
|
+
new_email = generate_email
|
384
|
+
expect(Authy::API.http_client).to receive(:request)
|
385
|
+
.once
|
386
|
+
.with(:post, url, {
|
387
|
+
:header => headers,
|
388
|
+
:body => Utils.escape_query(:email => new_email)
|
389
|
+
})
|
390
|
+
.and_return(double(:status => 404, :body => response_json))
|
391
|
+
|
392
|
+
response = Authy::API.update_user(id: "tony", email: new_email)
|
196
393
|
expect(response.errors['message']).to eq "User not found."
|
197
394
|
expect(response).to_not be_ok
|
198
395
|
end
|
199
396
|
end
|
200
397
|
|
201
398
|
context "user exists" do
|
202
|
-
|
203
|
-
|
204
|
-
|
399
|
+
it "should be ok" do
|
400
|
+
response_json = {
|
401
|
+
"message" => "User was updated successfully",
|
402
|
+
"success" => true
|
403
|
+
}.to_json
|
404
|
+
url = "#{Authy.api_uri}/protected/json/users/#{user_id}/update"
|
405
|
+
new_email = generate_email
|
406
|
+
expect(Authy::API.http_client).to receive(:request)
|
407
|
+
.once
|
408
|
+
.with(:post, url, {
|
409
|
+
body: Utils.escape_query({
|
410
|
+
email: new_email
|
411
|
+
}),
|
412
|
+
header: headers
|
413
|
+
})
|
414
|
+
.and_return(double(ok?: true, body: response_json, status: 200))
|
415
|
+
response = Authy::API.update_user(id: user_id, email: new_email)
|
416
|
+
expect(response.message).to eq "User was updated successfully"
|
417
|
+
expect(response).to be_ok
|
205
418
|
end
|
419
|
+
end
|
420
|
+
end
|
206
421
|
|
422
|
+
describe "delete users" do
|
423
|
+
context "user doesn't exist" do
|
424
|
+
it "should not be ok" do
|
425
|
+
url = "#{Authy.api_uri}/protected/json/users/delete/tony"
|
426
|
+
response_json = {
|
427
|
+
"message" => "User not found.",
|
428
|
+
"success" => false,
|
429
|
+
"errors" => {
|
430
|
+
"message" => "User not found."
|
431
|
+
},
|
432
|
+
"error_code" => "60026"
|
433
|
+
}.to_json
|
434
|
+
expect(Authy::API.http_client).to receive(:request)
|
435
|
+
.once
|
436
|
+
.with(:post, url, {
|
437
|
+
:header => headers,
|
438
|
+
:body => ""
|
439
|
+
})
|
440
|
+
.and_return(double(:status => 404, :body => response_json))
|
441
|
+
response = Authy::API.delete_user(id: "tony")
|
442
|
+
expect(response.errors["message"]).to eq "User not found."
|
443
|
+
expect(response).to_not be_ok
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "user exists" do
|
448
|
+
let(:url) { "#{Authy.api_uri}/protected/json/users/delete/31567" }
|
207
449
|
it "should be ok" do
|
208
|
-
|
209
|
-
|
450
|
+
response_json = {
|
451
|
+
"message" => "User removed from application",
|
452
|
+
"success" => false
|
453
|
+
}.to_json
|
454
|
+
expect(Authy::API.http_client).to receive(:request)
|
455
|
+
.once
|
456
|
+
.with(:post, url, {
|
457
|
+
:header => headers,
|
458
|
+
:body => ""
|
459
|
+
})
|
460
|
+
.and_return(double(:status => 200, :body => response_json))
|
461
|
+
response = Authy::API.delete_user(id: 31567)
|
462
|
+
expect(response.message).to eq "User removed from application"
|
210
463
|
expect(response).to be_ok
|
211
464
|
end
|
212
465
|
end
|
@@ -215,6 +468,23 @@ describe "Authy::API" do
|
|
215
468
|
describe "user status" do
|
216
469
|
context "user doesn't exist" do
|
217
470
|
it "should not be ok" do
|
471
|
+
url = "#{Authy.api_uri}/protected/json/users/tony/status"
|
472
|
+
response_json = {
|
473
|
+
"message" => "User not found.",
|
474
|
+
"success" => false,
|
475
|
+
"errors" => {
|
476
|
+
"message" => "User not found."
|
477
|
+
},
|
478
|
+
"error_code" => "60026"
|
479
|
+
}.to_json
|
480
|
+
expect(Authy::API.http_client).to receive(:request)
|
481
|
+
.once
|
482
|
+
.with(:get, url, {
|
483
|
+
:header => headers,
|
484
|
+
:query => {},
|
485
|
+
:follow_redirect => nil
|
486
|
+
})
|
487
|
+
.and_return(double(:status => 404, :body => response_json))
|
218
488
|
response = Authy::API.user_status(id: "tony")
|
219
489
|
expect(response.errors["message"]).to eq "User not found."
|
220
490
|
expect(response).to_not be_ok
|
@@ -222,13 +492,42 @@ describe "Authy::API" do
|
|
222
492
|
end
|
223
493
|
|
224
494
|
context "user exists" do
|
225
|
-
before do
|
226
|
-
@user = Authy::API.register_user(email: generate_email, cellphone: generate_cellphone, country_code: 1)
|
227
|
-
expect(@user).to be_ok
|
228
|
-
end
|
229
|
-
|
230
495
|
it "should be ok" do
|
231
|
-
|
496
|
+
url = "#{Authy.api_uri}/protected/json/users/290907/status"
|
497
|
+
response_json = {
|
498
|
+
"status" => {
|
499
|
+
"authy_id" => 290907,
|
500
|
+
"confirmed" => true,
|
501
|
+
"registered" => false,
|
502
|
+
"country_code" => 1,
|
503
|
+
"phone_number" => "XXX-XXX-1118",
|
504
|
+
"email" => "alfvawmu@authy.com",
|
505
|
+
"devices" => [],
|
506
|
+
"has_hard_token" => false,
|
507
|
+
"account_disabled" => false,
|
508
|
+
"detailed_devices" => [{
|
509
|
+
"device_type" => "authy",
|
510
|
+
"os_type" => "unknown",
|
511
|
+
"registration_device_id" => nil,
|
512
|
+
"registration_method" => nil,
|
513
|
+
"device_id" => 290908,
|
514
|
+
"last_sync_date" => 0,
|
515
|
+
"creation_date" => 1433868212
|
516
|
+
}],
|
517
|
+
"deleted_devices" => []
|
518
|
+
},
|
519
|
+
"message" => "User status.",
|
520
|
+
"success" => true
|
521
|
+
}.to_json
|
522
|
+
expect(Authy::API.http_client).to receive(:request)
|
523
|
+
.once
|
524
|
+
.with(:get, url, {
|
525
|
+
:header => headers,
|
526
|
+
:query => {},
|
527
|
+
:follow_redirect => nil
|
528
|
+
})
|
529
|
+
.and_return(double(:status => 200, :body => response_json))
|
530
|
+
response = Authy::API.user_status(id: 290907)
|
232
531
|
expect(response.status).to be_kind_of(Hash)
|
233
532
|
expect(response).to be_ok
|
234
533
|
end
|
@@ -236,13 +535,9 @@ describe "Authy::API" do
|
|
236
535
|
end
|
237
536
|
|
238
537
|
describe "blank params" do
|
239
|
-
before do
|
240
|
-
@user = Authy::API.register_user(email: generate_email, cellphone: generate_cellphone, country_code: 1)
|
241
|
-
expect(@user).to be_ok
|
242
|
-
end
|
243
|
-
|
244
538
|
[:request_sms, :request_phone_call, :delete_user].each do |method|
|
245
539
|
it "should return a proper response with the errors for #{method}" do
|
540
|
+
expect(Authy::API.http_client).to receive(:request).never
|
246
541
|
response = Authy::API.send(method, id: nil)
|
247
542
|
expect(response).to_not be_ok
|
248
543
|
expect(response.message).to eq "user_id is blank."
|
@@ -250,25 +545,26 @@ describe "Authy::API" do
|
|
250
545
|
end
|
251
546
|
|
252
547
|
it "should return a prope response with the errors for verify" do
|
548
|
+
expect(Authy::API.http_client).to receive(:request).never
|
253
549
|
response = Authy::API.verify({})
|
254
550
|
expect(response).to_not be_ok
|
255
551
|
expect(response.message).to eq "Token format is invalid"
|
256
552
|
end
|
257
553
|
end
|
258
554
|
|
259
|
-
describe
|
260
|
-
it
|
261
|
-
expect(Authy::API.send(:token_is_safe?,
|
555
|
+
describe ".token_is_safe?" do
|
556
|
+
it "checks minimum token size" do
|
557
|
+
expect(Authy::API.send(:token_is_safe?, "1")).to be false
|
262
558
|
end
|
263
559
|
|
264
|
-
it
|
265
|
-
expect(Authy::API.send(:token_is_safe?,
|
266
|
-
expect(Authy::API.send(:token_is_safe?,
|
560
|
+
it "checks valid characters" do
|
561
|
+
expect(Authy::API.send(:token_is_safe?, "123456")).to be true
|
562
|
+
expect(Authy::API.send(:token_is_safe?, "123456a")).to be false
|
267
563
|
end
|
268
564
|
|
269
|
-
it
|
270
|
-
expect(Authy::API.send(:token_is_safe?,
|
271
|
-
expect(Authy::API.send(:token_is_safe?,
|
565
|
+
it "checks maximum token size" do
|
566
|
+
expect(Authy::API.send(:token_is_safe?, "123456789098")).to be true
|
567
|
+
expect(Authy::API.send(:token_is_safe?, "1234567890987")).to be false
|
272
568
|
end
|
273
569
|
end
|
274
570
|
end
|