Skip to content
Snippets Groups Projects
Commit 686131de authored by Tristan Matthews's avatar Tristan Matthews
Browse files

tests: cleanup

parent 26408126
Branches
Tags 2.2.1rc1
No related merge requests found
...@@ -231,7 +231,7 @@ void InstantMessagingTest::testGetTextArea() ...@@ -231,7 +231,7 @@ void InstantMessagingTest::testGetTextArea()
formatedText.append("</resource-lists>"); formatedText.append("</resource-lists>");
formatedText.append("--boundary--"); formatedText.append("--boundary--");
std::string message = findTextMessage(formatedText); std::string message(findTextMessage(formatedText));
std::cout << "message " << message << std::endl; std::cout << "message " << message << std::endl;
......
...@@ -50,24 +50,17 @@ ...@@ -50,24 +50,17 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
SdesNegotiatorTest::SdesNegotiatorTest() : pattern(0), sdesnego(0),
remoteOffer(0), localCapabilities(0)
{}
void SdesNegotiatorTest::testTagPattern() void SdesNegotiatorTest::testTagPattern()
{ {
DEBUG("-------------------- SdesNegotiatorTest::testTagPattern --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::testTagPattern --------------------\n");
std::string subject = "a=crypto:4"; std::string subject = "a=crypto:4";
pattern = new sfl::Pattern("^a=crypto:(?P<tag>[0-9]{1,9})"); sfl::Pattern pattern("^a=crypto:(?P<tag>[0-9]{1,9})");
*pattern << subject; pattern << subject;
CPPUNIT_ASSERT(pattern->matches());
CPPUNIT_ASSERT(pattern->group("tag").compare("4") == 0);
delete pattern; CPPUNIT_ASSERT(pattern.matches());
pattern = NULL; CPPUNIT_ASSERT(pattern.group("tag").compare("4") == 0);
} }
...@@ -77,17 +70,14 @@ void SdesNegotiatorTest::testCryptoSuitePattern() ...@@ -77,17 +70,14 @@ void SdesNegotiatorTest::testCryptoSuitePattern()
std::string subject = "AES_CM_128_HMAC_SHA1_80"; std::string subject = "AES_CM_128_HMAC_SHA1_80";
pattern = new sfl::Pattern("(?P<cryptoSuite>AES_CM_128_HMAC_SHA1_80|" \ sfl::Pattern pattern("(?P<cryptoSuite>AES_CM_128_HMAC_SHA1_80|" \
"AES_CM_128_HMAC_SHA1_32|" \ "AES_CM_128_HMAC_SHA1_32|" \
"F8_128_HMAC_SHA1_80|" \ "F8_128_HMAC_SHA1_80|" \
"[A-Za-z0-9_]+)"); "[A-Za-z0-9_]+)");
*pattern << subject; pattern << subject;
CPPUNIT_ASSERT(pattern->matches());
CPPUNIT_ASSERT(pattern->group("cryptoSuite").compare("AES_CM_128_HMAC_SHA1_80") == 0);
delete pattern; CPPUNIT_ASSERT(pattern.matches());
pattern = NULL; CPPUNIT_ASSERT(pattern.group("cryptoSuite").compare("AES_CM_128_HMAC_SHA1_80") == 0);
} }
...@@ -97,24 +87,21 @@ void SdesNegotiatorTest::testKeyParamsPattern() ...@@ -97,24 +87,21 @@ void SdesNegotiatorTest::testKeyParamsPattern()
std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32"; std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32";
pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ sfl::Pattern pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \
"(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \ "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \
"(2\\^(?P<lifetime>[0-9]+)\\|" \ "(2\\^(?P<lifetime>[0-9]+)\\|" \
"(?P<mkiValue>[0-9]+)\\:" \ "(?P<mkiValue>[0-9]+)\\:" \
"(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g");
*pattern << subject; pattern << subject;
pattern->matches(); pattern.matches();
CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); CPPUNIT_ASSERT(pattern.group("srtpKeyMethod").compare("inline:"));
CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") CPPUNIT_ASSERT(pattern.group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj")
== 0); == 0);
CPPUNIT_ASSERT(pattern->group("lifetime").compare("20") == 0); CPPUNIT_ASSERT(pattern.group("lifetime").compare("20") == 0);
CPPUNIT_ASSERT(pattern->group("mkiValue").compare("1") == 0); CPPUNIT_ASSERT(pattern.group("mkiValue").compare("1") == 0);
CPPUNIT_ASSERT(pattern->group("mkiLength").compare("32") == 0); CPPUNIT_ASSERT(pattern.group("mkiLength").compare("32") == 0);
delete pattern;
pattern = NULL;
} }
...@@ -122,22 +109,19 @@ void SdesNegotiatorTest::testKeyParamsPatternWithoutMKI() ...@@ -122,22 +109,19 @@ void SdesNegotiatorTest::testKeyParamsPatternWithoutMKI()
{ {
DEBUG("-------------------- SdesNegotiatorTest::testKeyParamsPatternWithoutMKI --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::testKeyParamsPatternWithoutMKI --------------------\n");
std::string subject = "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj"; std::string subject("inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj");
pattern = new sfl::Pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \ sfl::Pattern pattern("(?P<srtpKeyMethod>inline|[A-Za-z0-9_]+)\\:" \
"(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)" \ "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)" \
"(\\|2\\^(?P<lifetime>[0-9]+)\\|" \ "(\\|2\\^(?P<lifetime>[0-9]+)\\|" \
"(?P<mkiValue>[0-9]+)\\:" \ "(?P<mkiValue>[0-9]+)\\:" \
"(?P<mkiLength>[0-9]{1,3})\\;?)?", "g"); "(?P<mkiLength>[0-9]{1,3})\\;?)?", "g");
*pattern << subject; pattern << subject;
pattern->matches(); pattern.matches();
CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); CPPUNIT_ASSERT(pattern.group("srtpKeyMethod").compare("inline:"));
CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") CPPUNIT_ASSERT(pattern.group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj")
== 0); == 0);
delete pattern;
pattern = NULL;
} }
...@@ -150,30 +134,19 @@ void SdesNegotiatorTest::testNegotiation() ...@@ -150,30 +134,19 @@ void SdesNegotiatorTest::testNegotiation()
DEBUG("-------------------- SdesNegotiatorTest::testNegotiation --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::testNegotiation --------------------\n");
// Add a new SDES crypto line to be processed. // Add a new SDES crypto line to be processed.
remoteOffer = new std::vector<std::string>(); std::vector<std::string> remoteOffer;
remoteOffer->push_back(std::string("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")); remoteOffer.push_back("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32");
remoteOffer->push_back(std::string("a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32")); remoteOffer.push_back("a=crypto:2 AES_CM_128_HMAC_SHA1_32 inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32");
// Register the local capabilities. // Register the local capabilities.
localCapabilities = new std::vector<sfl::CryptoSuiteDefinition>(); std::vector<sfl::CryptoSuiteDefinition> localCapabilities;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; ++i)
localCapabilities->push_back(sfl::CryptoSuites[i]); localCapabilities.push_back(sfl::CryptoSuites[i]);
}
sdesnego = new sfl::SdesNegotiator(*localCapabilities, *remoteOffer);
CPPUNIT_ASSERT(sdesnego->negotiate());
// CPPUNIT_ASSERT(sdesnego->getKeyInfo().compare("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd|2^20|1:32")==0);
delete remoteOffer; sfl::SdesNegotiator sdesnego(localCapabilities, remoteOffer);
remoteOffer = NULL;
delete localCapabilities; CPPUNIT_ASSERT(sdesnego.negotiate());
localCapabilities = NULL;
delete sdesnego;
sdesnego = NULL;
} }
/** /**
...@@ -184,25 +157,21 @@ void SdesNegotiatorTest::testComponent() ...@@ -184,25 +157,21 @@ void SdesNegotiatorTest::testComponent()
DEBUG("-------------------- SdesNegotiatorTest::testComponent --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::testComponent --------------------\n");
// Register the local capabilities. // Register the local capabilities.
std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); std::vector<sfl::CryptoSuiteDefinition> capabilities;
// Support all the CryptoSuites // Support all the CryptoSuites
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
capabilities->push_back(sfl::CryptoSuites[i]); capabilities.push_back(sfl::CryptoSuites[i]);
}
// Make sure that if a component is missing, negotiate will fail // Make sure that if a component is missing, negotiate will fail
std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:|2^20|1:32"); std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:|2^20|1:32");
std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); std::vector<std::string> cryptoOffer;
cryptoOffer->push_back(cryptoLine); cryptoOffer.push_back(cryptoLine);
sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); sfl::SdesNegotiator negotiator(capabilities, cryptoOffer);
CPPUNIT_ASSERT(!negotiator.negotiate());
CPPUNIT_ASSERT(negotiator->negotiate() == false);
} }
/** /**
* Make sure that most simple case does not fail. * Make sure that most simple case does not fail.
*/ */
...@@ -211,37 +180,28 @@ void SdesNegotiatorTest::testMostSimpleCase() ...@@ -211,37 +180,28 @@ void SdesNegotiatorTest::testMostSimpleCase()
DEBUG("-------------------- SdesNegotiatorTest::testMostSimpleCase --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::testMostSimpleCase --------------------\n");
// Register the local capabilities. // Register the local capabilities.
std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); std::vector<sfl::CryptoSuiteDefinition> capabilities;
// Support all the CryptoSuites // Support all the CryptoSuites
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
capabilities->push_back(sfl::CryptoSuites[i]); capabilities.push_back(sfl::CryptoSuites[i]);
}
// Make sure taht this case works (since it's default for most application) // Make sure taht this case works (since it's default for most application)
std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd");
std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); std::vector<std::string> cryptoOffer;
cryptoOffer->push_back(cryptoLine); cryptoOffer.push_back(cryptoLine);
sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer);
CPPUNIT_ASSERT(negotiator->negotiate() == true); sfl::SdesNegotiator negotiator(capabilities, cryptoOffer);
CPPUNIT_ASSERT(negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_80"); CPPUNIT_ASSERT(negotiator.negotiate());
CPPUNIT_ASSERT(negotiator->getKeyMethod() == "inline");
CPPUNIT_ASSERT(negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd");
CPPUNIT_ASSERT(negotiator->getLifeTime() == "");
CPPUNIT_ASSERT(negotiator->getMkiValue() == "");
CPPUNIT_ASSERT(negotiator->getMkiLength() == "");
CPPUNIT_ASSERT(negotiator->getAuthTagLength() == "80");
CPPUNIT_ASSERT(negotiator.getCryptoSuite() == "AES_CM_128_HMAC_SHA1_80");
delete capabilities; CPPUNIT_ASSERT(negotiator.getKeyMethod() == "inline");
capabilities = NULL; CPPUNIT_ASSERT(negotiator.getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd");
delete cryptoOffer; CPPUNIT_ASSERT(negotiator.getLifeTime().empty());
cryptoOffer = NULL; CPPUNIT_ASSERT(negotiator.getMkiValue().empty());
delete negotiator; CPPUNIT_ASSERT(negotiator.getMkiLength().empty());
negotiator = NULL; CPPUNIT_ASSERT(negotiator.getAuthTagLength() == "80");
} }
...@@ -250,34 +210,26 @@ void SdesNegotiatorTest::test32ByteKeyLength() ...@@ -250,34 +210,26 @@ void SdesNegotiatorTest::test32ByteKeyLength()
DEBUG("-------------------- SdesNegotiatorTest::test32ByteKeyLength --------------------\n"); DEBUG("-------------------- SdesNegotiatorTest::test32ByteKeyLength --------------------\n");
// Register the local capabilities. // Register the local capabilities.
std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); std::vector<sfl::CryptoSuiteDefinition> capabilities;
//Support all the CryptoSuites //Support all the CryptoSuites
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
capabilities->push_back(sfl::CryptoSuites[i]); capabilities.push_back(sfl::CryptoSuites[i]);
}
std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_32 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); std::string cryptoLine("a=crypto:1 AES_CM_128_HMAC_SHA1_32 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd");
std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); std::vector<std::string> cryptoOffer;
cryptoOffer->push_back(cryptoLine); cryptoOffer.push_back(cryptoLine);
sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator(*capabilities, *cryptoOffer); sfl::SdesNegotiator negotiator(capabilities, cryptoOffer);
CPPUNIT_ASSERT(negotiator->negotiate() == true); CPPUNIT_ASSERT(negotiator.negotiate());
CPPUNIT_ASSERT(negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_32"); CPPUNIT_ASSERT(negotiator.getCryptoSuite() == "AES_CM_128_HMAC_SHA1_32");
CPPUNIT_ASSERT(negotiator->getKeyMethod() == "inline"); CPPUNIT_ASSERT(negotiator.getKeyMethod() == "inline");
CPPUNIT_ASSERT(negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); CPPUNIT_ASSERT(negotiator.getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd");
CPPUNIT_ASSERT(negotiator->getLifeTime() == ""); CPPUNIT_ASSERT(negotiator.getLifeTime().empty());
CPPUNIT_ASSERT(negotiator->getMkiValue() == ""); CPPUNIT_ASSERT(negotiator.getMkiValue().empty());
CPPUNIT_ASSERT(negotiator->getMkiLength() == ""); CPPUNIT_ASSERT(negotiator.getMkiLength().empty());
CPPUNIT_ASSERT(negotiator->getAuthTagLength() == "32"); CPPUNIT_ASSERT(negotiator.getAuthTagLength() == "32");
delete capabilities;
capabilities = NULL;
delete cryptoOffer;
cryptoOffer = NULL;
delete negotiator;
negotiator = NULL;
} }
...@@ -80,8 +80,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase { ...@@ -80,8 +80,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase {
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
SdesNegotiatorTest();
/* /*
* Code factoring - Common resources can be released here. * Code factoring - Common resources can be released here.
* This method is called by unitcpp after each test * This method is called by unitcpp after each test
...@@ -103,14 +101,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase { ...@@ -103,14 +101,6 @@ class SdesNegotiatorTest : public CppUnit::TestCase {
void testMostSimpleCase(); void testMostSimpleCase();
void test32ByteKeyLength(); void test32ByteKeyLength();
private:
NON_COPYABLE(SdesNegotiatorTest);
sfl::Pattern *pattern;
sfl::SdesNegotiator *sdesnego;
std::vector<std::string> *remoteOffer;
std::vector<sfl::CryptoSuiteDefinition> *localCapabilities;
}; };
/* Register our test module */ /* Register our test module */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment