Skip to content
Snippets Groups Projects
Select Git revision
  • 9ef17d6f5676009cc396b848a47d9a439d72a1fb
  • main default protected
  • dev protected
  • f-fix-accent-sensitivity
  • f-filesystem-import
  • f-update-acl
  • f-filesystem-link
  • f-filesystem-directory
  • f-filesystem-core
  • f-filesystem-cleanup
  • f-string-ids
  • f-filesystem-main
  • f-multipart-encoding
  • f-trigger-advanced-user-tools
  • f-real-rename-test-pylibsolo2
  • f-real-rename-test-pylibsolo
  • f-real-rename-test
  • f-linkahead-rename
  • f-reference-record
  • f-xml-serialization
  • f-xfail-server-181
  • linkahead-pylib-v0.18.0
  • linkahead-control-v0.16.0
  • linkahead-pylib-v0.17.0
  • linkahead-mariadbbackend-v8.0.0
  • linkahead-server-v0.13.0
  • caosdb-pylib-v0.15.0
  • caosdb-pylib-v0.14.0
  • caosdb-pylib-v0.13.2
  • caosdb-server-v0.12.1
  • caosdb-pylib-v0.13.1
  • caosdb-pylib-v0.12.0
  • caosdb-server-v0.10.0
  • caosdb-pylib-v0.11.1
  • caosdb-pylib-v0.11.0
  • caosdb-server-v0.9.0
  • caosdb-pylib-v0.10.0
  • caosdb-server-v0.8.1
  • caosdb-pylib-v0.8.0
  • caosdb-server-v0.8.0
  • caosdb-pylib-v0.7.2
41 results

test_issues_pylib.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_connection.cpp 5.55 KiB
    /*
     * 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 "boost/filesystem/path.hpp"     // for path
    #include "caosdb/authentication.h"       // for PlainPasswordAuthenticator
    #include "caosdb/certificate_provider.h" // for PemFileCertificateProvider
    #include "caosdb/configuration.h"        // for InsecureConnectionConfigura...
    #include "caosdb/connection.h"           // for Connection, VersionInfo, path
    #include "caosdb/constants.h"            // for COMPATIBLE_SERVER_VERSION_M...
    #include "caosdb/exceptions.h"           // for AuthenticationError, Connec...
    #include "caosdb/info.h"                 // for VersionInfo
    #include "caosdb/utility.h"              // for get_env_var
    #include "caosdb_test_utility.h"         // for EXPECT_THROW_MESSAGE
    #include <gtest/gtest-message.h>         // NOLINT    TODO ?? for Message
    #include <gtest/gtest-test-part.h> // NOLINT    for SuiteApiResolver, TestPartR...
    #include "gtest/gtest_pred_impl.h" // NOLINT    for Test, TestInfo, TEST, EXPEC...
    #include <memory>                  // for allocator, unique_ptr, __sh...
    #include <string>                  // for stoi, string
    
    namespace caosdb::connection {
    using caosdb::authentication::PlainPasswordAuthenticator;
    using caosdb::configuration::InsecureConnectionConfiguration;
    using caosdb::configuration::PemFileCertificateProvider;
    using caosdb::configuration::TlsConnectionConfiguration;
    using caosdb::exceptions::AuthenticationError;
    using caosdb::exceptions::ConnectionError;
    
    TEST(test_connection, config_somehost_25323) {
      auto port = 25323;
      const auto *host = "somehost";
      auto config = InsecureConnectionConfiguration(host, port);
    
      EXPECT_EQ(host, config.GetHost());
      EXPECT_EQ(port, config.GetPort());
    }
    
    TEST(test_connection, connect_somehost_42347_fails) {
      auto port = 42347;
      const auto *host = "somehost";
      auto config = InsecureConnectionConfiguration(host, port);
      Connection connection(config);
    
      EXPECT_THROW(connection.RetrieveVersionInfo(), ConnectionError);
    }
    
    TEST(test_connection, connection_insecure_authentication_error_anonymous) {
      const auto *port_str =
        caosdb::utility::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTP", "8080");
      auto port = std::stoi(port_str);
      const auto *const host =
        caosdb::utility::get_env_var("CAOSDB_SERVER_HOST", "localhost");
    
      auto config = InsecureConnectionConfiguration(host, port);
      auto connection = Connection(config);
    
      EXPECT_THROW(connection.RetrieveVersionInfo(), AuthenticationError);
    }
    
    TEST(test_connection, connection_ssl_authentication_error_anonymous) {
      const auto *port_str =
        caosdb::utility::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
      auto port = std::stoi(port_str);
      const auto *const host =
        caosdb::utility::get_env_var("CAOSDB_SERVER_HOST", "localhost");
      const auto path =
        caosdb::utility::get_env_var("CAOSDB_SERVER_CERT", std::string());
    
      auto cert = PemFileCertificateProvider(path);
      auto config = TlsConnectionConfiguration(host, port, cert);
      auto connection = Connection(config);
    
      EXPECT_THROW_MESSAGE(connection.RetrieveVersionInfo(), AuthenticationError,
                           "The attempt to execute this transaction has not been "
                           "executed at all because the authentication did not "
                           "succeed. Original error: Please login.");
    }
    
    TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
      const auto *port_str =
        caosdb::utility::get_env_var("CAOSDB_SERVER_GRPC_PORT_HTTPS", "8443");
      auto port = std::stoi(port_str);
      const auto *const 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 *const user = "not-a-user-23461237";
      const auto *const password = "very-c-cred";
    
      auto auth = PlainPasswordAuthenticator(user, password);
      auto cert = PemFileCertificateProvider(path);
      auto config = TlsConnectionConfiguration(host, port, cert, auth);
      auto connection = Connection(config);
    
      EXPECT_THROW_MESSAGE(
        connection.RetrieveVersionInfo(), AuthenticationError,
        "The attempt to execute this transaction has not been executed at all "
        "because the authentication did not succeed. Original error: "
        "Authentication failed. Username or password wrong.");
    }
    
    TEST(test_connection, connection_ssl_authentication_success) {
      const auto &connection = ConnectionManager::GetDefaultConnection();
    
      auto major = caosdb::COMPATIBLE_SERVER_VERSION_MAJOR;
      auto minor = caosdb::COMPATIBLE_SERVER_VERSION_MINOR;
      const auto pre_release =
        std::string(caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE);
    
      const auto &v_info = connection->RetrieveVersionInfo();
      EXPECT_EQ(major, v_info.GetMajor());
      EXPECT_EQ(minor, v_info.GetMinor());
      EXPECT_EQ(pre_release, v_info.GetPreRelease());
    }
    
    } // namespace caosdb::connection