Skip to content
Snippets Groups Projects
Verified Commit a305c136 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: retrieve simple entity

parent 20f979b4
Branches
Tags
No related merge requests found
Pipeline #9994 failed
......@@ -49,3 +49,14 @@ add_compile_options(-Wno-unused-parameter -Wno-unused-result -g)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
enable_testing()
add_subdirectory(test)
#######################################################
### code formatting with clang-format
#######################################################
option(AUTOFORMATTING "call clang-format at configure time" ON)
if(AUTOFORMATTING)
file(GLOB format_test_sources test/*.cpp test/*.h)
execute_process(COMMAND clang-format -i --verbose ${format_test_sources}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif()
......@@ -2,6 +2,14 @@
Integration tests for caosdb-cpplib and the caosdb-server
# Dependencies
* clang-tidy
* clang-format
* include-what-you-use
* cmake
* conan
# Run tests
1. `mkdir build && cd build/`
......
......@@ -23,6 +23,7 @@
#######################################################################
set(test_cases
test_connection
test_transaction
)
#######################################################
......
......@@ -31,18 +31,18 @@
* @author Timm Fitschen
* @date 2021-07-07
*/
#define EXPECT_THROW_MESSAGE(statement, exeption_type, message) EXPECT_THROW( \
try { \
statement; \
} catch (const exeption_type& e) { \
#define EXPECT_THROW_MESSAGE(statement, exeption_type, message) \
EXPECT_THROW( \
try { statement; } catch (const exeption_type &e) { \
EXPECT_EQ(std::string(e.what()), message); \
throw; \
}, exeption_type)
#define ASSERT_THROW_MESSAGE(statement, exeption_type, message) ASSERT_THROW( \
try { \
statement; \
} catch (const exeption_type& e) { \
}, \
exeption_type)
#define ASSERT_THROW_MESSAGE(statement, exeption_type, message) \
ASSERT_THROW( \
try { statement; } catch (const exeption_type &e) { \
ASSERT_EQ(std::string(e.what()), message); \
throw; \
}, exeption_type)
}, \
exeption_type)
#endif
......@@ -29,11 +29,12 @@
#include "caosdb/info.h" // for VersionInfo
#include "caosdb/utils.h" // for get_env_var
#include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ, EXPECT_THROW
#include "caosdb_test_utility.h"
namespace caosdb::connection {
using caosdb::authentication::PlainPasswordAuthenticator;
using caosdb::exceptions::AuthenticationError;
using caosdb::exceptions::ConnectionError;
using caosdb::authentication::PlainPasswordAuthenticator;
TEST(test_connection, config_somehost_25323) {
auto port = 25323;
......@@ -53,26 +54,12 @@ TEST(test_connection, connect_somehost_42347_fails) {
EXPECT_THROW(connection.GetVersionInfo(), ConnectionError);
}
TEST(test_connection, connection_insecure_authentication_error_wrong_credentials) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto *const user = "not-a-user-23461237";
const auto *const password = "very-c-cred";
auto auth = std::make_shared<PlainPasswordAuthenticator>(user, password);
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port, auth);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
}
TEST(test_connection, connection_insecure_authentication_error_anonymous) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port_str =
caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto host =
caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port);
auto connection = CaosDBConnection(config);
......@@ -81,39 +68,52 @@ TEST(test_connection, connection_insecure_authentication_error_anonymous) {
}
TEST(test_connection, connection_ssl_authentication_error_anonymous) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port_str =
caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path = caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto host =
caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path =
caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
auto ssloptions = std::make_shared<PemFileCACertProvider>(path);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions);
auto config =
std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
EXPECT_THROW_MESSAGE(connection.GetVersionInfo(), AuthenticationError,
"Please Login.");
}
TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port_str =
caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path = caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto host =
caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path =
caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto *const user = "not-a-user-23461237";
const auto *const password = "very-c-cred";
auto auth = std::make_shared<PlainPasswordAuthenticator>(user, password);
auto ssloptions = std::make_shared<PemFileCACertProvider>(path);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions, auth);
auto config =
std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions, auth);
auto connection = CaosDBConnection(config);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
EXPECT_THROW_MESSAGE(connection.GetVersionInfo(), AuthenticationError,
"Authentication failed. Username or password wrong.");
}
TEST(test_connection, connection_ssl_authentication_success) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port_str =
caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path = caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto host =
caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto path =
caosdb::utils::get_env_var("CAOSDB_SERVER_CA_PEM", std::string());
const auto user = caosdb::utils::get_env_var("CAOSDB_USER", "admin");
const auto password = caosdb::utils::get_env_var("CAOSDB_PASSWORD", "caosdb");
......@@ -123,7 +123,8 @@ TEST(test_connection, connection_ssl_authentication_success) {
auto auth = std::make_shared<PlainPasswordAuthenticator>(user, password);
auto ssloptions = std::make_shared<PemFileCACertProvider>(path);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions, auth);
auto config =
std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions, auth);
auto connection = CaosDBConnection(config);
auto v_info = connection.GetVersionInfo();
......
......@@ -18,30 +18,36 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "caosdb/transaction.h"
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartResult
#include <memory> // for make_shared, allocator, shared_ptr
#include <string> // for string
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl
#include <memory> // for allocator, make_shared, static_po...
#include <string> // for stoi
#include "caosdb/authentication.h" // for PlainPasswordAuthenticator
#include "caosdb/connection.h" // for InsecureCaosDBConnectionConfig
#include "caosdb/exceptions.h" // for AuthenticationError, ConnectionError
#include "caosdb/entity.h" // for Entity, EntityID
#include "caosdb/transaction.h" // for Transaction, UniqueResult, Entity
#include "caosdb/utils.h" // for get_env_var
#include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ, EXPECT_THROW
#include "gtest/gtest_pred_impl.h" // for Test, TestInfo, EXPECT_EQ, TEST
namespace caosdb::transaction {
using caosdb::authentication::PlainPasswordAuthenticator;
using caosdb::connection::CaosDBConnection;
using caosdb::connection::InsecureCaosDBConnectionConfig;
TEST(test_transaction, first_test) {
auto port_str = caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port_str =
caosdb::utils::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
auto port = std::stoi(port_str);
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto host =
caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
const auto user = caosdb::utils::get_env_var("CAOSDB_USER", "admin");
const auto password = caosdb::utils::get_env_var("CAOSDB_PASSWORD", "caosdb");
const auto *const description = "This is an entity";
auto auth = std::make_shared<PlainPasswordAuthenticator>(user, password);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, auth);
auto config =
std::make_shared<InsecureCaosDBConnectionConfig>(host, port, auth);
auto connection = CaosDBConnection(config);
auto transaction(connection.CreateTransaction());
......@@ -53,4 +59,4 @@ TEST(test_transaction, first_test) {
EXPECT_EQ(description, result_set->GetEntity().GetDescription());
}
} //namespace caosdb::connection
} // namespace caosdb::transaction
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment