From d4bc79b6a1ac9b17de9c4c51c5d246a5f394eb7a Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Thu, 7 Nov 2024 06:15:30 -0500 Subject: [PATCH 1/6] created initial test case for globus api --- core/server/tests/unit/CMakeLists.txt | 1 + core/server/tests/unit/test_GlobusAPI.cpp | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 core/server/tests/unit/test_GlobusAPI.cpp diff --git a/core/server/tests/unit/CMakeLists.txt b/core/server/tests/unit/CMakeLists.txt index 3c46fb112..b4f2fabe5 100644 --- a/core/server/tests/unit/CMakeLists.txt +++ b/core/server/tests/unit/CMakeLists.txt @@ -2,6 +2,7 @@ foreach(PROG test_AuthMap test_AuthenticationManager + test_GlobusAPI ) file(GLOB ${PROG}_SOURCES ${PROG}*.cpp) diff --git a/core/server/tests/unit/test_GlobusAPI.cpp b/core/server/tests/unit/test_GlobusAPI.cpp new file mode 100644 index 000000000..db43cb87d --- /dev/null +++ b/core/server/tests/unit/test_GlobusAPI.cpp @@ -0,0 +1,28 @@ +#define BOOST_TEST_MAIN + +#define BOOST_TEST_MODULE globusapi + +// Local includes + +// Third party includes +#include +#include +#include + +// Standard includes +#include +#include + +using namespace SDMS::Core; + +BOOST_AUTO_TEST_SUITE(GlobusAPITest) + +BOOST_AUTO_TEST_CASE(testing_GlobusAPIPost) { + BOOST_TEST(true); +} + +BOOST_AUTO_TEST_CASE(testing_GlobusAPIGet) { + BOOST_TEST(true); +} + +BOOST_AUTO_TEST_SUITE_END() From 2a4d6f8d339d175cfe195d4348308070ac9984fd Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Thu, 7 Nov 2024 06:05:41 -0500 Subject: [PATCH 2/6] created a test class header for globus api --- core/server/GlobusAPI.hpp | 6 +++-- core/server/TestGlobusAPI.hpp | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 core/server/TestGlobusAPI.hpp diff --git a/core/server/GlobusAPI.hpp b/core/server/GlobusAPI.hpp index c571a1e4a..87682d271 100644 --- a/core/server/GlobusAPI.hpp +++ b/core/server/GlobusAPI.hpp @@ -67,8 +67,7 @@ class GlobusAPI { void refreshAccessToken(const std::string &a_ref_tok, std::string &a_new_acc_tok, uint32_t &a_expires_in); -private: - void init(); +protected: long get(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector> &a_params, @@ -77,6 +76,9 @@ class GlobusAPI { const std::string &a_url_path, const std::string &a_token, const std::vector> &a_params, const libjson::Value *a_body, std::string &a_result); + +private: + void init(); std::string getSubmissionID(const std::string &a_acc_token); bool eventsHaveErrors(const std::vector &a_events, XfrStatus &status, std::string &a_err_msg); diff --git a/core/server/TestGlobusAPI.hpp b/core/server/TestGlobusAPI.hpp new file mode 100644 index 000000000..fd72fdf82 --- /dev/null +++ b/core/server/TestGlobusAPI.hpp @@ -0,0 +1,43 @@ +#ifndef TESTGLOBUSAPICLIENT_HPP +#define TESTGLOBUSAPICLIENT_HPP +#pragma once + +// Local private includes +#include "GlobusAPI.hpp" + +// Local public includes +#include "common/DynaLog.hpp" +#include "common/SDMS.pb.h" +#include "common/libjson.hpp" + +// Third party includes +#include + +// Standard includes +#include +#include + +namespace SDMS { +namespace Core { + +class TestGlobusAPI: GlobusAPI { + TestGlobusAPI(); + explicit TestGlobusAPI(LogContext log_context); + + ~TestGlobusAPI(); + +public: + long get(CURL *a_curl, const std::string &a_base_url, + const std::string &a_url_path, const std::string &a_token, + const std::vector> &a_params, + std::string &a_result); + long post(CURL *a_curl, const std::string &a_base_url, + const std::string &a_url_path, const std::string &a_token, + const std::vector> &a_params, + const libjson::Value *a_body, std::string &a_result); +}; + +} // namespace Core +} // namespace SDMS + +#endif From a81f6b5a01b5a49aa95ebf687ce57dbf6b5f2fc8 Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Mon, 11 Nov 2024 05:56:05 -0500 Subject: [PATCH 3/6] moved test class definition into test file --- core/server/TestGlobusAPI.hpp | 43 ----------------------- core/server/tests/unit/test_GlobusAPI.cpp | 27 +++++++++++++- 2 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 core/server/TestGlobusAPI.hpp diff --git a/core/server/TestGlobusAPI.hpp b/core/server/TestGlobusAPI.hpp deleted file mode 100644 index fd72fdf82..000000000 --- a/core/server/TestGlobusAPI.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef TESTGLOBUSAPICLIENT_HPP -#define TESTGLOBUSAPICLIENT_HPP -#pragma once - -// Local private includes -#include "GlobusAPI.hpp" - -// Local public includes -#include "common/DynaLog.hpp" -#include "common/SDMS.pb.h" -#include "common/libjson.hpp" - -// Third party includes -#include - -// Standard includes -#include -#include - -namespace SDMS { -namespace Core { - -class TestGlobusAPI: GlobusAPI { - TestGlobusAPI(); - explicit TestGlobusAPI(LogContext log_context); - - ~TestGlobusAPI(); - -public: - long get(CURL *a_curl, const std::string &a_base_url, - const std::string &a_url_path, const std::string &a_token, - const std::vector> &a_params, - std::string &a_result); - long post(CURL *a_curl, const std::string &a_base_url, - const std::string &a_url_path, const std::string &a_token, - const std::vector> &a_params, - const libjson::Value *a_body, std::string &a_result); -}; - -} // namespace Core -} // namespace SDMS - -#endif diff --git a/core/server/tests/unit/test_GlobusAPI.cpp b/core/server/tests/unit/test_GlobusAPI.cpp index db43cb87d..e1c8a1b9a 100644 --- a/core/server/tests/unit/test_GlobusAPI.cpp +++ b/core/server/tests/unit/test_GlobusAPI.cpp @@ -2,19 +2,44 @@ #define BOOST_TEST_MODULE globusapi -// Local includes +// Local private includes +#include "GlobusAPI.hpp" + +// Local public includes +#include "common/DynaLog.hpp" +#include "common/libjson.hpp" // Third party includes +#include #include #include #include // Standard includes +#include +#include #include #include using namespace SDMS::Core; +class TestGlobusAPI: public GlobusAPI { +public: + TestGlobusAPI(); + explicit TestGlobusAPI(LogContext log_context); + + ~TestGlobusAPI(); + + long get(CURL *a_curl, const std::string &a_base_url, + const std::string &a_url_path, const std::string &a_token, + const std::vector> &a_params, + std::string &a_result); + long post(CURL *a_curl, const std::string &a_base_url, + const std::string &a_url_path, const std::string &a_token, + const std::vector> &a_params, + const libjson::Value *a_body, std::string &a_result); +}; + BOOST_AUTO_TEST_SUITE(GlobusAPITest) BOOST_AUTO_TEST_CASE(testing_GlobusAPIPost) { From deecc353a2a3edebdfd5734d2029b7f21ecc3d59 Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Tue, 12 Nov 2024 05:00:36 -0500 Subject: [PATCH 4/6] added function definitions and initial per test case setup --- core/server/tests/unit/test_GlobusAPI.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/server/tests/unit/test_GlobusAPI.cpp b/core/server/tests/unit/test_GlobusAPI.cpp index e1c8a1b9a..ca58dfbce 100644 --- a/core/server/tests/unit/test_GlobusAPI.cpp +++ b/core/server/tests/unit/test_GlobusAPI.cpp @@ -4,6 +4,7 @@ // Local private includes #include "GlobusAPI.hpp" +#include "Config.hpp" // Local public includes #include "common/DynaLog.hpp" @@ -25,28 +26,38 @@ using namespace SDMS::Core; class TestGlobusAPI: public GlobusAPI { public: - TestGlobusAPI(); - explicit TestGlobusAPI(LogContext log_context); + TestGlobusAPI() { + GlobusAPI::init() + } - ~TestGlobusAPI(); + ~TestGlobusAPI() {} long get(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector> &a_params, - std::string &a_result); + std::string &a_result) { + return GlobusAPI::get(a_curl, a_base_url, a_url_path, a_token, a_params, a_result); + } + long post(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, const std::vector> &a_params, - const libjson::Value *a_body, std::string &a_result); + const libjson::Value *a_body, std::string &a_result) { + return GlobusAPI::post(a_curl, a_base_url, a_url_path, a_token, a_params, a_body, a_result); + } }; BOOST_AUTO_TEST_SUITE(GlobusAPITest) BOOST_AUTO_TEST_CASE(testing_GlobusAPIPost) { + Config config = Config::getInstance(); + TestGlobusAPI api(); BOOST_TEST(true); } BOOST_AUTO_TEST_CASE(testing_GlobusAPIGet) { + Config config = Config::getInstance(); + TestGlobusAPI api(); BOOST_TEST(true); } From f1714b881e5219188ac5453049ee3d79f9dad35c Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Mon, 18 Nov 2024 06:31:20 -0500 Subject: [PATCH 5/6] finished tests --- core/server/GlobusAPI.hpp | 4 +-- core/server/tests/unit/test_GlobusAPI.cpp | 44 ++++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/core/server/GlobusAPI.hpp b/core/server/GlobusAPI.hpp index 87682d271..f0dd71cee 100644 --- a/core/server/GlobusAPI.hpp +++ b/core/server/GlobusAPI.hpp @@ -77,14 +77,14 @@ class GlobusAPI { const std::vector> &a_params, const libjson::Value *a_body, std::string &a_result); + Config &m_config; + private: void init(); std::string getSubmissionID(const std::string &a_acc_token); bool eventsHaveErrors(const std::vector &a_events, XfrStatus &status, std::string &a_err_msg); void checkResponsCode(long a_code, libjson::Value::Object &a_body) const; - - Config &m_config; CURL *m_curl_xfr; CURL *m_curl_auth; LogContext m_log_context; diff --git a/core/server/tests/unit/test_GlobusAPI.cpp b/core/server/tests/unit/test_GlobusAPI.cpp index ca58dfbce..fcf2faa74 100644 --- a/core/server/tests/unit/test_GlobusAPI.cpp +++ b/core/server/tests/unit/test_GlobusAPI.cpp @@ -4,7 +4,7 @@ // Local private includes #include "GlobusAPI.hpp" -#include "Config.hpp" +// #include "Config.hpp" // Local public includes #include "common/DynaLog.hpp" @@ -22,15 +22,18 @@ #include #include +using namespace libjson; using namespace SDMS::Core; class TestGlobusAPI: public GlobusAPI { public: - TestGlobusAPI() { - GlobusAPI::init() - } + TestGlobusAPI() {} ~TestGlobusAPI() {} + + void setupConfig() { + + } long get(CURL *a_curl, const std::string &a_base_url, const std::string &a_url_path, const std::string &a_token, @@ -47,17 +50,42 @@ class TestGlobusAPI: public GlobusAPI { } }; +CURL* curl_setup() { + CURL* m_curl = curl_easy_init(); + if (!m_curl) + EXCEPT(1, "libcurl init failed"); + + curl_easy_setopt(m_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); + // curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlResponseWriteCB); + curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(m_curl, CURLOPT_TCP_NODELAY, 1); +} + BOOST_AUTO_TEST_SUITE(GlobusAPITest) BOOST_AUTO_TEST_CASE(testing_GlobusAPIPost) { - Config config = Config::getInstance(); - TestGlobusAPI api(); + TestGlobusAPI api; + api.setupConfig(); + CURL* m_curl = curl_setup(); + Value body; + Value::Object &body_o = body.initObject(); + body_o["username"] = "admin"; + body_o["password"] = "password123"; + std::string res; + + api.post(m_curl, "https://restful-booker.herokuapp.com/", "auth", "", {{"field","test"}}, &body, res); + BOOST_TEST(true); } BOOST_AUTO_TEST_CASE(testing_GlobusAPIGet) { - Config config = Config::getInstance(); - TestGlobusAPI api(); + TestGlobusAPI api; + api.setupConfig(); + CURL* m_curl = curl_setup(); + std::string res; + + api.get(m_curl, "https://restful-booker.herokuapp.com/", "booking", "authtoken", {{"field","test"}}, res); + BOOST_TEST(true); } From f9187414d463df1048115f1eb5b4d205b56e100c Mon Sep 17 00:00:00 2001 From: Blake Nedved Date: Thu, 21 Nov 2024 06:49:51 -0500 Subject: [PATCH 6/6] added missing curl method --- core/server/tests/unit/test_GlobusAPI.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/server/tests/unit/test_GlobusAPI.cpp b/core/server/tests/unit/test_GlobusAPI.cpp index fcf2faa74..7717308e8 100644 --- a/core/server/tests/unit/test_GlobusAPI.cpp +++ b/core/server/tests/unit/test_GlobusAPI.cpp @@ -9,6 +9,7 @@ // Local public includes #include "common/DynaLog.hpp" #include "common/libjson.hpp" +#include "common/Util.hpp" // Third party includes #include @@ -56,7 +57,7 @@ CURL* curl_setup() { EXCEPT(1, "libcurl init failed"); curl_easy_setopt(m_curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - // curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlResponseWriteCB); + curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlResponseWriteCB); curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(m_curl, CURLOPT_TCP_NODELAY, 1); }