@@ -112,6 +112,75 @@ func TestDialogServerTransactionCanceled(t *testing.T) {
112112
113113}
114114
115+ func TestDialogServerRequestsWithinDialog (t * testing.T ) {
116+ // https://datatracker.ietf.org/doc/html/rfc3261#section-12.2.2
117+
118+ ua , _ := NewUA ()
119+ defer ua .Close ()
120+ cli , _ := NewClient (ua )
121+
122+ uasContact := sip.ContactHeader {
123+ Address : sip.Uri {User : "test" , Host : "127.0.0.200" , Port : 5099 },
124+ }
125+ dialogSrv := NewDialogServerCache (cli , uasContact )
126+
127+ invite ,
_ ,
_ := createTestInvite (
t ,
"sip:[email protected] " ,
"udp" ,
"127.0.0.1:5090" )
128+ invite .AppendHeader (& sip.ContactHeader {Address : sip.Uri {Host : "uas" , Port : 1234 }})
129+
130+ t .Run ("InvalidCseq" , func (t * testing.T ) {
131+ // This covers issue explained as
132+ // https://github.com/emiago/sipgo/issues/187
133+ conn := & sip.UDPConnection {
134+ PacketConn : & fakes.UDPConn {
135+ Writers : map [string ]io.Writer {
136+ "127.0.0.1:5090" : bytes .NewBuffer (make ([]byte , 0 )),
137+ },
138+ },
139+ }
140+ tx := sip .NewServerTx ("test" , invite , conn , slog .Default ())
141+ tx .Init ()
142+
143+ dialog , err := dialogSrv .ReadInvite (invite , tx )
144+ require .NoError (t , err )
145+ defer dialog .Close ()
146+
147+ byeWrongCseq := newByeRequestUAC (invite , sip .NewResponseFromRequest (invite , 200 , "OK" , nil ), nil )
148+ byeWrongCseq .CSeq ().SeqNo --
149+ tx = sip .NewServerTx ("test" , byeWrongCseq , conn , slog .Default ())
150+ tx .Init ()
151+ err = dialog .ReadBye (byeWrongCseq , tx )
152+ require .ErrorIs (t , err , ErrDialogInvalidCseq )
153+ })
154+
155+ t .Run ("TerminateAfterSentRequest" , func (t * testing.T ) {
156+ // This covers issue explained as
157+ // https://github.com/emiago/sipgo/issues/187
158+ conn := & sip.UDPConnection {
159+ PacketConn : & fakes.UDPConn {
160+ Writers : map [string ]io.Writer {
161+ "127.0.0.1:5090" : bytes .NewBuffer (make ([]byte , 0 )),
162+ },
163+ },
164+ }
165+ tx := sip .NewServerTx ("test" , invite , conn , slog .Default ())
166+ tx .Init ()
167+
168+ dialog , err := dialogSrv .ReadInvite (invite , tx )
169+ require .NoError (t , err )
170+ defer dialog .Close ()
171+
172+ reinvite := sip .NewRequest (sip .INVITE , invite .From ().Address )
173+ _ , err = dialog .TransactionRequest (context .TODO (), reinvite )
174+ require .NoError (t , err )
175+
176+ bye := newByeRequestUAC (invite , sip .NewResponseFromRequest (invite , 200 , "OK" , nil ), nil )
177+ tx = sip .NewServerTx ("test-bye" , bye , conn , slog .Default ())
178+ tx .Init ()
179+ err = dialog .ReadBye (bye , tx )
180+ require .NoError (t , err )
181+ })
182+ }
183+
115184func TestDialogServer2xxRetransmission (t * testing.T ) {
116185 // sip.T1 = 1
117186 ua , _ := NewUA ()
0 commit comments