diff --git a/lib/sippy_cup/scenario.rb b/lib/sippy_cup/scenario.rb index 82863f5..04f3dea 100644 --- a/lib/sippy_cup/scenario.rb +++ b/lib/sippy_cup/scenario.rb @@ -16,6 +16,8 @@ class Scenario MSEC = 1_000 DEFAULT_RETRANS = 500 + SIP_URI_HEADER_MATCH = '.*?.*;tag=([^;]*)' + # # Build a scenario based on either a manifest string or a file handle. Manifests are supplied in YAML format. # All manifest keys can be overridden by passing in a Hash of corresponding values. @@ -297,17 +299,31 @@ def receive_invite(opts = { compact_header: false }) recv(opts.merge(request: 'INVITE', rrs: true)) do |recv| action = doc.create_element('action') do |action| action << doc.create_element('ereg') do |ereg| - ereg['regexp'] = '.*.*;tag=([^;]*)' + ereg['regexp'] = SIP_URI_HEADER_MATCH + ereg['search_in'] = 'hdr' + ereg['header'] = 'f:' + ereg['assign_to'] = 'dummy,remote_addr,remote_tag' + end + action << doc.create_element('ereg') do |ereg| + ereg['regexp'] = SIP_URI_HEADER_MATCH ereg['search_in'] = 'hdr' - ereg['header'] = opts[:compact_header] ? 'f:' : 'From:' + ereg['header'] = 'From:' ereg['assign_to'] = 'dummy,remote_addr,remote_tag' end + + action << doc.create_element('ereg') do |ereg| + ereg['regexp'] = '?' + ereg['search_in'] = 'hdr' + ereg['header'] = 't:' + ereg['assign_to'] = 'dummy,local_addr' + end action << doc.create_element('ereg') do |ereg| - ereg['regexp'] = '' + ereg['regexp'] = '?' ereg['search_in'] = 'hdr' - ereg['header'] = opts[:compact_header] ? 't:' : 'To:' + ereg['header'] = 'To:' ereg['assign_to'] = 'dummy,local_addr' end + action << doc.create_element('assignstr') do |assignstr| assignstr['assign_to'] = "call_addr" assignstr['value'] = "[$local_addr]" @@ -507,18 +523,39 @@ def receive_answer(opts = { compact_header: false }) rtd: true # Response Time Duration: Record the response time } + @direction = "outbound" + receive_200(options.merge(opts)) do |recv| recv << doc.create_element('action') do |action| action << doc.create_element('ereg') do |ereg| - ereg['regexp'] = '.*.*;tag=([^;]*)' + ereg['regexp'] = SIP_URI_HEADER_MATCH ereg['search_in'] = 'hdr' - ereg['header'] = opts[:compact_header] ? 'f:' : 'From:' + ereg['header'] = 't:' ereg['assign_to'] = 'dummy,remote_addr,remote_tag' end + action << doc.create_element('ereg') do |ereg| + ereg['regexp'] = SIP_URI_HEADER_MATCH + ereg['search_in'] = 'hdr' + ereg['header'] = 'To:' + ereg['assign_to'] = 'dummy,remote_addr,remote_tag' + end + + action << doc.create_element('ereg') do |ereg| + ereg['regexp'] = SIP_URI_HEADER_MATCH + ereg['search_in'] = 'hdr' + ereg['header'] = 'f:' + ereg['assign_to'] = 'dummy,local_addr,local_tag' + end + action << doc.create_element('ereg') do |ereg| + ereg['regexp'] = SIP_URI_HEADER_MATCH + ereg['search_in'] = 'hdr' + ereg['header'] = 'From:' + ereg['assign_to'] = 'dummy,local_addr,local_tag' + end end end # These variables will only be used if we initiate a hangup - @reference_variables += %w(dummy remote_addr remote_tag) + @reference_variables += %w(dummy remote_addr remote_tag local_addr local_tag) end # @@ -796,10 +833,10 @@ def send_bye(opts = {}) msg = <<-MSG BYE [next_url] SIP/2.0 -Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];rport;branch=[branch] -[routes] -To: "#{@from_user}" ;tag=[$remote_tag] -From: "#{@to_user}" ;tag=[call_number] +[last_Record-Route:] +[last_Via:] +#{@direction == "outbound" ? "To:" : "From:" } sip:[$remote_addr];tag=[$remote_tag] +#{@direction == "outbound" ? "From:" : "To:" } sip:[$local_addr];tag=[call_number] [last_Call-ID:] CSeq: [cseq] BYE Max-Forwards: 100 @@ -810,29 +847,6 @@ def send_bye(opts = {}) send msg, opts end - # - # Send a BYE message using destination of previous messages Contact Header - # - # @param [Hash] opts A set of options to modify the message parameters - # - def send_bye_using_contact(opts = {}) - msg = <<-MSG - -BYE [next_url] SIP/2.0 -Via: SIP/2.0/[transport] #{@adv_ip}:[local_port];rport;branch=[branch] -[routes] -To: "#{@from_user}" ;tag=[$remote_tag] -From: "#{@to_user}" ;tag=[call_number] -[last_Call-ID:] -Contact: -Max-Forwards: 100 -CSeq: [cseq] BYE -User-Agent: #{USER_AGENT} -Content-Length: 0 - MSG - send msg, opts - end - # # Expect to receive a BYE message # diff --git a/spec/sippy_cup/scenario_spec.rb b/spec/sippy_cup/scenario_spec.rb index ec7d335..0dd0178 100644 --- a/spec/sippy_cup/scenario_spec.rb +++ b/spec/sippy_cup/scenario_spec.rb @@ -503,9 +503,9 @@ subject.hangup opts end - it 'calls send_by_using_contact and receive_ok when passed a use_contact option' do + it 'calls send_bye and receive_ok when passed a use_contact option' do opts = { foo: 'bar', use_contact: true } - expect(subject).to receive(:send_bye_using_contact).with({ foo: 'bar' }) + expect(subject).to receive(:send_bye).with({ foo: 'bar' }) expect(subject).to receive(:receive_ok).with({ foo: 'bar' }) subject.hangup opts end