From 63273fd60607be632fd39e709d8312d93650d202 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 20 Oct 2021 13:17:48 -0500 Subject: [PATCH] Don't allow bad tel format Otherwise people can specify things that won't (or shouldn't) work. --- lib/customer_fwd.rb | 5 +++++ test/test_customer_fwd.rb | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/customer_fwd.rb b/lib/customer_fwd.rb index 9f575fc..400bee3 100644 --- a/lib/customer_fwd.rb +++ b/lib/customer_fwd.rb @@ -61,6 +61,11 @@ class CustomerFwd true end + def initialize(values) + super + raise "Bad tel format: #{uri}" unless uri.match?(/\Atel:\+1\d{10}\Z/) + end + def to uri.sub(/^tel:/, "") end diff --git a/test/test_customer_fwd.rb b/test/test_customer_fwd.rb index 8b76aa6..4409853 100644 --- a/test/test_customer_fwd.rb +++ b/test/test_customer_fwd.rb @@ -33,13 +33,19 @@ class CustomerFwdTest < Minitest::Test assert_equal sip, fwd.to end - property(:for_tel) { "+#{string(:digit)}" } + property(:for_tel) { sized(10) { "+1#{string(:digit)}" } } def for_tel(tel) fwd = CustomerFwd.for(uri: "tel:#{tel}", timeout: 10) assert_kind_of CustomerFwd::Tel, fwd assert_equal tel, fwd.to end + def test_for_bad_tel + assert_raises do + CustomerFwd.for(uri: "tel:2261234567", timeout: 10) + end + end + property(:for_sip) { "#{string(:alnum)}@#{string(:alnum)}.example.com" } def for_sip(sip) fwd = CustomerFwd.for(uri: "sip:#{sip}", timeout: 10) -- 2.45.2