summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-10 07:30:52 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-10 07:30:52 (GMT)
commit896e2a121d58931740ea8becc0544e10e629c6c5 (patch)
treea5e0c748ff472357dfbde89292eccac08900cee9 /Swiften/QA
parentafae15f7cf212c993da8264a4ae89cf8729b3f86 (diff)
downloadswift-contrib-896e2a121d58931740ea8becc0544e10e629c6c5.zip
swift-contrib-896e2a121d58931740ea8becc0544e10e629c6c5.tar.bz2
Refactored TLS tests.
Diffstat (limited to 'Swiften/QA')
-rw-r--r--Swiften/QA/OpenSSLTest/.gitignore1
-rw-r--r--Swiften/QA/OpenSSLTest/OpenSSLCertificateTest.cpp56
-rw-r--r--Swiften/QA/SConscript6
-rw-r--r--Swiften/QA/TLSTest/.gitignore1
-rw-r--r--Swiften/QA/TLSTest/CertificateTest.cpp96
-rw-r--r--Swiften/QA/TLSTest/SConscript (renamed from Swiften/QA/OpenSSLTest/SConscript)10
-rw-r--r--Swiften/QA/TLSTest/jabber_org.crt (renamed from Swiften/QA/OpenSSLTest/jabber_org.crt)bin2081 -> 2081 bytes
7 files changed, 105 insertions, 65 deletions
diff --git a/Swiften/QA/OpenSSLTest/.gitignore b/Swiften/QA/OpenSSLTest/.gitignore
deleted file mode 100644
index 27154e7..0000000
--- a/Swiften/QA/OpenSSLTest/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-OpenSSLTest
diff --git a/Swiften/QA/OpenSSLTest/OpenSSLCertificateTest.cpp b/Swiften/QA/OpenSSLTest/OpenSSLCertificateTest.cpp
deleted file mode 100644
index 59aee47..0000000
--- a/Swiften/QA/OpenSSLTest/OpenSSLCertificateTest.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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/OpenSSL/OpenSSLCertificate.h"
-#include "SwifTools/Application/PlatformApplicationPathProvider.h"
-
-using namespace Swift;
-
-class OpenSSLCertificateTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(OpenSSLCertificateTest);
- CPPUNIT_TEST(testConstructFromDER);
- CPPUNIT_TEST(testToDER);
- CPPUNIT_TEST(testGetSubjectName);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void setUp() {
- pathProvider = new PlatformApplicationPathProvider("FileReadBytestreamTest");
- certificateData.readFromFile((pathProvider->getExecutableDir() / "jabber_org.crt").string());
- }
-
- void tearDown() {
- delete pathProvider;
- }
-
- void testConstructFromDER() {
- OpenSSLCertificate testling(certificateData);
-
- CPPUNIT_ASSERT_EQUAL(String("*.jabber.org"), testling.getCommonNames()[0]);
- }
-
- void testToDER() {
- OpenSSLCertificate testling(certificateData);
-
- CPPUNIT_ASSERT_EQUAL(certificateData, testling.toDER());
- }
-
- void testGetSubjectName() {
- OpenSSLCertificate testling(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());
- }
-
- private:
- PlatformApplicationPathProvider* pathProvider;
- ByteArray certificateData;
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(OpenSSLCertificateTest);
diff --git a/Swiften/QA/SConscript b/Swiften/QA/SConscript
index 97b6ed0..b885909 100644
--- a/Swiften/QA/SConscript
+++ b/Swiften/QA/SConscript
@@ -6,7 +6,5 @@ SConscript(dirs = [
"ClientTest",
# "DNSSDTest",
"StorageTest",
- ])
-
-if swiften_env.get("HAVE_OPENSSL", False) :
- SConscript(dirs = ["OpenSSLTest"])
+ "TLSTest",
+ ]) \ No newline at end of file
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/OpenSSLTest/SConscript b/Swiften/QA/TLSTest/SConscript
index a3309f2..034336e 100644
--- a/Swiften/QA/OpenSSLTest/SConscript
+++ b/Swiften/QA/TLSTest/SConscript
@@ -10,9 +10,11 @@ if env["TEST"] :
myenv.MergeFlags(myenv["CPPUNIT_FLAGS"])
myenv.MergeFlags(myenv["BOOST_FLAGS"])
myenv.MergeFlags(myenv["LIBIDN_FLAGS"])
- myenv.MergeFlags(myenv["OPENSSL_FLAGS"])
-
- tester = myenv.Program("OpenSSLTest", [
- "OpenSSLCertificateTest.cpp",
+ 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/OpenSSLTest/jabber_org.crt b/Swiften/QA/TLSTest/jabber_org.crt
index 5a9ddaa..5a9ddaa 100644
--- a/Swiften/QA/OpenSSLTest/jabber_org.crt
+++ b/Swiften/QA/TLSTest/jabber_org.crt
Binary files differ