Exemple #1
0
    // Test matching line authentication credentials
    void testLineManagerAuthLineSelect()
    {
        UtlString lineId ;
        Url identity("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        Url alias("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        UtlBoolean bRC ;
        Url from ;
        Url contact ;
        SipLineMgr mgr ;

        // Add line
        SipLine line(identity, identity, "userId") ;
        lineId = line.getLineId() ;
        bRC = mgr.addLine(line, false) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add alias
        bRC = mgr.addLineAlias(identity, alias) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add credential
        UtlString passwordToken;
        HttpMessage::buildMd5UserPasswordDigest("userId", "testRealm", "password", passwordToken);
        bRC = mgr.addCredentialForLine(identity, "testRealm", "userId", passwordToken, HTTP_DIGEST_AUTHENTICATION) ;
        CPPUNIT_ASSERT(bRC) ;

        // Expected From and Contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            line.getPreferredContactUri(contact) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Expected From and Contact w/o lineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            contact = identity ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and Unknown Contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:[email protected]", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(!bRC) ;
        }

        // Unknown identity and Unknown Contact w/ LineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:[email protected]", Url::NameAddr, NULL) ;
            contact.setUrlParameter("LINEID", lineId) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and IP w/ LineId
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            contact.setUrlParameter("LINEID", lineId) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Expected identity and Unknown contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = identity ;
            from.setFieldParameter("tag", "5678") ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Alias identity and Unknown contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth;

            from = alias ;
            from.setFieldParameter("tag", "5678") ;
            contact = Url("sip:127.0.0.1", Url::NameAddr, NULL) ;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }

        // Unknown identity and alias contact
        {
            SipMessage request ;
            SipMessage response ;
            SipMessage requestWithAuth ;

            from = Url("<sip:[email protected]>;tag=5678", Url::NameAddr, NULL) ;
            contact = alias;
            buildRequestAndResponse(from, contact, request, response) ;
            bRC = mgr.buildAuthenticatedRequest(&response, &request, &requestWithAuth);
            CPPUNIT_ASSERT(bRC) ;
        }
    }
Exemple #2
0
    // Test line adding functions from the SipLineMgr
    void testLineManagerAddLine()
    {
        UtlString lineId ;
        Url identity("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        Url alias("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ;
        char cTemp[256] ;
        UtlBoolean bRC ;
        int iRC ;

        SipLineMgr mgr ;
        SipLine line(identity, identity, "userId") ;
        lineId = line.getLineId() ;

        // Add Line
        bRC = mgr.addLine(line, false) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add alias
        bRC = mgr.addLineAlias(identity, alias) ;
        CPPUNIT_ASSERT(bRC) ;

        // Add credential
        UtlString passwordToken;
        HttpMessage::buildMd5UserPasswordDigest("userId", "testRealm", "password", passwordToken);
        bRC = mgr.addCredentialForLine(identity, "testRealm", "userId", passwordToken, HTTP_DIGEST_AUTHENTICATION) ;
        CPPUNIT_ASSERT(bRC) ;


        // Sanity Checking
        iRC = mgr.getNumLines() ;
        CPPUNIT_ASSERT(iRC == 1) ;
        iRC = mgr.getNumOfCredentialsForLine(identity) ;
        CPPUNIT_ASSERT(iRC == 1) ;
        iRC = mgr.getNumOfCredentialsForLine(alias) ;
        CPPUNIT_ASSERT(iRC == 1) ;

        SipLine test ;

        //
        // Test getLine via "To" URL
        //
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:example.com", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("sip:[email protected]", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("sip:127.0.0.1", "", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "<sip:127.0.0.1;LINEID=%s>", lineId.data()) ;
        bRC = mgr.getLine(cTemp, "", "", test) ;
        CPPUNIT_ASSERT(bRC) ;

        //
        // Test getLine via local contact
        //
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:example.com", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "sip:[email protected]", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "sip:127.0.0.1", "", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "<sip:127.0.0.1;LINEID=%s>", lineId.data()) ;
        bRC = mgr.getLine("", cTemp, "", test) ;
        CPPUNIT_ASSERT(bRC) ;

        //
        // Test getLine via request URI
        //
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:example.com", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(bRC) ;
        bRC = mgr.getLine("", "", "sip:[email protected]", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        bRC = mgr.getLine("", "", "sip:127.0.0.1", test) ;
        CPPUNIT_ASSERT(!bRC) ;
        sprintf(cTemp, "sip:127.0.0.1;LINEID=%s", lineId.data()) ;
        bRC = mgr.getLine("", "", cTemp, test) ;
        CPPUNIT_ASSERT(bRC) ;
    }