~singpolyma/sgx-jmp

e67150915385518e9916c1c989592d3fe7641b5d — Stephen Paul Weber 9 months ago d8da4d0 + 63273fd
Merge branch 'ban-bad-tel-fwd'

* ban-bad-tel-fwd:
  Don't allow bad tel format
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)