Skip to content
Snippets Groups Projects

Error handling

Merged Timm Fitschen requested to merge dev into main
3 files
+ 44
26
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 17
14
@@ -18,10 +18,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR...
#include <memory> // for allocator, unique_ptr, __sh...
#include <string> // for stoi, string
#include "boost/filesystem/path.hpp" // for path
#include "caosdb/authentication.h" // for PlainPasswordAuthenticator
#include "caosdb/certificate_provider.h" // for PemFileCertificateProvider
@@ -32,7 +28,11 @@
#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> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR...
#include "gtest/gtest_pred_impl.h" // for Test, TestInfo, TEST, EXPEC...
#include <memory> // for allocator, unique_ptr, __sh...
#include <string> // for stoi, string
namespace caosdb::connection {
using caosdb::authentication::PlainPasswordAuthenticator;
@@ -57,7 +57,7 @@ TEST(test_connection, connect_somehost_42347_fails) {
auto config = InsecureConnectionConfiguration(host, port);
Connection connection(config);
EXPECT_THROW(connection.GetVersionInfo(), ConnectionError);
EXPECT_THROW(connection.RetrieveVersionInfo(), ConnectionError);
}
TEST(test_connection, connection_insecure_authentication_error_anonymous) {
@@ -70,7 +70,7 @@ TEST(test_connection, connection_insecure_authentication_error_anonymous) {
auto config = InsecureConnectionConfiguration(host, port);
auto connection = Connection(config);
EXPECT_THROW(connection.GetVersionInfo(), AuthenticationError);
EXPECT_THROW(connection.RetrieveVersionInfo(), AuthenticationError);
}
TEST(test_connection, connection_ssl_authentication_error_anonymous) {
@@ -86,8 +86,10 @@ TEST(test_connection, connection_ssl_authentication_error_anonymous) {
auto config = TlsConnectionConfiguration(host, port, cert);
auto connection = Connection(config);
EXPECT_THROW_MESSAGE(connection.GetVersionInfo(), AuthenticationError,
"Please login.");
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) {
@@ -106,8 +108,9 @@ TEST(test_connection, connection_ssl_authentication_error_wrong_credentials) {
auto config = TlsConnectionConfiguration(host, port, cert, auth);
auto connection = Connection(config);
EXPECT_THROW_MESSAGE(connection.GetVersionInfo(), AuthenticationError,
"Authentication failed. Username or password wrong.");
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) {
@@ -118,10 +121,10 @@ TEST(test_connection, connection_ssl_authentication_success) {
const auto pre_release =
std::string(caosdb::COMPATIBLE_SERVER_VERSION_PRE_RELEASE);
auto v_info = connection->GetVersionInfo();
EXPECT_EQ(major, v_info->GetMajor());
EXPECT_EQ(minor, v_info->GetMinor());
EXPECT_EQ(pre_release, v_info->GetPreRelease());
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
Loading