From fe52ed99bcc97ee3b5c3e161fa9ab09be140a3c1 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 23 Apr 2024 12:58:37 +0100 Subject: [PATCH 1/7] Adding `from` validation tests for sms and whatsapp channels --- test/vonage/test.rb | 2 +- .../verify2/channels/silent_auth_test.rb | 4 +- test/vonage/verify2/channels/sms_test.rb | 38 +++++++++++++++++-- test/vonage/verify2/channels/voice_test.rb | 4 +- .../channels/whats_app_interactive_test.rb | 4 +- .../vonage/verify2/channels/whats_app_test.rb | 20 ++++++++-- 6 files changed, 58 insertions(+), 14 deletions(-) diff --git a/test/vonage/test.rb b/test/vonage/test.rb index bee82215..95032d12 100644 --- a/test/vonage/test.rb +++ b/test/vonage/test.rb @@ -408,7 +408,7 @@ def e164_compliant_number '447000000000' end - def invalid_number + def non_e164_compliant_number 'abcdefg' end diff --git a/test/vonage/verify2/channels/silent_auth_test.rb b/test/vonage/verify2/channels/silent_auth_test.rb index 40e17784..877a8505 100644 --- a/test/vonage/verify2/channels/silent_auth_test.rb +++ b/test/vonage/verify2/channels/silent_auth_test.rb @@ -21,9 +21,9 @@ def test_to_setter_method assert_equal new_number, sa_workflow.instance_variable_get(:@to) end - def test_to_setter_method_with_invalid_number + def test_to_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - silent_auth_channel.to = invalid_number + silent_auth_channel.to = non_e164_compliant_number end end diff --git a/test/vonage/verify2/channels/sms_test.rb b/test/vonage/verify2/channels/sms_test.rb index 51159ac0..1fed0a54 100644 --- a/test/vonage/verify2/channels/sms_test.rb +++ b/test/vonage/verify2/channels/sms_test.rb @@ -29,9 +29,9 @@ def test_to_setter_method assert_equal new_number, channel.instance_variable_get(:@to) end - def test_to_setter_method_with_invalid_number + def test_to_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - sms_channel.to = invalid_number + sms_channel.to = non_e164_compliant_number end end @@ -39,7 +39,7 @@ def test_from_getter_method assert_nil sms_channel.from end - def test_from_setter_method + def test_from_setter_method_with_valid_numeric channel = sms_channel new_number = '447000000002' channel.from = new_number @@ -47,6 +47,38 @@ def test_from_setter_method assert_equal new_number, channel.instance_variable_get(:@from) end + def test_from_setter_method_with_valid_alphanumeric + channel = sms_channel + new_number = 'abc123' + channel.from = new_number + + assert_equal new_number, channel.instance_variable_get(:@from) + end + + def test_from_setter_method_with_numeric_too_short + assert_raises ArgumentError do + sms_channel.from = '4470000002' + end + end + + def test_from_setter_method_with_numeric_too_long + assert_raises ArgumentError do + sms_channel.from = '4470000000000002' + end + end + + def test_from_setter_method_with_alphanumeric_too_short + assert_raises ArgumentError do + sms_channel.from = 'ab' + end + end + + def test_from_setter_method_with_alphanumeric_too_long + assert_raises ArgumentError do + sms_channel.from = 'abcdefghijkl' + end + end + def test_entity_id_getter_method assert_nil sms_channel.entity_id end diff --git a/test/vonage/verify2/channels/voice_test.rb b/test/vonage/verify2/channels/voice_test.rb index ecbe5e1e..00643229 100644 --- a/test/vonage/verify2/channels/voice_test.rb +++ b/test/vonage/verify2/channels/voice_test.rb @@ -25,9 +25,9 @@ def test_to_setter_method assert_equal new_number, channel.instance_variable_get(:@to) end - def test_to_setter_method_with_invalid_number + def test_to_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - voice_channel.to = invalid_number + voice_channel.to = non_e164_compliant_number end end diff --git a/test/vonage/verify2/channels/whats_app_interactive_test.rb b/test/vonage/verify2/channels/whats_app_interactive_test.rb index 44377ddb..ef11de9b 100644 --- a/test/vonage/verify2/channels/whats_app_interactive_test.rb +++ b/test/vonage/verify2/channels/whats_app_interactive_test.rb @@ -25,9 +25,9 @@ def test_to_setter_method assert_equal new_number, channel.instance_variable_get(:@to) end - def test_to_setter_method_with_invalid_number + def test_to_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - whatsapp_interactive_channel.to = invalid_number + whatsapp_interactive_channel.to = non_e164_compliant_number end end diff --git a/test/vonage/verify2/channels/whats_app_test.rb b/test/vonage/verify2/channels/whats_app_test.rb index b4d8b38d..5c4d074c 100644 --- a/test/vonage/verify2/channels/whats_app_test.rb +++ b/test/vonage/verify2/channels/whats_app_test.rb @@ -29,9 +29,9 @@ def test_to_setter_method assert_equal new_number, channel.instance_variable_get(:@to) end - def test_to_setter_method_with_invalid_number + def test_to_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - whatsapp_channel.to = invalid_number + whatsapp_channel.to = non_e164_compliant_number end end @@ -47,9 +47,21 @@ def test_from_setter_method assert_equal new_number, channel.instance_variable_get(:@from) end - def test_from_setter_method_with_invalid_number + def test_from_setter_method_with_non_e164_compliant_number assert_raises ArgumentError do - whatsapp_channel.from = invalid_number + whatsapp_channel.from = non_e164_compliant_number + end + end + + def test_from_setter_method_with_number_too_short + assert_raises ArgumentError do + whatsapp_channel.from = '4470000002' + end + end + + def test_from_setter_method_with_number_too_long + assert_raises ArgumentError do + whatsapp_channel.from = '4470000000000002' end end From 6719e1033f4429bb4fa58f131668169c0b70626f Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 23 Apr 2024 14:33:36 +0100 Subject: [PATCH 2/7] Adding `from` validations to SMS and WhatsApp channels --- lib/vonage/verify2/channels/sms.rb | 10 ++++++++++ lib/vonage/verify2/channels/whats_app.rb | 1 + 2 files changed, 11 insertions(+) diff --git a/lib/vonage/verify2/channels/sms.rb b/lib/vonage/verify2/channels/sms.rb index f7cb1a79..220abce6 100644 --- a/lib/vonage/verify2/channels/sms.rb +++ b/lib/vonage/verify2/channels/sms.rb @@ -20,6 +20,7 @@ def to=(to) end def from=(from) + validate_from(from) @from = from end @@ -49,5 +50,14 @@ def to_h private attr_writer :channel + + def validate_from(from) + if from.match?(/\D/) + raise ArgumentError, "Invalid alpha-numeric 'from' value #{from}. Length must be between 3 and 11 characters." unless from.length.between?(3, 11) + else + raise ArgumentError, "Invalid numeric 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15) + raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from).valid? + end + end end end diff --git a/lib/vonage/verify2/channels/whats_app.rb b/lib/vonage/verify2/channels/whats_app.rb index 4dcbbd7b..ad333f1f 100644 --- a/lib/vonage/verify2/channels/whats_app.rb +++ b/lib/vonage/verify2/channels/whats_app.rb @@ -19,6 +19,7 @@ def to=(to) end def from=(from) + raise ArgumentError, "Invalid 'from' value #{from}. Length must be between 11 and 15 characters." unless from.length.between?(11, 15) raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from.to_i).valid? @from = from end From 6469e2ff057eeed8d16cab102c32ce57b9e16082 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 23 Apr 2024 14:44:57 +0100 Subject: [PATCH 3/7] Adding Verify2 `brand` length tests --- test/vonage/verify2_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index e51bd600..5364a20d 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -77,6 +77,22 @@ def test_start_verification_method_without_brand end end + def test_start_verification_method_wit_brand_too_short + workflow = [{channel: 'sms', to: to_number}] + + assert_raises ArgumentError do + verify2.start_verification(brand: '', workflow: workflow) + end + end + + def test_start_verification_method_wit_brand_too_long + workflow = [{channel: 'sms', to: to_number}] + + assert_raises ArgumentError do + verify2.start_verification(brand: 'abcdefghijklmnopq', workflow: workflow) + end + end + def test_start_verification_method_without_workflow assert_raises ArgumentError do verify2.start_verification(brand: brand) From 4a3cbb49f00071b36c0beae5839f262aaf2d893e Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 23 Apr 2024 14:49:33 +0100 Subject: [PATCH 4/7] Implementing Verify2 brand validation --- lib/vonage/verify2.rb | 3 +++ test/vonage/verify2_test.rb | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index d4311986..fbbc006c 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -17,6 +17,7 @@ class Verify2 < Namespace # ) # # @param [required, String] :brand The brand that is sending the verification request + # - Must be between 1 and 16 characters in length # # @param [required, Array] :workflow An array of hashes for channels in the workflow # @@ -32,6 +33,8 @@ class Verify2 < Namespace # @see https://developer.vonage.com/en/api/verify.v2#newRequest # def start_verification(brand:, workflow:, **opts) + raise ArgumentError, ':workflow must be a String' unless brand.is_a?(String) + raise ArgumentError, "Invalid 'brand' value #{brand}. Length must be between 1 and 16 characters." unless brand.length.between?(1, 16) raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array) raise ArgumentError, ':workflow must not be empty' if workflow.empty? diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index 5364a20d..f2aa08e3 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -77,7 +77,15 @@ def test_start_verification_method_without_brand end end - def test_start_verification_method_wit_brand_too_short + def test_start_verification_method_with_invalid_brand_type + workflow = [{channel: 'sms', to: to_number}] + + assert_raises ArgumentError do + verify2.start_verification(brand: 123, workflow: workflow) + end + end + + def test_start_verification_method_with_brand_too_short workflow = [{channel: 'sms', to: to_number}] assert_raises ArgumentError do @@ -85,7 +93,7 @@ def test_start_verification_method_wit_brand_too_short end end - def test_start_verification_method_wit_brand_too_long + def test_start_verification_method_with_brand_too_long workflow = [{channel: 'sms', to: to_number}] assert_raises ArgumentError do From 990f1c276900b463fc54a579d4562b49c0068a31 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 23 Apr 2024 15:05:45 +0100 Subject: [PATCH 5/7] Bunping version and updating changelog --- CHANGES.md | 4 ++++ lib/vonage/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0b349f3d..27453b20 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 7.25.0 + +* Validation updates to Verify v2 SMS and WhatsApp channels. [#309](https://github.com/Vonage/vonage-ruby-sdk/pull/309) + # 7.24.0 * 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 --git a/lib/vonage/version.rb b/lib/vonage/version.rb index 4281258d..a44d3131 100644 --- a/lib/vonage/version.rb +++ b/lib/vonage/version.rb @@ -1,5 +1,5 @@ # typed: strong module Vonage - VERSION = '7.24.0' + VERSION = '7.25.0' end From 37654f6474b31b6d602e4644611448cfbeda6370 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 30 Apr 2024 16:45:29 +0100 Subject: [PATCH 6/7] Fixing typo --- lib/vonage/verify2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index fbbc006c..9027b7d7 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -33,7 +33,7 @@ class Verify2 < Namespace # @see https://developer.vonage.com/en/api/verify.v2#newRequest # def start_verification(brand:, workflow:, **opts) - raise ArgumentError, ':workflow must be a String' unless brand.is_a?(String) + raise ArgumentError, ':brand must be a String' unless brand.is_a?(String) raise ArgumentError, "Invalid 'brand' value #{brand}. Length must be between 1 and 16 characters." unless brand.length.between?(1, 16) raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array) raise ArgumentError, ':workflow must not be empty' if workflow.empty? From 22f96559ba03bd656a7493dfbf32b27dfb9990c9 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 1 May 2024 11:48:17 +0100 Subject: [PATCH 7/7] Updating Ruby versions in testing matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7859441..cbd4d798 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - ruby: [2.5, 2.6, 2.7, 3.0, 3.1] + ruby: [3.0, 3.1, 3.2, 3.3] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2