diff options
Diffstat (limited to 'Swiften/QA/TLSTest')
-rw-r--r-- | Swiften/QA/TLSTest/.gitignore | 1 | ||||
-rw-r--r-- | Swiften/QA/TLSTest/CertificateTest.cpp | 96 | ||||
-rw-r--r-- | Swiften/QA/TLSTest/SConscript | 20 | ||||
-rw-r--r-- | Swiften/QA/TLSTest/jabber_org.crt | bin | 0 -> 2081 bytes |
4 files changed, 117 insertions, 0 deletions
diff --git a/Swiften/QA/TLSTest/.gitignore b/Swiften/QA/TLSTest/.gitignore new file mode 100644 index 0000000..1ef40d7 --- /dev/null +++ b/Swiften/QA/TLSTest/.gitignore @@ -0,0 +1 @@ +TLSTest diff --git a/Swiften/QA/TLSTest/CertificateTest.cpp b/Swiften/QA/TLSTest/CertificateTest.cpp new file mode 100644 index 0000000..627887c --- /dev/null +++ b/Swiften/QA/TLSTest/CertificateTest.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <boost/bind.hpp> + +#include "Swiften/TLS/CertificateFactory.h" +#include "SwifTools/Application/PlatformApplicationPathProvider.h" + +using namespace Swift; + +template<typename CERTIFICATE_FACTORY> +class CertificateTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(CertificateTest); + CPPUNIT_TEST(testConstructFromDER); + CPPUNIT_TEST(testToDER); + CPPUNIT_TEST(testGetSubjectName); + CPPUNIT_TEST(testGetCommonNames); + CPPUNIT_TEST(testGetSRVNames); + CPPUNIT_TEST(testGetDNSNames); + CPPUNIT_TEST(testGetXMPPAddresses); + CPPUNIT_TEST_SUITE_END(); + + public: + void setUp() { + pathProvider = new PlatformApplicationPathProvider("FileReadBytestreamTest"); + certificateData.readFromFile((pathProvider->getExecutableDir() / "jabber_org.crt").string()); + certificateFactory = new CERTIFICATE_FACTORY(); + } + + void tearDown() { + delete certificateFactory; + delete pathProvider; + } + + void testConstructFromDER() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling->getCommonNames()[0]); + } + + void testToDER() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(certificateData, testling->toDER()); + } + + void testGetSubjectName() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(String("/description=114072-VMk8pdi1aj5kTXxO/C=US/ST=Colorado/L=Denver/O=Peter Saint-Andre/OU=StartCom Trusted Certificate Member/CN=*.jabber.org/emailAddress=hostmaster@jabber.org"), testling->getSubjectName()); + } + + void testGetCommonNames() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling->getCommonNames().size())); + CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling->getCommonNames()[0]); + } + + void testGetSRVNames() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling->getSRVNames().size())); + CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling->getSRVNames()[0]); + } + + void testGetDNSNames() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(testling->getDNSNames().size())); + CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling->getDNSNames()[0]); + CPPUNIT_ASSERT_EQUAL(String("jabber.org"), testling->getDNSNames()[1]); + } + + void testGetXMPPAddresses() { + Certificate::ref testling = certificateFactory->createCertificateFromDER(certificateData); + + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(testling->getXMPPAddresses().size())); + CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling->getXMPPAddresses()[0]); + } + + private: + PlatformApplicationPathProvider* pathProvider; + ByteArray certificateData; + CertificateFactory* certificateFactory; +}; + +#ifdef HAVE_OPENSSL +#include "Swiften/TLS/OpenSSL/OpenSSLCertificateFactory.h" +CPPUNIT_TEST_SUITE_REGISTRATION(CertificateTest<OpenSSLCertificateFactory>); +#endif diff --git a/Swiften/QA/TLSTest/SConscript b/Swiften/QA/TLSTest/SConscript new file mode 100644 index 0000000..034336e --- /dev/null +++ b/Swiften/QA/TLSTest/SConscript @@ -0,0 +1,20 @@ +import os + +Import("env") + +if env["TEST"] : + myenv = env.Clone() + myenv.MergeFlags(myenv["CHECKER_FLAGS"]) + myenv.MergeFlags(myenv["SWIFTOOLS_FLAGS"]) + myenv.MergeFlags(myenv["SWIFTEN_FLAGS"]) + myenv.MergeFlags(myenv["CPPUNIT_FLAGS"]) + myenv.MergeFlags(myenv["BOOST_FLAGS"]) + myenv.MergeFlags(myenv["LIBIDN_FLAGS"]) + if myenv.get("HAVE_OPENSSL") : + myenv.MergeFlags(myenv["OPENSSL_FLAGS"]) + myenv.Append(CPPDEFINES = ["HAVE_OPENSSL"]) + + tester = myenv.Program("TLSTest", [ + "CertificateTest.cpp", + ]) + myenv.Test(tester, "system") diff --git a/Swiften/QA/TLSTest/jabber_org.crt b/Swiften/QA/TLSTest/jabber_org.crt Binary files differnew file mode 100644 index 0000000..5a9ddaa --- /dev/null +++ b/Swiften/QA/TLSTest/jabber_org.crt |