diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 47cacfaf867e18c7ecfa8629e0d31cc00d5edf9c..a0d975f82b721dd71cc1e4f7e724c47c20e28a55 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -13,6 +13,8 @@ COPY . /caosdb-cppinttest WORKDIR /caosdb-cppinttest RUN rm -rf .git +COPY .docker/caosdb-client.json /caosdb-client.json + # build and run tests CMD mkdir build && \ cd build && \ diff --git a/.docker/caosdb-client.json b/.docker/caosdb-client.json new file mode 100644 index 0000000000000000000000000000000000000000..5da162e2561da384892fc62e02f2fdaddad2e6aa --- /dev/null +++ b/.docker/caosdb-client.json @@ -0,0 +1,14 @@ +{ + "connections": { + "default": { + "host": "caosdb-server", + "port": 8443, + "server_certificate_path": "/cert/caosdb.cert.pem", + "authentication": { + "type": "plain", + "username": "admin", + "password": "caosdb" + } + } + } +} diff --git a/.docker/tester.yml b/.docker/tester.yml index f801f421f2cfb179da86f69cd5bc58d312f48882..dc88a13e8e89ef99d7a4ff37e819dbf9bc6dbd37 100644 --- a/.docker/tester.yml +++ b/.docker/tester.yml @@ -3,8 +3,7 @@ services: tester: image: "$CPPINTTEST_REGISTRY_IMAGE" environment: - CAOSDB_SERVER_HOST: caosdb-server - CAOSDB_SERVER_CERT: /cert/caosdb.cert.pem + CAOSDB_CLIENT_CONFIGURATION: /caosdb-client.json networks: - docker_caosnet volumes: diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 7039a6096af1e7337209fafa5c5d8705edea9726..7909ab8830cad441e40fb3b782b35e06f9eb3f1b 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -17,26 +17,25 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <memory> // for allocator, unique_ptr -#include "ccaosdb.h" // for caosdb_connection_create_connection -#include "gtest/gtest.h" // for Test, SuiteApiResolver, TestInfo, TEST -#include "test_connection.h" // for create_test_connection_config +#include <memory> // for allocator, unique_ptr +#include "ccaosdb.h" // for caosdb_info_version_info, caosdb_... +#include "gtest/gtest-message.h" // for Message +#include "gtest/gtest-test-part.h" // for TestPartResult +#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, SuiteApiResolver TEST(test_ccaosdb, connection_ssl_authentication_success) { - caosdb_connection_connection_configuration config; - auto wrapped = caosdb::connection::create_test_connection_config(); - config.wrapped_connection_configuration = wrapped.get(); caosdb_connection_connection connection; - caosdb_connection_create_connection(&connection, &config); + caosdb_connection_connection_manager_get_default_connection(&connection); caosdb_info_version_info version_info; caosdb_connection_get_version_info(&version_info, &connection); auto major = caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR(); auto minor = caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR(); - const auto *const pre_release = caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); + const auto *const pre_release = + caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); EXPECT_EQ(major, version_info.major); EXPECT_EQ(minor, version_info.minor); diff --git a/test/test_connection.cpp b/test/test_connection.cpp index f09d6b071802d26b21de1db46e23a2582ec86db1..b69719768e3e4fad2b9d40d87549c7fc70d0020b 100644 --- a/test/test_connection.cpp +++ b/test/test_connection.cpp @@ -29,7 +29,6 @@ #include "caosdb/utility.h" // for get_env_var #include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ, EXPECT_THROW #include "caosdb_test_utility.h" -#include "test_connection.h" #include "caosdb/constants.h" namespace caosdb::connection { @@ -106,7 +105,7 @@ TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) { } TEST(test_connection, connection_ssl_authentication_success) { - const auto& connection = get_test_connection(); + const auto &connection = ConnectionManager::GetDefaultConnection(); auto major = caosdb::COMPATIBLE_SERVER_VERSION_MAJOR; auto minor = caosdb::COMPATIBLE_SERVER_VERSION_MINOR; diff --git a/test/test_connection.h b/test/test_connection.h deleted file mode 100644 index 5e3cf5cb556e3b28134600ebd5dd9f3e5cd7de51..0000000000000000000000000000000000000000 --- a/test/test_connection.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ -#include <memory> // for allocator, make_shared, shared_ptr -#include <string> // for stoi, string -#include "caosdb/authentication.h" // for PlainPasswordAuthenticator -#include "caosdb/connection.h" // for PemFileCertificateProvider, TlsCaosDBC... -#include "caosdb/utility.h" // for get_env_var - -namespace caosdb::connection { -using caosdb::authentication::PlainPasswordAuthenticator; - -inline auto create_test_connection_config() - -> std::unique_ptr<TlsConnectionConfig> { - auto port_str = - caosdb::utility::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443"); - auto port = std::stoi(port_str); - const auto host = - caosdb::utility::get_env_var("CAOSDB_SERVER_HOST", "localhost"); - const auto path = - caosdb::utility::get_env_var("CAOSDB_SERVER_CERT", std::string()); - const auto user = caosdb::utility::get_env_var("CAOSDB_USER", "admin"); - const auto password = - caosdb::utility::get_env_var("CAOSDB_PASSWORD", "caosdb"); - - auto auth = PlainPasswordAuthenticator(user, password); - auto cert = PemFileCertificateProvider(path); - return std::make_unique<TlsConnectionConfig>(host, port, cert, auth); -} - -/** - * Return a fresh Connection pointer. The caller has the ownership. - */ -inline auto create_test_connection() -> std::unique_ptr<Connection> { - auto config = create_test_connection_config(); - return std::make_unique<Connection>(*(config.get())); -}; - -/** - * Singleton which holds a single global Connection - */ -class ConnectionProvider { -private: - std::shared_ptr<Connection> connection; - ConnectionProvider() : connection(create_test_connection()){}; - -public: - static ConnectionProvider &GetInstance() { - static ConnectionProvider instance; - return instance; - }; - inline auto GetConnection() -> std::shared_ptr<Connection> & { - return this->connection; - } - - ConnectionProvider(ConnectionProvider const &) = delete; - void operator=(ConnectionProvider const &) = delete; -}; - -/** - * Return a connection for testing purposes. - */ -inline auto get_test_connection() -> const std::shared_ptr<Connection> & { - return ConnectionProvider::GetInstance().GetConnection(); -}; - -} // namespace caosdb::connection diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 15901dfdac7dbec8e0e1bc5952693ce994649fba..62fa60f8fafbb424333a7828b8d9f71bd9bd0f6f 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -25,12 +25,12 @@ #include "caosdb/entity.h" // for Entity, EntityID #include "caosdb/transaction.h" // for Transaction, UniqueResult, Entity #include "gtest/gtest_pred_impl.h" // for Test, TestInfo, EXPECT_EQ, TEST -#include "test_connection.h" // for get_test_connection namespace caosdb::transaction { -TEST(test_transaction, DISABLED_retrieve_manufacturer_by_id) { - const auto &connection = caosdb::connection::get_test_connection(); +TEST(test_transaction, retrieve_manufacturer_by_id) { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); const auto *id = "107"; const auto *role = "RecordType";