~singpolyma/sgx-jmp

63273fd60607be632fd39e709d8312d93650d202 — Stephen Paul Weber 6 months ago f873448
Don't allow bad tel format

Otherwise people can specify things that won't (or shouldn't) work.
2 files changed, 12 insertions(+), 1 deletions(-)

M lib/customer_fwd.rb
M test/test_customer_fwd.rb
M lib/customer_fwd.rb => lib/customer_fwd.rb +5 -0
@@ 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

M test/test_customer_fwd.rb => test/test_customer_fwd.rb +7 -1
@@ 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)