Skip to content

Commit 2c04bc4

Browse files
authored
Verify v2 Validation Updates (#309)
* Adding validation to `from` and `brand` parameters for sms and whatsapp channels
1 parent 35e4214 commit 2c04bc4

File tree

13 files changed

+102
-16
lines changed

13 files changed

+102
-16
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
matrix:
2626
os: [ubuntu-latest, windows-latest, macos-latest]
27-
ruby: [2.5, 2.6, 2.7, 3.0, 3.1]
27+
ruby: [3.0, 3.1, 3.2, 3.3]
2828
runs-on: ${{ matrix.os }}
2929
steps:
3030
- uses: actions/checkout@v2

Diff for: CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 7.25.0
2+
3+
* Validation updates to Verify v2 SMS and WhatsApp channels. [#309](https://github.com/Vonage/vonage-ruby-sdk/pull/309)
4+
15
# 7.24.0
26

37
* Updating Video API functionality with methods for Live Captions, Audio Connector, Experience Composer, and a `publisheronly` cleint token role. [#307](https://github.com/Vonage/vonage-ruby-sdk/pull/307)

Diff for: lib/vonage/verify2.rb

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Verify2 < Namespace
1717
# )
1818
#
1919
# @param [required, String] :brand The brand that is sending the verification request
20+
# - Must be between 1 and 16 characters in length
2021
#
2122
# @param [required, Array<Hash>] :workflow An array of hashes for channels in the workflow
2223
#
@@ -32,6 +33,8 @@ class Verify2 < Namespace
3233
# @see https://developer.vonage.com/en/api/verify.v2#newRequest
3334
#
3435
def start_verification(brand:, workflow:, **opts)
36+
raise ArgumentError, ':brand must be a String' unless brand.is_a?(String)
37+
raise ArgumentError, "Invalid 'brand' value #{brand}. Length must be between 1 and 16 characters." unless brand.length.between?(1, 16)
3538
raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array)
3639
raise ArgumentError, ':workflow must not be empty' if workflow.empty?
3740

Diff for: lib/vonage/verify2/channels/sms.rb

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def to=(to)
2020
end
2121

2222
def from=(from)
23+
validate_from(from)
2324
@from = from
2425
end
2526

@@ -49,5 +50,14 @@ def to_h
4950
private
5051

5152
attr_writer :channel
53+
54+
def validate_from(from)
55+
if from.match?(/\D/)
56+
raise ArgumentError, "Invalid alpha-numeric 'from' value #{from}. Length must be between 3 and 11 characters." unless from.length.between?(3, 11)
57+
else
58+
raise ArgumentError, "Invalid numeric 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
59+
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from).valid?
60+
end
61+
end
5262
end
5363
end

Diff for: lib/vonage/verify2/channels/whats_app.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def to=(to)
1919
end
2020

2121
def from=(from)
22+
raise ArgumentError, "Invalid 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15)
2223
raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from.to_i).valid?
2324
@from = from
2425
end

Diff for: lib/vonage/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# typed: strong
22

33
module Vonage
4-
VERSION = '7.24.0'
4+
VERSION = '7.25.0'
55
end

Diff for: test/vonage/test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def e164_compliant_number
408408
'447000000000'
409409
end
410410

411-
def invalid_number
411+
def non_e164_compliant_number
412412
'abcdefg'
413413
end
414414

Diff for: test/vonage/verify2/channels/silent_auth_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def test_to_setter_method
2121
assert_equal new_number, sa_workflow.instance_variable_get(:@to)
2222
end
2323

24-
def test_to_setter_method_with_invalid_number
24+
def test_to_setter_method_with_non_e164_compliant_number
2525
assert_raises ArgumentError do
26-
silent_auth_channel.to = invalid_number
26+
silent_auth_channel.to = non_e164_compliant_number
2727
end
2828
end
2929

Diff for: test/vonage/verify2/channels/sms_test.rb

+35-3
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,56 @@ def test_to_setter_method
2929
assert_equal new_number, channel.instance_variable_get(:@to)
3030
end
3131

32-
def test_to_setter_method_with_invalid_number
32+
def test_to_setter_method_with_non_e164_compliant_number
3333
assert_raises ArgumentError do
34-
sms_channel.to = invalid_number
34+
sms_channel.to = non_e164_compliant_number
3535
end
3636
end
3737

3838
def test_from_getter_method
3939
assert_nil sms_channel.from
4040
end
4141

42-
def test_from_setter_method
42+
def test_from_setter_method_with_valid_numeric
4343
channel = sms_channel
4444
new_number = '447000000002'
4545
channel.from = new_number
4646

4747
assert_equal new_number, channel.instance_variable_get(:@from)
4848
end
4949

50+
def test_from_setter_method_with_valid_alphanumeric
51+
channel = sms_channel
52+
new_number = 'abc123'
53+
channel.from = new_number
54+
55+
assert_equal new_number, channel.instance_variable_get(:@from)
56+
end
57+
58+
def test_from_setter_method_with_numeric_too_short
59+
assert_raises ArgumentError do
60+
sms_channel.from = '4470000002'
61+
end
62+
end
63+
64+
def test_from_setter_method_with_numeric_too_long
65+
assert_raises ArgumentError do
66+
sms_channel.from = '4470000000000002'
67+
end
68+
end
69+
70+
def test_from_setter_method_with_alphanumeric_too_short
71+
assert_raises ArgumentError do
72+
sms_channel.from = 'ab'
73+
end
74+
end
75+
76+
def test_from_setter_method_with_alphanumeric_too_long
77+
assert_raises ArgumentError do
78+
sms_channel.from = 'abcdefghijkl'
79+
end
80+
end
81+
5082
def test_entity_id_getter_method
5183
assert_nil sms_channel.entity_id
5284
end

Diff for: test/vonage/verify2/channels/voice_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def test_to_setter_method
2525
assert_equal new_number, channel.instance_variable_get(:@to)
2626
end
2727

28-
def test_to_setter_method_with_invalid_number
28+
def test_to_setter_method_with_non_e164_compliant_number
2929
assert_raises ArgumentError do
30-
voice_channel.to = invalid_number
30+
voice_channel.to = non_e164_compliant_number
3131
end
3232
end
3333

Diff for: test/vonage/verify2/channels/whats_app_interactive_test.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def test_to_setter_method
2525
assert_equal new_number, channel.instance_variable_get(:@to)
2626
end
2727

28-
def test_to_setter_method_with_invalid_number
28+
def test_to_setter_method_with_non_e164_compliant_number
2929
assert_raises ArgumentError do
30-
whatsapp_interactive_channel.to = invalid_number
30+
whatsapp_interactive_channel.to = non_e164_compliant_number
3131
end
3232
end
3333

Diff for: test/vonage/verify2/channels/whats_app_test.rb

+16-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def test_to_setter_method
2929
assert_equal new_number, channel.instance_variable_get(:@to)
3030
end
3131

32-
def test_to_setter_method_with_invalid_number
32+
def test_to_setter_method_with_non_e164_compliant_number
3333
assert_raises ArgumentError do
34-
whatsapp_channel.to = invalid_number
34+
whatsapp_channel.to = non_e164_compliant_number
3535
end
3636
end
3737

@@ -47,9 +47,21 @@ def test_from_setter_method
4747
assert_equal new_number, channel.instance_variable_get(:@from)
4848
end
4949

50-
def test_from_setter_method_with_invalid_number
50+
def test_from_setter_method_with_non_e164_compliant_number
5151
assert_raises ArgumentError do
52-
whatsapp_channel.from = invalid_number
52+
whatsapp_channel.from = non_e164_compliant_number
53+
end
54+
end
55+
56+
def test_from_setter_method_with_number_too_short
57+
assert_raises ArgumentError do
58+
whatsapp_channel.from = '4470000002'
59+
end
60+
end
61+
62+
def test_from_setter_method_with_number_too_long
63+
assert_raises ArgumentError do
64+
whatsapp_channel.from = '4470000000000002'
5365
end
5466
end
5567

Diff for: test/vonage/verify2_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ def test_start_verification_method_without_brand
7777
end
7878
end
7979

80+
def test_start_verification_method_with_invalid_brand_type
81+
workflow = [{channel: 'sms', to: to_number}]
82+
83+
assert_raises ArgumentError do
84+
verify2.start_verification(brand: 123, workflow: workflow)
85+
end
86+
end
87+
88+
def test_start_verification_method_with_brand_too_short
89+
workflow = [{channel: 'sms', to: to_number}]
90+
91+
assert_raises ArgumentError do
92+
verify2.start_verification(brand: '', workflow: workflow)
93+
end
94+
end
95+
96+
def test_start_verification_method_with_brand_too_long
97+
workflow = [{channel: 'sms', to: to_number}]
98+
99+
assert_raises ArgumentError do
100+
verify2.start_verification(brand: 'abcdefghijklmnopq', workflow: workflow)
101+
end
102+
end
103+
80104
def test_start_verification_method_without_workflow
81105
assert_raises ArgumentError do
82106
verify2.start_verification(brand: brand)

0 commit comments

Comments
 (0)