Newer
Older
/*
*
* 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 "caosdb/connection.h"
#include "caosdb/authentication.h"
#include <gtest/gtest-message.h>
#include <gtest/gtest-test-part.h>
#include <memory>
#include "gtest/gtest_pred_impl.h"
using caosdb::connection::InsecureCaosDBConnectionConfig;
using caosdb::connection::SslCaosDBConnectionConfig;
using caosdb::connection::PemFileCACertProvider;
using caosdb::connection::CaosDBConnection;
using caosdb::authentication::PlainPasswordAuthenticator;
auto config = std::make_unique<InsecureCaosDBConnectionConfig>(host, port);
ASSERT_EQ(host, config->getHost());
ASSERT_EQ(port, config->getPort());
}
TEST(test_connection, connect_somehost_42347_fails) {
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port);
CaosDBConnection connection(config);
ASSERT_THROW(connection.getVersionInfo(), std::runtime_error);
TEST(test_connection, connection_insecure_authentication_error) {
auto port = 8080;
const auto host = caosdb::utils::get_env_var("CAOSDB_SERVER_HOST", "localhost");
auto major = 0;
auto minor = 5;
auto config = std::make_shared<InsecureCaosDBConnectionConfig>(host, port);
auto connection = CaosDBConnection(config);
// TODO AuthenticationError
ASSERT_THROW(connection.getVersionInfo(), std::runtime_error);
TEST(test_connection, connection_ssl_authentication_error) {
auto port = 8443;
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 major = 0;
auto minor = 5;
auto ssloptions = std::make_shared<PemFileCACertProvider>(path);
auto config = std::make_shared<SslCaosDBConnectionConfig>(host, port, ssloptions);
auto connection = CaosDBConnection(config);
// TODO AuthenticationError
ASSERT_THROW(connection.getVersionInfo(), std::runtime_error);
TEST(test_connection, connection_ssl_authentication_success) {
auto port = 8443;
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");
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 connection = CaosDBConnection(config);
auto v_info = connection.getVersionInfo();
ASSERT_EQ(major, v_info.major());
ASSERT_EQ(minor, v_info.minor());
}