From d673ce95f865d8c9a21110941ebc4c9c037b3a67 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nicolas.pope@utu.fi>
Date: Thu, 12 May 2022 11:08:55 +0000
Subject: [PATCH] #19 Fix TLS and add test

---
 .gitignore               |  4 +++-
 src/protocol/factory.cpp |  1 +
 src/protocol/tls.cpp     |  2 ++
 src/protocol/tls.hpp     |  6 +++---
 test/CMakeLists.txt      | 13 ++++++++++++-
 test/webservice_e2e.cpp  | 25 +++++++++++++++++++++++++
 6 files changed, 46 insertions(+), 5 deletions(-)
 create mode 100644 test/webservice_e2e.cpp

diff --git a/.gitignore b/.gitignore
index 09a73bb..c5ca081 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,6 @@ build
 *.zip
 **/config.cpp
 **/config.h
-_CPack_Packages
\ No newline at end of file
+_CPack_Packages
+.vscode
+.env
\ No newline at end of file
diff --git a/src/protocol/factory.cpp b/src/protocol/factory.cpp
index 1570810..e966edb 100644
--- a/src/protocol/factory.cpp
+++ b/src/protocol/factory.cpp
@@ -1,6 +1,7 @@
 #include <loguru.hpp>
 
 #include <ftl/exception.hpp>
+#include <ftl/protocol/config.h>
 
 #include "connection.hpp"
 #include "tcp.hpp"
diff --git a/src/protocol/tls.cpp b/src/protocol/tls.cpp
index ed59ba5..4217500 100644
--- a/src/protocol/tls.cpp
+++ b/src/protocol/tls.cpp
@@ -6,8 +6,10 @@
 #include <iomanip>
 
 #include <ftl/exception.hpp>
+#include <ftl/lib/loguru.hpp>
 
 using ftl::net::internal::Connection_TLS;
+using uchar = unsigned char;
 
 /** get basic certificate info: Distinguished Name (DN), issuer DN,
  *  certificate fingerprint */
diff --git a/src/protocol/tls.hpp b/src/protocol/tls.hpp
index 75aadf2..65cad60 100644
--- a/src/protocol/tls.hpp
+++ b/src/protocol/tls.hpp
@@ -1,5 +1,6 @@
-#ifndef _FTL_NET_TLS_HPP_
-#define _FTL_NET_TLS_HPP_
+#pragma once
+
+#include <ftl/protocol/config.h>
 
 #ifdef HAVE_GNUTLS
 
@@ -44,4 +45,3 @@ private:
 }
 
 #endif // HAVE_GNUTLS
-#endif // _FTL_NET_TLS_HPP_
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 578543c..c7dc751 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -81,4 +81,15 @@ target_include_directories(stream_integration PUBLIC "${CMAKE_CURRENT_SOURCE_DIR
 target_link_libraries(stream_integration
 	beyond-protocol GnuTLS::GnuTLS Threads::Threads ${URIPARSER_LIBRARIES} ${UUID_LIBRARIES} ${OS_LIBS})
 
-add_test(StreamIntegrationTest stream_integration)
\ No newline at end of file
+add_test(StreamIntegrationTest stream_integration)
+
+### Webservice E2E #############################################################
+add_executable(webservice_e2e
+	$<TARGET_OBJECTS:CatchTestFTL>
+	./webservice_e2e.cpp
+)
+target_include_directories(webservice_e2e PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include")
+target_link_libraries(webservice_e2e
+	beyond-protocol GnuTLS::GnuTLS Threads::Threads ${URIPARSER_LIBRARIES} ${UUID_LIBRARIES} ${OS_LIBS})
+
+add_test(WebserviceE2ETest webservice_e2e)
\ No newline at end of file
diff --git a/test/webservice_e2e.cpp b/test/webservice_e2e.cpp
new file mode 100644
index 0000000..722b281
--- /dev/null
+++ b/test/webservice_e2e.cpp
@@ -0,0 +1,25 @@
+#include "catch.hpp"
+#include <ftl/protocol.hpp>
+#include <ftl/protocol/self.hpp>
+#include <ftl/protocol/node.hpp>
+#include <ftl/uri.hpp>
+
+// --- Tests -------------------------------------------------------------------
+
+TEST_CASE("Webservice connection", "[net]") {
+	SECTION("connect using secure websocket") {
+		std::string uri;
+        if(const char* env_p = std::getenv("FTL_WEBSERVICE_URI")) {
+            uri = std::string(env_p);
+        } else {
+            return;
+        }
+
+		auto p = ftl::connectNode(uri);
+		REQUIRE( p );
+		
+		REQUIRE( p->waitConnection(5) );
+	}
+
+	ftl::protocol::reset();
+}
-- 
GitLab