@@ -68,6 +68,30 @@ public function testShouldNotParseMissingHost()
6868 ViaHeader::parse (['SIP/2.0/TCP ' ]);
6969 }
7070
71+ public function testShouldNotParseEmptyReceivedParameter ()
72+ {
73+ $ this ->expectException (InvalidHeaderParameter::class);
74+ ViaHeader::parse (['SIP/2.0/TCP 178.73.76.230:5060;branch=z9hG4bKiokioukju908;received ' ]);
75+ }
76+
77+ public function testShouldNotParseNonIPReceivedParameter ()
78+ {
79+ $ this ->expectException (InvalidHeaderParameter::class);
80+ ViaHeader::parse (['SIP/2.0/TCP 178.73.76.230:5060;branch=z9hG4bKiokioukju908;received=some.fqdn.com ' ]);
81+ }
82+
83+ public function testShouldNotParseNonNumericRPortParameter ()
84+ {
85+ $ this ->expectException (InvalidHeaderParameter::class);
86+ ViaHeader::parse (['SIP/2.0/TCP 178.73.76.230:5060;branch=z9hG4bKiokioukju908;rport=onethousandtwentyfour ' ]);
87+ }
88+
89+ public function testShouldNotParseLargeRPortParameter ()
90+ {
91+ $ this ->expectException (InvalidHeaderParameter::class);
92+ ViaHeader::parse (['SIP/2.0/TCP 178.73.76.230:5060;branch=z9hG4bKiokioukju908;rport=318272 ' ]);
93+ }
94+
7195 public function testShouldNotParseEmptyParameterNames ()
7296 {
7397 $ this ->expectException (InvalidHeaderParameter::class);
@@ -83,14 +107,38 @@ public function testShouldRenderWellFormedValues()
83107 $ via ->values [0 ]->transport = 'UDP ' ;
84108 $ via ->values [0 ]->host = '192.0.2.4:5060 ' ;
85109 $ via ->values [0 ]->branch = 'z9hG4bKnashds7 ' ;
110+ $ via ->values [0 ]->received = '64.52.36.12 ' ;
111+ $ via ->values [0 ]->rport = 1025 ;
112+ $ via ->values [0 ]->params ['custom ' ] = 'something ' ;
113+
114+ $ rendered = $ via ->render ('Via ' );
115+
116+ $ this ->assertNotNull ($ rendered );
117+ $ this ->assertIsString ($ rendered );
118+ $ this ->assertEquals (
119+ 'Via: SIP/2.0/UDP 192.0.2.4:5060;branch=z9hG4bKnashds7;received=64.52.36.12;rport=1025;custom=something ' . "\r\n" ,
120+ $ rendered
121+ );
122+ }
123+
124+ public function testShouldRenderEmptyRPort ()
125+ {
126+ $ via = new ViaHeader ;
127+ $ via ->values [0 ] = new ViaValue ;
128+ $ via ->values [0 ]->protocol = 'SIP ' ;
129+ $ via ->values [0 ]->version = '2.0 ' ;
130+ $ via ->values [0 ]->transport = 'UDP ' ;
131+ $ via ->values [0 ]->host = '192.0.2.4:5060 ' ;
132+ $ via ->values [0 ]->branch = 'z9hG4bKnashds7 ' ;
133+ $ via ->values [0 ]->rport = 0 ;
86134 $ via ->values [0 ]->params ['custom ' ] = 'something ' ;
87135
88136 $ rendered = $ via ->render ('Via ' );
89137
90138 $ this ->assertNotNull ($ rendered );
91139 $ this ->assertIsString ($ rendered );
92140 $ this ->assertEquals (
93- 'Via: SIP/2.0/UDP 192.0.2.4:5060;branch=z9hG4bKnashds7;custom=something ' . "\r\n" ,
141+ 'Via: SIP/2.0/UDP 192.0.2.4:5060;branch=z9hG4bKnashds7;rport; custom=something ' . "\r\n" ,
94142 $ rendered
95143 );
96144 }
0 commit comments