Here's a small test I wrote to check register messages. It is almost similar to existent test for INVITE message with some modifications
var userid string = "user1"
func TestSendRegisterUDP(t *testing.T) {
register, err := request([]string{
"REGISTER sip:ims.hom SIP/2.0",
"Via: SIP/2.0/UDP " + c_CLIENT + ";rport;branch=z9hG4bK996329494",
"Route: <sip:pcscf.ims.hom;lr>",
"From: <sip:"+userid+"@ims.hom>;tag=1224392795",
"To: <sip:"+userid+"@ims.hom>",
"Call-ID: 1379275388",
"CSeq: 1 REGISTER",
"Contact: <sip:"+userid+"@192.168.1.39:5060>",
"Authorization: Digest username=\""+userid+"@ims.hom\", realm=\"ims.hom\", nonce=\" \", uri=\"sip:ims.hom\", response=\" \"",
"Max-Forwards: 70",
"User-Agent: eXosip/3.1.0",
"Expires: 600000",
"Supported: path",
"Supported: gruu",
"Content-Length: 0",
"",
"",
})
assertNoError(t, err)
ok, err := response([]string{
"SIP/2.0 401 Unauthorized",
"CSeq: 1 REGISTER",
"Via: SIP/2.0/UDP " + c_SERVER + ";branch=z9hG4bK996329494",
"",
"",
})
test := transactionTest{actions: []action{
&clientSend{register},
&clientRecv{ok},
}}
test.Execute(t)
}
func (test *transactionTest) Execute(t *testing.T) {
var err error
test.client, err = NewManager("udp", c_CLIENT)
assertNoError(t, err)
defer test.client.Stop()
for _, actn := range test.actions {
testLog.Debug("Performing action %v", actn)
actn.Act(test)
}
}
type clientSend struct {
msg *base.Request
}
func (actn *clientSend) Act(test *transactionTest) error {
test.lastTx = test.client.Send(actn.msg, c_SERVER)
return nil
}
type clientRecv struct {
expected *base.Response
}
func (actn *clientRecv) Act(test *transactionTest) error {
go func() error {
for {
fmt.Println("Checking Responses")
responses := test.lastTx.Responses()
select {
case response, ok := <-responses:
if !ok {
return fmt.Errorf("Response channel prematurely closed")
} else if response.String() != actn.expected.String() {
return fmt.Errorf("Unexpected response:\n%s", response.String())
} else {
return nil
}
case <-time.After(time.Duration(1)*time.Second):
return fmt.Errorf("Timed out waiting for response")
}
}
}()
return nil
}
However, the issue here is, although I can see a response from the server via tcpdump, I'm not able to capture it via the response channel.
I've couple of questions: