void testNoRouteLocal() { const char* message = "INVITE sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); Url requestUri; UtlSList removedRoutes; testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes); UtlString normalizedMsg; int msgLen; testMsg.getBytes(&normalizedMsg, &msgLen); ASSERT_STR_EQUAL(message, normalizedMsg.data()); UtlString requestUriResult; requestUri.toString(requestUriResult); ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data()); CPPUNIT_ASSERT(removedRoutes.isEmpty()); }
void getOneRowByLocationCodeTest() { SipDbTestContext sipDbTestContext(TEST_DATA_DIR "/locationdata", TEST_WORK_DIR "/locationdata" ); sipDbTestContext.inputFile("dummy_loc_db.xml" ); LocationDB* pLocDb = LocationDB::getInstance("dummy_loc_db"); UtlHashMap hashmap; CPPUNIT_ASSERT( !pLocDb->getRowByLocationCode( "5144", hashmap ) ); CPPUNIT_ASSERT( pLocDb->getRowByLocationCode( "514", hashmap ) ); CPPUNIT_ASSERT( hashmap.entries() == 4 ); UtlString* pTempString; UtlString key; key = "name"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "Montreal", pTempString->data() ); key = "description"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "Go Habs Go!", pTempString->data() ); key = "locationcode"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "514", pTempString->data() ); key = "subnets"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "10.10.10.0/24,11.11.11.0/24,12.12.12.0/24", pTempString->data() ); }
void testAllNoDefaultPermutations() { FallbackRulesUrlMapping* urlmap; ResultSet registrations; UtlString actual; UtlString callTag = "UNK"; CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() ); UtlString simpleXml; mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml); CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS ); CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]") ,UtlString("boston"), registrations, callTag ) == OS_SUCCESS ); CPPUNIT_ASSERT_EQUAL( 2 , registrations.getSize() ); getResult( registrations, 0, "contact", actual); ASSERT_STR_EQUAL("sip:[email protected]",actual); getResult( registrations, 1, "contact", actual); ASSERT_STR_EQUAL("sip:[email protected]",actual); registrations.destroyAll(); CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]") ,UtlString("salem"), registrations, callTag ) != OS_SUCCESS ); CPPUNIT_ASSERT_EQUAL( 0 , registrations.getSize() ); delete urlmap; }
void testBranchIdparse() { size_t counter; UtlString uniqueValue; UtlString loopDetectKey; CPPUNIT_ASSERT(!BranchId::parse("z9hG4bK11e0671922444aa6a5f7f10b5", counter, uniqueValue, loopDetectKey)); CPPUNIT_ASSERT(uniqueValue.isNull()); CPPUNIT_ASSERT(loopDetectKey.isNull()); CPPUNIT_ASSERT(!BranchId::parse("az9hG4bK11e0671922444aa6a5f7f10b5", counter, uniqueValue, loopDetectKey)); CPPUNIT_ASSERT(uniqueValue.isNull()); CPPUNIT_ASSERT(loopDetectKey.isNull()); CPPUNIT_ASSERT(!BranchId::parse("x9hG4bK11e0671922444aa6a5f7f10b5", counter, uniqueValue, loopDetectKey)); CPPUNIT_ASSERT(uniqueValue.isNull()); CPPUNIT_ASSERT(loopDetectKey.isNull()); CPPUNIT_ASSERT(BranchId::parse("z9hG4bK-XX-0014xXPnvpKqfTHmjFlrAD5sPA~1Pke3N5l0uqpDw00P`ZWYw", counter, uniqueValue, loopDetectKey)); CPPUNIT_ASSERT_EQUAL((size_t)20, counter); ASSERT_STR_EQUAL("xXPnvpKqfTHmjFlrAD5sPA", uniqueValue.data()); ASSERT_STR_EQUAL("1Pke3N5l0uqpDw00P`ZWYw", loopDetectKey.data()); }
void testDoubleRoute() { const char* message = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:[email protected];lr>, <sip:[email protected];lr>\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); Url requestUri; UtlSList removedRoutes; testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes); UtlString normalizedMsg; int msgLen; testMsg.getBytes(&normalizedMsg, &msgLen); const char* expectedMessage = // route header removed, uri swapped "INVITE sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; ASSERT_STR_EQUAL(expectedMessage, normalizedMsg.data()); UtlString requestUriResult; requestUri.toString(requestUriResult); ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data()); UtlString* removedRoute; CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT( removedRoute = static_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:[email protected];lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT(removedRoutes.isEmpty()); }
// Test that an out-of-dialog request gets an authentication challenge when // the auth rules require it. void testForbidden() { const char* message = "INVITE sip:user@forbidden SIP/2.0\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:user@forbidden\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 2 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlString identity; // no authenticated identity Url requestUri("sip:somewhere@forbidden"); UtlSList noRemovedRoutes; UtlString routeName("example.com"); RouteState routeState( testMsg, noRemovedRoutes, routeName ); UtlString rejectReason; UtlString method("INVITE"); const bool bSpiralingRequest = false; AuthPlugin::AuthResult priorResult = AuthPlugin::CONTINUE; CPPUNIT_ASSERT(AuthPlugin::DENY == enforcer->authorizeAndModify(identity, requestUri, routeState, method, priorResult, testMsg, bSpiralingRequest, rejectReason )); ASSERT_STR_EQUAL("", rejectReason.data()); // now try the same request, but with an authenticated identity // so this time it should provide a reject reason identity = "*****@*****.**"; CPPUNIT_ASSERT(AuthPlugin::DENY == enforcer->authorizeAndModify(identity, requestUri, routeState, method, priorResult, testMsg, bSpiralingRequest, rejectReason )); ASSERT_STR_EQUAL("Requires NoAccess", rejectReason.data()); }
// Test that an authenticated REFER without Replaces to a good target is allowed and not modified void AuthenticatedRefer() { UtlString identity("controller@domain"); // an authenticated identity Url requestUri("sip:someone@somewhere"); const char* message = "REFER sip:someone@somewhere SIP/2.0\r\n" "Refer-To: [email protected]\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:someone@somewhere\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlSList noRemovedRoutes; UtlString myRouteName("myhost.example.com"); RouteState routeState( testMsg, noRemovedRoutes, myRouteName ); const char unmodifiedRejectReason[] = "unmodified"; UtlString rejectReason(unmodifiedRejectReason); UtlString method("REFER"); bool bSpiralingRequest = false; AuthPlugin::AuthResult priorResult = AuthPlugin::CONTINUE; CPPUNIT_ASSERT(AuthPlugin::CONTINUE == xferctl->authorizeAndModify(identity, requestUri, routeState, method, priorResult, testMsg, bSpiralingRequest, rejectReason )); ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data()); UtlString modifiedReferToStr; CPPUNIT_ASSERT(testMsg.getReferToField(modifiedReferToStr)); Url modifiedReferTo(modifiedReferToStr); CPPUNIT_ASSERT(Url::SipUrlScheme == modifiedReferTo.getScheme()); // check that the message has not been modified UtlString outputMsg; ssize_t outputSize; testMsg.getBytes(&outputMsg, &outputSize); ASSERT_STR_EQUAL(message, outputMsg.data()); }
void testBranchCopy() { UtlString sipXbranchId("z9hG4bK-XX-000af33a294c2143da892d81dbc8183fd7f8"); BranchId sipXcopied(sipXbranchId); ASSERT_STR_EQUAL(sipXbranchId.data(), sipXcopied.data()); UtlString non_sipXbranchId("z9hG4bK-94rkdeeepdeloepw%ww-lflll"); BranchId non_sipXcopied(non_sipXbranchId); ASSERT_STR_EQUAL(sipXbranchId.data(), sipXcopied.data()); }
void testMapUriNoRoot() { UtlString mapped; HttpServer server(NULL); server.addUriMap("/notrooturi", "/notrootpath"); CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/uripath", mapped)); ASSERT_STR_EQUAL("/uripath", mapped.data()); CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/", mapped)); ASSERT_STR_EQUAL("/", mapped.data()); }
// Test that a response message is allowed and is not modified void testNoPermResponse() { OsConfigDb configuration; configuration.set("RULES", TEST_DATA_DIR "/enforcerules.xml"); enforcer->readConfig(configuration); UtlString identity; // no authenticated identity Url requestUri("sip:somewhere@forbidden"); const char* message = "SIP/2.0 200 Ok\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:somewhere@forbidden\r\n" "From: Caller <sip:[email protected]>; tag=99911983748\r\n" "Call-Id: b1373e736d7d359ead76fa5cd467d999\r\n" "Cseq: 2 ACK\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "Record-Route: <sip:example.com;lr;sipXecs-rs=enforce%2Aauth%7E%21d1e296555015a54cb746fa7ac5695cf7>\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlSList noRemovedRoutes; UtlString routeName("example.com"); RouteState routeState( testMsg, noRemovedRoutes, routeName ); const char unmodifiedRejectReason[] = "unmodified"; UtlString rejectReason(unmodifiedRejectReason); UtlString method("INVITE"); const bool bSpiralingRequest = false; AuthPlugin::AuthResult priorResult = AuthPlugin::ALLOW; // SipRouter passes this for responses CPPUNIT_ASSERT(AuthPlugin::CONTINUE == enforcer->authorizeAndModify(identity, requestUri, routeState, method, priorResult, testMsg, bSpiralingRequest, rejectReason )); ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data()); UtlString recordRoute; CPPUNIT_ASSERT(testMsg.getRecordRouteField(0, &recordRoute)); ASSERT_STR_EQUAL( "<sip:example.com;lr;sipXecs-rs=enforce%2Aauth%7E%21d1e296555015a54cb746fa7ac5695cf7>", recordRoute ); }
void testMultiplePAIs_Mixed() { const char* message = "INVITE sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A29544 SIP/2.0\r\n" "Record-Route: <sip:192.168.0.2:5060;lr>\r\n" "From: caller <sip:[email protected]>;tag=94bc25b8-c0a80165-13c4-3e635-37aa1989-3e635\r\n" "To: <sip:[email protected]>\r\n" "Call-Id: 94bb2520-c0a80165-13c4-3e635-3ccd2971-3e635@rjolyscs2.ca.nortel.com\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 19\r\n" "Supported: replaces\r\n" "Contact: <sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A14956>\r\n" "P-Asserted-Identity: \"Some guy\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner1\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"Some other guy\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner2\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner3\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"yet another guy\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner4\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"you again\" <sip:[email protected]>\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlSList noRemovedRoutes; UtlString routeName("mydomain.com"); RouteState routeState( testMsg, noRemovedRoutes, routeName ); UtlString rejectReason; CPPUNIT_ASSERT(AuthPlugin::CONTINUE == spLinter->authorizeAndModify(identity, requestUri, routeState, "INVITE", AuthPlugin::CONTINUE, testMsg, false, rejectReason )); // verify that foreign PAIs are still there. const char* pPAI; CPPUNIT_ASSERT( ( pPAI = testMsg.getHeaderValue( 0, SipXauthIdentity::PAssertedIdentityHeaderName ) ) ); ASSERT_STR_EQUAL( "\"foreigner1\" <sip:[email protected]>", pPAI ); CPPUNIT_ASSERT( ( pPAI = testMsg.getHeaderValue( 1, SipXauthIdentity::PAssertedIdentityHeaderName ) ) ); ASSERT_STR_EQUAL( "\"foreigner2\" <sip:[email protected]>", pPAI ); CPPUNIT_ASSERT( ( pPAI = testMsg.getHeaderValue( 2, SipXauthIdentity::PAssertedIdentityHeaderName ) ) ); ASSERT_STR_EQUAL( "\"foreigner3\" <sip:[email protected]>", pPAI ); CPPUNIT_ASSERT( ( pPAI = testMsg.getHeaderValue( 3, SipXauthIdentity::PAssertedIdentityHeaderName ) ) ); ASSERT_STR_EQUAL( "\"foreigner4\" <sip:[email protected]>", pPAI ); }
void testGetAcceptField() { UtlString v; HttpMessage m0( "SUBSCRIBE sip:[email protected] SIP/2.0\r\n" "From: <sip:[email protected]>;tag=1c1198308561\r\n" "To: <sip:[email protected];user=phone>\r\n" "Call-Id: [email protected]\r\n" "Cseq: 1 INVITE\r\n" "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n" "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n" "Content-Length: 0\r\n" "\r\n" ); CPPUNIT_ASSERT(!m0.getAcceptField(v)); HttpMessage m1( "SUBSCRIBE sip:[email protected] SIP/2.0\r\n" "From: <sip:[email protected]>;tag=1c1198308561\r\n" "To: <sip:[email protected];user=phone>\r\n" "Call-Id: [email protected]\r\n" "Cseq: 1 INVITE\r\n" "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n" "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n" "Accept: foo, bar\r\n" "Content-Length: 0\r\n" "\r\n" ); CPPUNIT_ASSERT(m1.getAcceptField(v)); ASSERT_STR_EQUAL("foo, bar", v.data()); HttpMessage m2( "SUBSCRIBE sip:[email protected] SIP/2.0\r\n" "From: <sip:[email protected]>;tag=1c1198308561\r\n" "To: <sip:[email protected];user=phone>\r\n" "Call-Id: [email protected]\r\n" "Cseq: 1 INVITE\r\n" "Via: SIP/2.0/UDP 10.139.4.84;branch=z9hG4bK-de2c934952294f774ee0acbc133e9b1d\r\n" "Via: SIP/2.0/UDP 10.139.33.244;branch=z9hG4bKac1198312375\r\n" "Accept: foo, bar\r\n" "Accept: baz\r\n" "Content-Length: 0\r\n" "\r\n" ); CPPUNIT_ASSERT(m2.getAcceptField(v)); ASSERT_STR_EQUAL("foo, bar,baz", v.data()); }
// Basic santity checking for lines; make sure they work as expected void sanityTest() { Url identity("\"Display Name\" <sip:[email protected]>", Url::NameAddr, NULL) ; SipLine line(identity, identity, "userId") ; Url url = line.getIdentity() ; ASSERT_STR_EQUAL(identity.toString().data(), url.toString().data()) ; line.getPreferredContactUri(url) ; CPPUNIT_ASSERT(url.isUserHostPortEqual(url, SIP_PORT) == true) ; UtlString lineId = line.getLineId() ; UtlString lineParamId; url.getUrlParameter(SIP_LINE_IDENTIFIER, lineParamId) ; ASSERT_STR_EQUAL(lineParamId.data(), lineId.data()) ; }
// Test that a buggy REFER without Replaces from Exchange is modified void BadReferFromExchangeWithPort() { UtlString identity; // no authenticated identity Url requestUri("sip:[email protected]:56777"); const char* message = "REFER sip:[email protected]:56777 SIP/2.0\r\n" "Refer-To: [email protected]:56777\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:someone@somewhere\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "User-Agent: RTCC/2\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlSList noRemovedRoutes; UtlString myRouteName("myhost.example.com"); RouteState routeState( testMsg, noRemovedRoutes, myRouteName ); const char unmodifiedRejectReason[] = "unmodified"; UtlString rejectReason(unmodifiedRejectReason); UtlString method("REFER"); bool bSpiralingRequest = false; AuthPlugin::AuthResult priorResult = AuthPlugin::CONTINUE; CPPUNIT_ASSERT(AuthPlugin::CONTINUE == xferctl->authorizeAndModify(identity, requestUri, routeState, method, priorResult, testMsg, bSpiralingRequest, rejectReason )); ASSERT_STR_EQUAL(unmodifiedRejectReason, rejectReason.data()); // check that the target has been modified to our domain UtlString modifiedReferToStr; CPPUNIT_ASSERT(testMsg.getReferToField(modifiedReferToStr)); ASSERT_STR_EQUAL("sip:[email protected]", modifiedReferToStr.data()); }
void getOneRowByNameTest() { SipDbTestContext sipDbTestContext(TEST_DATA_DIR "/locationdata", TEST_WORK_DIR "/locationdata" ); sipDbTestContext.inputFile("dummy_loc_db.xml" ); LocationDB* pLocDb = LocationDB::getInstance("dummy_loc_db"); UtlHashMap hashmap; CPPUNIT_ASSERT( !pLocDb->getRowByName( "Washington", hashmap ) ); CPPUNIT_ASSERT( pLocDb->getRowByName( "Ottawa", hashmap ) ); CPPUNIT_ASSERT( hashmap.entries() == 4 ); UtlString* pTempString; UtlString key; key = "name"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "Ottawa", pTempString->data() ); key = "description"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "One crazy location", pTempString->data() ); key = "locationcode"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "613", pTempString->data() ); key = "subnets"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "172.30.0.0/16,22.22.22.22/32", pTempString->data() ); // get a second location row CPPUNIT_ASSERT( pLocDb->getRowByName( "Quebec", hashmap ) ); CPPUNIT_ASSERT( hashmap.entries() == 4 ); key = "name"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "Quebec", pTempString->data() ); key = "description"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "Happy 400th anniversary", pTempString->data() ); key = "locationcode"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( "418", pTempString->data() ); key = "subnets"; pTempString = dynamic_cast<UtlString*>(hashmap.findValue( &key ) ); CPPUNIT_ASSERT( pTempString ); ASSERT_STR_EQUAL( SPECIAL_IMDB_NULL_VALUE, pTempString->data() ); }
void testEscape() { const char* umlautUriValue = "\"Thomas Frölich Snom 320\" <sip:[email protected];transport=udp>;tag=zmbmylm36n"; UtlString umlautString(umlautUriValue); ASSERT_STR_EQUAL(umlautUriValue, umlautString.data()); HttpMessage::escape(umlautString); const char* umlautUriEscaped = "%22Thomas+Fr%C3%B6lich+Snom+320%22+%3Csip%3A2012%40pforzheim.org%3Btransport%3Dudp%3E%3Btag%3Dzmbmylm36n"; ASSERT_STR_EQUAL(umlautUriEscaped, umlautString.data()); HttpMessage::unescape(umlautString); ASSERT_STR_EQUAL(umlautUriValue, umlautString.data()); }
void blockSimultaneousCommand() { FileTestContext testContext(TEST_DATA_DIR "commandDef", TEST_WORK_DIR "commandDef"); // copy test files into testContext structure testContext.inputFile("goodcommand.xml"); testContext.inputFile("goodcommand.sh"); UtlString exePath; testContext.workingFilePath("goodcommand.sh", exePath); chmod(exePath.data(), S_IREAD | S_IWRITE | S_IEXEC); testContext.setSipxDir(SipXecsService::VarDirType, "var"); testContext.setSipxDir(SipXecsService::LogDirType); UtlString path; SipxCommand* command1; testContext.inputFilePath("goodcommand.xml", path); CPPUNIT_ASSERT((command1 = SipxCommand::createFromDefinition(path))); ASSERT_STR_EQUAL("Good", command1->data()); command1->execute(); OsTask::delay(500); // give task some time to get up and running // another invocation should fail: command is already running CPPUNIT_ASSERT(false == command1->execute()); OsTask::delay(1000); // give task some time to shutdown delete command1; }
void testMapUriPostRoot() { UtlString mapped; HttpServer server(NULL); server.addUriMap("/a/b", "/x/y"); CPPUNIT_ASSERT(HttpServer::mapUri(server.mUriMaps, "/a/b/c", mapped)); ASSERT_STR_EQUAL("/x/y/c", mapped.data()); CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/", mapped)); ASSERT_STR_EQUAL("/", mapped.data()); CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/x/a/b/c", mapped)); ASSERT_STR_EQUAL("/x/a/b/c", mapped.data()); }
void testTwoRoutesOneLocal() { const char* message = "INVITE sip:[email protected] SIP/2.0\r\n" "Route: <sip:example.com;lr>, <sip:proxy.somewhere.com;lr>\r\n" "Via: SIP/2.0/TCP 10.1.1.3:33855\r\n" "To: sip:[email protected]\r\n" "From: Caller <sip:[email protected]>; tag=30543f3483e1cb11ecb40866edd3295b\r\n" "Call-Id: f88dfabce84b6a2787ef024a7dbe8749\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 20\r\n" "Contact: [email protected]\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); Url requestUri; UtlSList removedRoutes; testMsg.normalizeProxyRoutes(UserAgent, requestUri, &removedRoutes); UtlString normalizedMsg; int msgLen; testMsg.getBytes(&normalizedMsg, &msgLen); UtlString requestUriResult; requestUri.toString(requestUriResult); ASSERT_STR_EQUAL("sip:[email protected]", requestUriResult.data()); UtlString* removedRoute; CPPUNIT_ASSERT( removedRoute = dynamic_cast<UtlString*>(removedRoutes.get())); ASSERT_STR_EQUAL("<sip:example.com;lr>", removedRoute->data()); delete removedRoute; CPPUNIT_ASSERT(removedRoutes.isEmpty()); UtlString route; /* "Route: <sip:proxy.somewhere.com;lr>\r\n" */ CPPUNIT_ASSERT(getNormalRoute(testMsg, 0, route)); ASSERT_STR_EQUAL("<sip:proxy.somewhere.com;lr>", route.data()); CPPUNIT_ASSERT(!getNormalRoute(testMsg, 1, route)); }
void runCommand() { FileTestContext testContext(TEST_DATA_DIR "commandDef", TEST_WORK_DIR "commandDef"); // copy test files into testContext structure testContext.inputFile("goodcommand.xml"); testContext.inputFile("goodcommand.sh"); UtlString exePath; testContext.workingFilePath("goodcommand.sh", exePath); chmod(exePath.data(), S_IREAD | S_IWRITE | S_IEXEC); testContext.setSipxDir(SipXecsService::VarDirType, "var"); testContext.setSipxDir(SipXecsService::LogDirType); UtlString path; SipxCommand* command1; testContext.inputFilePath("goodcommand.xml", path); CPPUNIT_ASSERT((command1 = SipxCommand::createFromDefinition(path))); ASSERT_STR_EQUAL("Good", command1->data()); UtlSList msgs; command1->getCommandMessages(msgs); CPPUNIT_ASSERT(0 == msgs.entries()); command1->execute(); OsTask::delay(500); // give task some time to get up and running CPPUNIT_ASSERT(true == command1->isRunning()); OsTask::delay(1000); // give task some time to finish CPPUNIT_ASSERT(false == command1->isRunning()); command1->getCommandMessages(msgs); CPPUNIT_ASSERT(3 == msgs.entries()); ASSERT_STR_EQUAL("stdout.msg-1: goodprocess.sh" , ((UtlString*)msgs.at(0))->data()); ASSERT_STR_EQUAL("return.code: 11" , ((UtlString*)msgs.at(2))->data()); msgs.destroyAll(); delete command1; OsTask::delay(1000); // give task some time to shutdown }
void testMapUriEndSep() { UtlString mapped; HttpServer server(NULL); server.addUriMap("/a/b/", "/root1"); // @TODO bogus that this doesn't work CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/a/b/c", mapped)); ASSERT_STR_EQUAL("/a/b/c", mapped.data()); server.addUriMap("/a/b", "/root2"); CPPUNIT_ASSERT(HttpServer::mapUri(server.mUriMaps, "/a/b/c", mapped)); ASSERT_STR_EQUAL("/root2/c", mapped.data()); CPPUNIT_ASSERT(!HttpServer::mapUri(server.mUriMaps, "/a/bc", mapped)); ASSERT_STR_EQUAL("/a/bc", mapped.data()); }
static void TestProtocol_DataReceived(PerfxProtocol *protocol, /* IN */ PerfxBuffer *buffer) /* IN */ { char *msg = (char *)buffer->data; ASSERT_STR_EQUAL("I loved that girl.", msg); gDataReceived = TRUE; PerfxMain_Quit(); }
static bool encode_err_returns_correct_json(char** msg) { const char* const EXPECTED = "{\"errorCode\":1}"; char* actual = ot_encode_err(1); ASSERT_STR_EQUAL(EXPECTED, actual, "Encoded error JSON was incorrect.", msg); free(actual); return true; }
void testEscaping() { const char* testString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"&version;\" state=\"full\" entity=\"sip:entity&@example.com;&=&\">\n" "<dialog id=\"<>&\" call-id=\"callid<>\" local-tag=\"localtag\" remote-tag=\"remotetag\" direction=\"recipient\">\n" "<state event=\"rejected\" code=\"456\">terminated</state>\n" "<duration>1</duration>\n" "<local>\n" "<identity display=\"local<>&\">sip:local&@example.com;a&=b&</identity>\n" "<target uri=\"sip:localtarget&@example.com;a&=b&\">\n" "<param pname=\"localparam\" pval=\"<>&\"/>\n" "</target>\n" "</local>\n" "<remote>\n" "<identity display=\"remote<>&\">sip:remote&@example.com;a&=b&</identity>\n" "<target uri=\"sip:remotetarget&@example.com;a&=b&\">\n" "<param pname=\"remoteparam\" pval=\"<>&\"/>\n" "</target>\n" "</remote>\n" "</dialog>\n" "</dialog-info>\n" ; // Allocate *dialog on the heap, so that it is freed when // dialogEvent goes out of scope, and not freed when dialog // goes out of scope. Dialog* dialog = new Dialog("<>&", "callid<>", "localtag", "remotetag", "recipient"); dialog->setState("terminated", "rejected", "456"); dialog->setDuration(OsDateTime::getSecsSinceEpoch()); dialog->setLocalIdentity("sip:local&@example.com;a&=b&", "local<>&"); dialog->setLocalTarget("sip:localtarget&@example.com;a&=b&"); dialog->addLocalParameter(new NameValuePairInsensitive("localparam", "<>&")); dialog->setRemoteIdentity("sip:remote&@example.com;a&=b&", "remote<>&"); dialog->setRemoteTarget("sip:remotetarget&@example.com;a&=b&"); dialog->addRemoteParameter(new NameValuePairInsensitive("remoteparam", "<>&")); SipDialogEvent dialogEvent("full", "sip:entity&@example.com;&=&"); dialogEvent.insertDialog(dialog); sleep(1); // so that the duration is now 1 dialogEvent.buildBody(NULL); const char* b; ssize_t l; dialogEvent.getBytes(&b, &l); ASSERT_STR_EQUAL(testString, b); }
void testMapUriToNull() { UtlString mapped; HttpServer server(NULL); server.addUriMap("/a/b", "/"); CPPUNIT_ASSERT(HttpServer::mapUri(server.mUriMaps, "/a/b/c/d", mapped)); // KNOWN_BUG("TODO", "mapping prefix to root or null does not work"); ASSERT_STR_EQUAL("/c/d", mapped.data()); }
void testMapUriLongest() { UtlString mapped; HttpServer server(NULL); server.addUriMap("/a/b/c", "/longpath"); server.addUriMap("/a/b", "/shortpath"); CPPUNIT_ASSERT(HttpServer::mapUri(server.mUriMaps, "/a/b/c/d", mapped)); ASSERT_STR_EQUAL("/longpath/d", mapped.data()); }
void testAllInternationalPermutations() { FallbackRulesUrlMapping* urlmap; ResultSet registrations; UtlString actual; UtlString callTag = "UNK"; CPPUNIT_ASSERT( urlmap = new FallbackRulesUrlMapping() ); UtlString simpleXml; mFileTestContext->inputFilePath("fallbackrules.xml", simpleXml); CPPUNIT_ASSERT( urlmap->loadMappings(simpleXml.data() ) == OS_SUCCESS ); CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]") ,UtlString("Boston"), registrations, callTag ) == OS_SUCCESS ); CPPUNIT_ASSERT_EQUAL( 1 , registrations.getSize() ); getResult( registrations, 0, "contact", actual); ASSERT_STR_EQUAL("sip:[email protected]",actual); registrations.destroyAll(); CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]") ,UtlString(""), registrations, callTag ) == OS_SUCCESS ); CPPUNIT_ASSERT_EQUAL( 1 , registrations.getSize() ); getResult( registrations, 0, "contact", actual); ASSERT_STR_EQUAL("sip:[email protected]",actual); registrations.destroyAll(); CPPUNIT_ASSERT( urlmap->getContactList( Url("sip:[email protected]") ,UtlString("ogden"), registrations, callTag ) == OS_SUCCESS ); CPPUNIT_ASSERT_EQUAL( 1 , registrations.getSize() ); getResult( registrations, 0, "contact", actual); ASSERT_STR_EQUAL("sip:[email protected]",actual); registrations.destroyAll(); delete urlmap; }
void SubscribeWithoutEventListSupportRejectedTest() { instantiateAllTestFixtures( "resource-lists1.xml", "subscription1", "credential1", "rlstest.test", TRUE); const char* message = "SUBSCRIBE sip:[email protected]:54140 SIP/2.0\r\n" "From: <sip:[email protected]>;tag=17211757-9E4FBD78\r\n" "To: <sip:[email protected]>\r\n" "CSeq: 1 SUBSCRIBE\r\n" "Call-ID: 51405734-b9be4835-dcd9d196\r\n" "Contact: <sip:[email protected]>\r\n" "Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, INFO, MESSAGE, SUBSCRIBE, NOTIFY, PRACK, UPDATE, REFER\r\n" "Event: dialog\r\n" "User-Agent: UnitTest\r\n" "Accept-Language: en\r\n" "Supported: something else\r\n" "Accept: application/dialog-info+xml,application/rlmi+xml,multipart/related\r\n" "Max-Forwards: 70\r\n" "Expires: 3600\r\n" "Content-Length: 0\r\n" "\r\n"; // send the SUBSCRIBE SipMessage request( message, strlen( message ) ); CPPUNIT_ASSERT( sendToRlsServerUnderTest( request ) ); // receive the 401 Unauthorized SipMessage response; CPPUNIT_ASSERT( getNextMessageFromRlsServerUnderTest( response, 5 ) ); CPPUNIT_ASSERT( response.isResponse() ); CPPUNIT_ASSERT( response.getResponseStatusCode() == HTTP_UNAUTHORIZED_CODE ); // craft a new SUBSCRIBE with proper credentials and send it CPPUNIT_ASSERT( addCredentialsToRequest( request, response ) ); CPPUNIT_ASSERT( sendToRlsServerUnderTest( request ) ); // receive the 421 Extension Required response CPPUNIT_ASSERT( getNextMessageFromRlsServerUnderTest( response, 5 ) ); CPPUNIT_ASSERT( response.isResponse() ); CPPUNIT_ASSERT( response.getResponseStatusCode() == SIP_EXTENSION_REQUIRED_CODE ); const char *pRequireFieldValue = response.getHeaderValue( 0, SIP_REQUIRE_FIELD ); CPPUNIT_ASSERT( pRequireFieldValue ); ASSERT_STR_EQUAL( SIP_EVENTLIST_EXTENSION, pRequireFieldValue ); // no requisite first NOTIFY request SipMessage notify_request; CPPUNIT_ASSERT( ! getNextMessageFromRlsServerUnderTest( notify_request, 5 ) ); }
void testMultiplePAIs_NoMatch() { const char* message = "INVITE sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A29544 SIP/2.0\r\n" "Record-Route: <sip:192.168.0.2:5060;lr>\r\n" "From: caller <sip:[email protected]>;tag=94bc25b8-c0a80165-13c4-3e635-37aa1989-3e635\r\n" "To: <sip:[email protected]>\r\n" "Call-Id: 94bb2520-c0a80165-13c4-3e635-3ccd2971-3e635@rjolyscs2.ca.nortel.com\r\n" "Cseq: 1 INVITE\r\n" "Max-Forwards: 19\r\n" "Supported: replaces\r\n" "Contact: <sip:[email protected]:5060;x-sipX-pubcontact=47.135.162.145%3A14956>\r\n" "P-Asserted-Identity: \"foreigner1\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner2\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner3\" <sip:[email protected]>\r\n" "P-Asserted-Identity: \"foreigner4\" <sip:[email protected]>\r\n" "Content-Length: 0\r\n" "\r\n"; SipMessage testMsg(message, strlen(message)); UtlSList noRemovedRoutes; UtlString routeName("mydomain.com"); RouteState routeState( testMsg, noRemovedRoutes, routeName ); UtlString rejectReason; CPPUNIT_ASSERT(AuthPlugin::CONTINUE == spLinter->authorizeAndModify(identity, requestUri, routeState, "INVITE", AuthPlugin::CONTINUE, testMsg, false, rejectReason )); ssize_t size; UtlString modifiedMessageText; testMsg.getBytes( &modifiedMessageText, &size ); ASSERT_STR_EQUAL( message, modifiedMessageText.data() ); }
void testReplaceAt() { UtlString target("won"); target.replaceAt(0,'t'); ASSERT_STR_EQUAL("ton", target.data()); target.replaceAt(1,'i'); ASSERT_STR_EQUAL("tin", target.data()); target.replaceAt(2,'e'); ASSERT_STR_EQUAL("tie", target.data()); target.replaceAt(3,'e'); ASSERT_STR_EQUAL("tie", target.data()); target.replaceAt(4,'e'); ASSERT_STR_EQUAL("tie", target.data()); target.replaceAt(5,'e'); ASSERT_STR_EQUAL("tie", target.data()); }