authy 2.7.5 → 3.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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +21 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +1 -11
- data/README.md +39 -195
- data/authy.gemspec +0 -2
- data/examples/Gemfile +6 -0
- data/examples/README.md +48 -0
- data/examples/demo.rb +23 -19
- data/lib/authy.rb +0 -2
- data/lib/authy/api.rb +64 -58
- 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/spec/authy/api_spec.rb +384 -91
- 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 +8 -11
- data/.travis.yml +0 -12
- 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/onetouch_spec.rb
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
class Utils
|
4
|
+
include Authy::URL
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@user = Authy::API.register_user(:email => @email,
|
10
|
-
:cellphone => @cellphone,
|
11
|
-
:country_code => 1)
|
12
|
-
expect(@user).to be_ok
|
13
|
-
end
|
7
|
+
describe Authy::OneTouch 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 }
|
14
10
|
|
11
|
+
describe ".send_approval_request" do
|
12
|
+
let(:url) { "#{Authy.api_url}/onetouch/json/users/#{user_id}/approval_requests" }
|
15
13
|
it 'creates a new approval_request for user' do
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
response_json = {
|
15
|
+
"approval_request" => {
|
16
|
+
"uuid" => "550e8400-e29b-41d4-a716-446655440000"
|
17
|
+
},
|
18
|
+
"success" => true
|
19
|
+
}.to_json
|
20
|
+
params = {
|
19
21
|
message: 'You are moving 10 BTC from your account',
|
20
22
|
details: {
|
21
23
|
'Bank account' => '23527922',
|
@@ -25,15 +27,27 @@ describe Authy::OneTouch do
|
|
25
27
|
'IP Address' => '192.168.0.3'
|
26
28
|
},
|
27
29
|
seconds_to_expire: 150
|
28
|
-
|
30
|
+
}
|
31
|
+
|
32
|
+
expect(Authy::API.http_client).to receive(:request)
|
33
|
+
.once
|
34
|
+
.with(:post, url, {
|
35
|
+
:body => Utils.escape_query(params),
|
36
|
+
:header => headers
|
37
|
+
})
|
38
|
+
.and_return(double(:status => 200, :body => response_json))
|
39
|
+
|
40
|
+
params[:id] = user_id
|
41
|
+
response = Authy::OneTouch.send_approval_request(params)
|
29
42
|
|
30
43
|
expect(response).to be_kind_of(Authy::Response)
|
31
44
|
expect(response).to be_ok
|
32
45
|
end
|
33
46
|
|
34
47
|
it 'requires message as mandatory' do
|
48
|
+
expect(Authy::API.http_client).to receive(:request).never
|
35
49
|
response = Authy::OneTouch.send_approval_request(
|
36
|
-
id:
|
50
|
+
id: user_id,
|
37
51
|
details: {
|
38
52
|
'Bank account' => '23527922',
|
39
53
|
'Amount' => '10 BTC',
|
@@ -49,20 +63,39 @@ describe Authy::OneTouch do
|
|
49
63
|
end
|
50
64
|
|
51
65
|
it 'does not require other fields as mandatory' do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
response_json = {
|
67
|
+
"approval_request" => {
|
68
|
+
"uuid" => "550e8400-e29b-41d4-a716-446655440000"
|
69
|
+
},
|
70
|
+
"success" => true
|
71
|
+
}.to_json
|
72
|
+
params = {
|
73
|
+
message: 'You are moving 10 BTC from your account'
|
74
|
+
}
|
75
|
+
|
76
|
+
expect(Authy::API.http_client).to receive(:request)
|
77
|
+
.once
|
78
|
+
.with(:post, url, {
|
79
|
+
:body => Utils.escape_query(params),
|
80
|
+
:header => headers
|
81
|
+
})
|
82
|
+
.and_return(double(:status => 200, :body => response_json))
|
83
|
+
|
84
|
+
params[:id] = user_id
|
85
|
+
response = Authy::OneTouch.send_approval_request(params)
|
57
86
|
|
58
87
|
expect(response).to be_kind_of(Authy::Response)
|
59
88
|
expect(response).to be_ok
|
60
89
|
end
|
61
90
|
|
62
91
|
it 'checks logos format' do
|
63
|
-
|
64
|
-
|
65
|
-
|
92
|
+
response_json = {
|
93
|
+
"approval_request" => {
|
94
|
+
"uuid" => "550e8400-e29b-41d4-a716-446655440000"
|
95
|
+
},
|
96
|
+
"success" => true
|
97
|
+
}.to_json
|
98
|
+
params = {
|
66
99
|
message: 'You are moving 10 BTC from your account',
|
67
100
|
details: {
|
68
101
|
'Bank account' => '23527922',
|
@@ -71,9 +104,19 @@ describe Authy::OneTouch do
|
|
71
104
|
hidden_details: {
|
72
105
|
'IP Address' => '192.168.0.3'
|
73
106
|
},
|
74
|
-
|
75
|
-
|
76
|
-
|
107
|
+
logos: [{res: 'low', url: 'http://foo.bar'}],
|
108
|
+
seconds_to_expire: 150
|
109
|
+
}
|
110
|
+
expect(Authy::API.http_client).to receive(:request)
|
111
|
+
.once
|
112
|
+
.with(:post, url, {
|
113
|
+
:body => Utils.escape_query(params),
|
114
|
+
:header => headers
|
115
|
+
})
|
116
|
+
.and_return(double(:status => 200, :body => response_json))
|
117
|
+
|
118
|
+
params[:id] = user_id
|
119
|
+
response = Authy::OneTouch.send_approval_request(params)
|
77
120
|
|
78
121
|
expect(response).to be_kind_of(Authy::Response)
|
79
122
|
expect(response).to be_ok
|
@@ -82,10 +125,23 @@ describe Authy::OneTouch do
|
|
82
125
|
|
83
126
|
describe '.approval_request_status' do
|
84
127
|
it 'returns approval request status' do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
128
|
+
uuid = '550e8400-e29b-41d4-a716-446655440000'
|
129
|
+
url = "#{Authy.api_url}/onetouch/json/approval_requests/#{uuid}"
|
130
|
+
response_json = {
|
131
|
+
"approval_request" => {
|
132
|
+
"status" => "pending"
|
133
|
+
},
|
134
|
+
"success" => true
|
135
|
+
}.to_json
|
136
|
+
expect(Authy::API.http_client).to receive(:request)
|
137
|
+
.once
|
138
|
+
.with(:get, url, {
|
139
|
+
:header => headers,
|
140
|
+
:query => {},
|
141
|
+
:follow_redirect => nil
|
142
|
+
})
|
143
|
+
.and_return(double(:status => 200, :body => response_json))
|
144
|
+
response = Authy::OneTouch.approval_request_status(uuid: uuid)
|
89
145
|
|
90
146
|
expect(response).to be_kind_of(Authy::Response)
|
91
147
|
expect(response).to be_ok
|
@@ -1,108 +1,239 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class Utils
|
4
|
+
include Authy::URL
|
5
|
+
end
|
6
|
+
|
3
7
|
describe "Authy::PhoneVerification" do
|
4
|
-
|
8
|
+
let(:valid_phone_number) { '201-555-0123' }
|
9
|
+
let(:invalid_phone_number) { '123' }
|
10
|
+
let(:headers) { { "X-Authy-API-Key" => Authy.api_key, "User-Agent" => "AuthyRuby/#{Authy::VERSION} (#{RUBY_PLATFORM}, Ruby #{RUBY_VERSION})" } }
|
11
|
+
let(:start_url) { "#{Authy.api_url}/protected/json/phones/verification/start" }
|
12
|
+
let(:check_url) { "#{Authy.api_url}/protected/json/phones/verification/check"}
|
5
13
|
|
14
|
+
describe "Sending the verification code" do
|
6
15
|
it "should send the code via SMS" do
|
7
|
-
|
8
|
-
|
16
|
+
response_json = {
|
17
|
+
"carrier" => "Fixed Line Operators and Other Networks",
|
18
|
+
"is_cellphone" => true,
|
19
|
+
"is_ported" => false,
|
20
|
+
"message" => "Text message sent to +1 201-555-0123.",
|
21
|
+
"seconds_to_expire" => 0,
|
22
|
+
"uuid" => nil,
|
23
|
+
"success" => true
|
24
|
+
}.to_json
|
25
|
+
params = {
|
9
26
|
via: "sms",
|
10
27
|
country_code: "1",
|
11
|
-
phone_number:
|
12
|
-
|
13
|
-
|
28
|
+
phone_number: valid_phone_number
|
29
|
+
}
|
30
|
+
expect(Authy::API.http_client).to receive(:request)
|
31
|
+
.once
|
32
|
+
.with(:post, start_url, {
|
33
|
+
:body => Utils.escape_query(params),
|
34
|
+
:header => headers
|
35
|
+
})
|
36
|
+
.and_return(double(:status => 200, :body => response_json))
|
37
|
+
response = Authy::PhoneVerification.start(params)
|
14
38
|
expect(response).to be_kind_of(Authy::Response)
|
15
39
|
expect(response).to be_ok
|
16
|
-
expect(response.message).to eq "Text message sent to +1
|
40
|
+
expect(response.message).to eq "Text message sent to +1 #{valid_phone_number}."
|
17
41
|
end
|
18
42
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
43
|
+
it "should send the code via SMS with code length" do
|
44
|
+
response_json = {
|
45
|
+
"carrier" => "Fixed Line Operators and Other Networks",
|
46
|
+
"is_cellphone" => true,
|
47
|
+
"is_ported" => false,
|
48
|
+
"message" => "Text message sent to +1 201-555-0123.",
|
49
|
+
"seconds_to_expire" => 0,
|
50
|
+
"uuid" => nil,
|
51
|
+
"success" => true
|
52
|
+
}.to_json
|
53
|
+
params = {
|
54
|
+
via: "sms",
|
55
|
+
country_code: "1",
|
56
|
+
phone_number: valid_phone_number,
|
57
|
+
code_length: "4"
|
58
|
+
}
|
59
|
+
expect(Authy::API.http_client).to receive(:request)
|
60
|
+
.once
|
61
|
+
.with(:post, start_url, {
|
62
|
+
:body => Utils.escape_query(params),
|
63
|
+
:header => headers
|
64
|
+
})
|
65
|
+
.and_return(double(:status => 200, :body => response_json))
|
66
|
+
response = Authy::PhoneVerification.start(params)
|
67
|
+
|
68
|
+
expect(response).to be_kind_of(Authy::Response)
|
69
|
+
expect(response).to be_ok
|
70
|
+
expect(response.message).to eq "Text message sent to +1 #{valid_phone_number}."
|
71
|
+
end
|
30
72
|
end
|
31
73
|
|
32
74
|
describe "validate the fields required" do
|
33
75
|
it "should return an error. Country code is required" do
|
34
|
-
|
76
|
+
response_json = {
|
77
|
+
"error_code" => "60004",
|
78
|
+
"message" => "Invalid parameter: country_code - Parameter is required",
|
79
|
+
"errors" => {
|
80
|
+
"message" => "Invalid parameter: country_code - Parameter is required"
|
81
|
+
},
|
82
|
+
"success" => false
|
83
|
+
}.to_json
|
84
|
+
params = {
|
35
85
|
via: "sms",
|
36
|
-
phone_number:
|
37
|
-
|
38
|
-
|
86
|
+
phone_number: valid_phone_number
|
87
|
+
}
|
88
|
+
expect(Authy::API.http_client).to receive(:request)
|
89
|
+
.once
|
90
|
+
.with(:post, start_url, {
|
91
|
+
:body => Utils.escape_query(params),
|
92
|
+
:header => headers
|
93
|
+
})
|
94
|
+
.and_return(double(:status => 400, :body => response_json))
|
95
|
+
response = Authy::PhoneVerification.start(params)
|
39
96
|
|
40
97
|
expect(response).to_not be_ok
|
41
98
|
expect(response.errors['message']).to match(/country_code - Parameter is required/)
|
42
99
|
end
|
43
100
|
|
44
101
|
it "should return an error. Cellphone is invalid" do
|
45
|
-
|
102
|
+
response_json = {
|
103
|
+
"error_code" => "60033",
|
104
|
+
"message" => "Phone number is invalid",
|
105
|
+
"errors" => {
|
106
|
+
"message" => "Phone number is invalid"
|
107
|
+
},
|
108
|
+
"success" => false
|
109
|
+
}.to_json
|
110
|
+
params = {
|
46
111
|
via: "sms",
|
47
112
|
country_code: "1",
|
48
|
-
phone_number:
|
49
|
-
|
113
|
+
phone_number: invalid_phone_number
|
114
|
+
}
|
115
|
+
expect(Authy::API.http_client).to receive(:request)
|
116
|
+
.once
|
117
|
+
.with(:post, start_url, {
|
118
|
+
:body => Utils.escape_query(params),
|
119
|
+
:header => headers
|
120
|
+
})
|
121
|
+
.and_return(double(:status => 400, :body => response_json))
|
122
|
+
response = Authy::PhoneVerification.start(params)
|
50
123
|
|
51
124
|
expect(response).to_not be_ok
|
52
125
|
expect(response.errors['message']).to eq('Phone number is invalid')
|
53
126
|
end
|
54
127
|
end
|
55
128
|
|
56
|
-
describe 'Check that a custom code request' do
|
57
|
-
it "should return an error if not enabled" do
|
58
|
-
pending("API is not returning expected response in this case. The test phone number is invalid")
|
59
|
-
|
60
|
-
response = Authy::PhoneVerification.start(
|
61
|
-
country_code: "1",
|
62
|
-
phone_number: "111-111-1111",
|
63
|
-
custom_code: "1234"
|
64
|
-
)
|
65
|
-
expect(response).not_to be_ok
|
66
|
-
expect(response.message).to eq("Phone verification couldn't be created: custom codes are not allowed.")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
129
|
describe "Check the verification code" do
|
71
130
|
it "should return success true if code is correct" do
|
72
|
-
|
73
|
-
|
74
|
-
|
131
|
+
response_json = {
|
132
|
+
"message" => "Verification code is correct.",
|
133
|
+
"success" => true
|
134
|
+
}.to_json
|
135
|
+
params = {
|
75
136
|
country_code: "1",
|
76
|
-
phone_number:
|
137
|
+
phone_number: valid_phone_number,
|
77
138
|
verification_code: "0000"
|
78
|
-
|
139
|
+
}
|
140
|
+
expect(Authy::API.http_client).to receive(:request)
|
141
|
+
.once
|
142
|
+
.with(:get, check_url, {
|
143
|
+
:query => params,
|
144
|
+
:header => headers,
|
145
|
+
:follow_redirect => nil
|
146
|
+
})
|
147
|
+
.and_return(double(:status => 200, :body => response_json))
|
148
|
+
response = Authy::PhoneVerification.check(params)
|
79
149
|
|
80
150
|
expect(response).to be_ok
|
81
151
|
expect(response.message).to eq('Verification code is correct.')
|
82
152
|
end
|
83
153
|
|
84
154
|
it "should return an error if code is incorrect" do
|
85
|
-
|
86
|
-
|
87
|
-
|
155
|
+
response_json = {
|
156
|
+
"error_code" => "60022",
|
157
|
+
"message" => "Verification code is incorrect",
|
158
|
+
"errors" => {
|
159
|
+
"message" => "Verification code is incorrect"
|
160
|
+
},
|
161
|
+
"success" => false
|
162
|
+
}.to_json
|
163
|
+
params = {
|
88
164
|
country_code: "1",
|
89
|
-
phone_number:
|
165
|
+
phone_number: valid_phone_number,
|
90
166
|
verification_code: "1234"
|
91
|
-
|
167
|
+
}
|
168
|
+
expect(Authy::API.http_client).to receive(:request)
|
169
|
+
.once
|
170
|
+
.with(:get, check_url, {
|
171
|
+
:query => params,
|
172
|
+
:header => headers,
|
173
|
+
:follow_redirect => nil
|
174
|
+
})
|
175
|
+
.and_return(double(:status => 401, :body => response_json))
|
176
|
+
response = Authy::PhoneVerification.check(params)
|
177
|
+
|
178
|
+
expect(response).not_to be_ok
|
179
|
+
expect(response.message).to eq('Verification code is incorrect')
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should return an error if there are no active verifications" do
|
183
|
+
response_json = {
|
184
|
+
"message" => "No pending verifications for #{valid_phone_number} found.",
|
185
|
+
"success" => false,
|
186
|
+
"errors" => {
|
187
|
+
"message" => "No pending verifications for #{valid_phone_number} found."
|
188
|
+
},
|
189
|
+
"error_code" => "60023"
|
190
|
+
}.to_json
|
191
|
+
params = {
|
192
|
+
:country_code => "1",
|
193
|
+
:phone_number => valid_phone_number,
|
194
|
+
:verification_code => "1234"
|
195
|
+
}
|
196
|
+
expect(Authy::API.http_client).to receive(:request)
|
197
|
+
.once
|
198
|
+
.with(:get, check_url, {
|
199
|
+
:query => params,
|
200
|
+
:header => headers,
|
201
|
+
:follow_redirect => nil
|
202
|
+
})
|
203
|
+
.and_return(double(:status => 404, :body => response_json))
|
204
|
+
|
205
|
+
response = Authy::PhoneVerification.check(params)
|
92
206
|
|
93
207
|
expect(response).not_to be_ok
|
94
|
-
expect(response.message).to eq(
|
208
|
+
expect(response.message).to eq("No pending verifications for #{valid_phone_number} found.")
|
95
209
|
end
|
96
210
|
end
|
97
211
|
|
98
212
|
describe 'Check the phone number' do
|
99
213
|
it "should return an error if phone number is invalid" do
|
100
|
-
|
214
|
+
response_json = {
|
215
|
+
"error_code" => "60033",
|
216
|
+
"message" => "Phone number is invalid",
|
217
|
+
"errors" => {
|
218
|
+
"message" => "Phone number is invalid"
|
219
|
+
},
|
220
|
+
"success" => false
|
221
|
+
}.to_json
|
222
|
+
params = {
|
101
223
|
country_code: "1",
|
102
|
-
phone_number:
|
224
|
+
phone_number: invalid_phone_number,
|
103
225
|
verification_code: "1234"
|
104
|
-
|
105
|
-
|
226
|
+
}
|
227
|
+
expect(Authy::API.http_client).to receive(:request)
|
228
|
+
.once
|
229
|
+
.with(:get, check_url, {
|
230
|
+
:query => params,
|
231
|
+
:header => headers,
|
232
|
+
:follow_redirect => nil
|
233
|
+
})
|
234
|
+
.and_return(double(:status => 400, :body => response_json))
|
235
|
+
|
236
|
+
response = Authy::PhoneVerification.check(params)
|
106
237
|
expect(response).not_to be_ok
|
107
238
|
expect(response.message).to eq('Phone number is invalid')
|
108
239
|
end
|